'URL parser and manipulator based on the WHAT WG URL standard'


Keywords
whatwg-url
License
Apache-2.0
Install
pip install ada-url==1.12.0

Documentation

ada-url

The urlib.parse module in Python does not follow the legacy RFC 3978 standard nor does it follow the newer WHATWG URL specification. It is also relatively slow.

This is ada_url, a fast standard-compliant Python library for working with URLs based on the Ada URL parser.

Installation

Install from PyPI:

Usage examples

Parsing URLs

The URL class is intended to match the one described in the WHATWG URL spec:.

The parse_url function returns a dictionary of all URL elements:

Altering URLs

Replacing URL components with the URL class:

Replacing URL components with the replace_url function:

>>> from ada_url import replace_url >>> replace_url('https://example.org/path/../file.txt', host='example.com') 'https://example.com/file.txt'

Search parameters

The URLSearchParams class is intended to match the one described in the WHATWG URL spec.

The parse_search_params function returns a dictionary of search keys mapped to value lists:

Internationalized domain names

The idna class can encode and decode IDNs:

WHATWG URL compliance

This library is compliant with the WHATWG URL spec. This means, among other things, that it properly encodes IDNs and resolves paths:

Contrast that with the Python standard library's urlib.parse module:

Alternative Python bindings

This package uses CFFI to call the Ada library's functions, which has a performance cost. The alternative can_ada (Canadian Ada) package uses pybind11 to generate a Python extension module, which is more performant.