Skip to content

Python

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:

Terminal window
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:

  1. Prepare

    Terminal window
    make requirements package
  2. Install

    Terminal window
    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'

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:[email protected]:80/api?q=1#2')
{
'href': 'https://user:[email protected]: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'
)