Skip to main content

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

Project description

This is ada_url, a Python library for parsing and joining URLs.

WHATWG URL compliance

Unlike the standard library’s urllib.parse module, this library is compliant with the WHATWG URL spec.

urlstring = "https://www.GOoglé.com/./path/../path2/"

import ada_url

# prints www.xn--googl-fsa.com,
# the correctly parsed domain name according to WHATWG
print(ada_url.URL(urlstring).hostname)
# prints /path2/
# the correctly parsed pathname according to WHATWG
print(ada_url.URL(urlstring).pathname)

import urllib

#prints www.googlé.com
print(urllib.parse.urlparse(urlstring).hostname)
#prints /./path/../path2/
print(urllib.parse.urlparse(urlstring).path)

Examples

This package exposes a URL class that is intended to match the one described in the WHATWG URL spec.

>>> import ada_url
>>> ada_url.URL('https://example.org/path/../file.txt') as urlobj:
>>> urlobj.host = 'example.com'
>>> new_url = urlobj.href
>>> new_url
'https://example.com/file.txt'

It also provides some higher level functions for parsing and manipulating URLs.

>>> import ada_url
>>> ada_url.check_url('https://example.org')
True
>>> ada_url.join_url(
    'https://example.org/dir/child.txt', '../parent.txt'
)
'https://example.org/parent.txt'
>>> ada_url.normalize_url('https://example.org/dir/../parent.txt')
'https://example.org/parent.txt'
>>> 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'
}
>>> ada_url.replace_url('http://example.org:80', protocol='https:')
'https://example.org/'

You can find more documentation at Read the Docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ada-url-1.0.0.tar.gz (374.2 kB view hashes)

Uploaded Source

Built Distributions

ada_url-1.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (596.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ada_url-1.0.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (541.0 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

ada_url-1.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (596.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ada_url-1.0.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (541.0 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

ada_url-1.0.0-cp311-cp311-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ada_url-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (637.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ada_url-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (382.0 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ada_url-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl (548.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ada_url-1.0.0-cp311-cp311-macosx_10_9_universal2.whl (558.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

ada_url-1.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ada_url-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (637.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ada_url-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (382.0 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ada_url-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl (548.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ada_url-1.0.0-cp310-cp310-macosx_10_9_universal2.whl (558.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

ada_url-1.0.0-cp39-cp39-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ada_url-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (637.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ada_url-1.0.0-cp39-cp39-macosx_11_0_arm64.whl (382.0 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ada_url-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl (548.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ada_url-1.0.0-cp39-cp39-macosx_10_9_universal2.whl (558.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

ada_url-1.0.0-cp38-cp38-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

ada_url-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (637.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ada_url-1.0.0-cp38-cp38-macosx_11_0_arm64.whl (382.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

ada_url-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl (548.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

ada_url-1.0.0-cp38-cp38-macosx_10_9_universal2.whl (558.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page