Docs
Python

Python

How to install and use Ada in a Python project

Ada has a Python client available on Github. For more details on the ada_url API, see the documentation at Read the Docs.

Installation

Installing pre-built binary wheels

The easiest way to get started is to install ada-url from PyPI.

From within your virtual environment, run:

python3 -m pip install ada-url 
python3 -m pip install ada-url 

Installing from source

The Makefile in the project root will build a package for installation on your own machine.

From within your virtual environment, run:

Prepare

make requirements package
make requirements package

Install

python3 -m install -e .
python3 -m install -e .

Usage

URL class

The ada_url package defines a URL class that can parse URLs:

>>> import ada_url
>>> urlobj = ada_url.URL('https://example.org/path/file.txt')
>>> urlobj.protocol
'https:'
>>> urlobj.pathname
'/path/file.txt'
>>> import ada_url
>>> urlobj = ada_url.URL('https://example.org/path/file.txt')
>>> urlobj.protocol
'https:'
>>> urlobj.pathname
'/path/file.txt'

High-level functions

It also exposes some higher level functions for analyzing and manipulating URLs:

parse_url

>>> import ada_url
>>> ada_url.parse_url('https://user:pass@example.org:80/api?q=1#2')
{
    'href': 'https://user:pass@example.org:80/api?q=1#2',
    'username': 'user',
    'password': 'pass',
    'protocol': 'https:',
    'host': 'example.org:80',
    'port': '80',
    'hostname': 'example.org',
    'pathname': '/api',
    'search': '?q=1',
    'hash': '#2'
}
>>> import ada_url
>>> ada_url.parse_url('https://user:pass@example.org:80/api?q=1#2')
{
    'href': 'https://user:pass@example.org:80/api?q=1#2',
    'username': 'user',
    'password': 'pass',
    'protocol': 'https:',
    'host': 'example.org:80',
    'port': '80',
    'hostname': 'example.org',
    'pathname': '/api',
    'search': '?q=1',
    'hash': '#2'
}

join_url

>>> import ada_url
>>> ada_url.join_url(
'https://example.org/dir/child.txt', '../parent.txt'
)
>>> import ada_url
>>> ada_url.join_url(
'https://example.org/dir/child.txt', '../parent.txt'
)