Ada URL Parser
Ada URL is a fast, standard-compliant Python library for parsing and manipulating URLs, directly based on the high-performance Ada C++ URL parser. It strictly adheres to the WHATWG URL Standard, offering a more predictable and often faster alternative to Python's built-in `urllib.parse`. The library is actively maintained with frequent updates, often aligning with new releases of the underlying C++ project.
Warnings
- deprecated Python 3.9 support was deprecated in version 1.28.0. Users are encouraged to upgrade to Python 3.10 or newer.
- gotcha The `__repr__` of `URL` objects now redacts passwords for security reasons. If you relied on the full URL string (including sensitive credentials) in `__repr__` output for debugging or logging, this behavior has changed.
- gotcha While `ada-url` is significantly faster than Python's `urllib.parse`, it uses CFFI for its bindings. For scenarios requiring absolute maximum performance with minimal Python-C overhead, alternative bindings like `can_ada` (which uses `pybind11`) might offer further speed improvements.
- gotcha Ada-url strictly follows the WHATWG URL Standard. This can lead to different parsing behaviors compared to Python's `urllib.parse`, which does not strictly adhere to any single standard (neither WHATWG nor older RFCs). Be aware of potential differences when migrating or when interacting with systems that follow older RFCs.
- breaking The underlying Ada C++ library (which `ada-url` binds to) has its own breaking changes between major versions (e.g., Ada v3.0 introduced C++20 requirements and changed error types). While the Python bindings aim for stability, users building from source or relying on very specific low-level behaviors might indirectly encounter these breaking changes or require updated C++ toolchains.
Install
-
pip install ada-url
Imports
- URL
from ada_url import URL
- parse_url
from ada_url import parse_url
- URLSearchParams
from ada_url import URLSearchParams
Quickstart
import ada_url
# Parse a URL using the URL class
url_obj = ada_url.URL('https://user:pass@example.org:8080/path/to/resource?query=value#fragment')
print(f"Original URL: {url_obj.href}")
print(f"Protocol: {url_obj.protocol}")
print(f"Hostname: {url_obj.hostname}")
print(f"Port: {url_obj.port}")
print(f"Pathname: {url_obj.pathname}")
print(f"Search: {url_obj.search}")
print(f"Hash: {url_obj.hash}")
# Modify a URL component
url_obj.port = '443'
url_obj.protocol = 'https:'
print(f"Modified URL: {url_obj.href}")
# Use high-level parse_url function (returns a dictionary)
parsed_dict = ada_url.parse_url('https://example.com/api?id=123&name=test')
print(f"Parsed dictionary: {parsed_dict['search']}")