can-ada: Fast Spec-Compliant URL Parser

3.0.0 · active · verified Fri Apr 17

can-ada is a Python wrapper for the Ada C++ library, providing a fast and spec-compliant URL parser. It adheres to the WHATWG URL Standard, offering high-performance parsing capabilities. The current version is 3.0.0, with releases typically following updates to the underlying Ada C++ library.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic URL parsing, accessing components, and modification using the URL object, as well as the convenience function `parse_url`.

from can_ada import URL, parse_url

# Parse a URL string into a URL object
url_string = "https://example.com:8080/path/to/resource?query=value&foo=bar#fragment"
url_object = URL(url_string)

print(f"Original URL: {url_object.href}")
print(f"Protocol: {url_object.protocol}")     # e.g., 'https:'
print(f"Host: {url_object.host}")             # e.g., 'example.com:8080'
print(f"Hostname: {url_object.hostname}")     # e.g., 'example.com'
print(f"Port: {url_object.port}")             # e.g., '8080'
print(f"Pathname: {url_object.pathname}")     # e.g., '/path/to/resource'
print(f"Search: {url_object.search}")         # e.g., '?query=value&foo=bar'
print(f"Hash: {url_object.hash}")             # e.g., '#fragment'

# Modify parts of the URL
url_object.hostname = "newhost.org"
url_object.pathname = "/new/path"
print(f"Modified URL: {url_object.href}")

# Using parse_url for convenience (returns a dictionary-like object)
parsed_dict = parse_url("http://test.com/page")
print(f"Parsed dict protocol: {parsed_dict.protocol}")

view raw JSON →