Registry / http-networking / urlcanon

urlcanon

JSON →
library0.3.1pypypi✓ verified 84d ago

urlcanon is a URL canonicalization and normalization library for Python and Java, currently at version 0.3.1. It provides a URL parser that preserves input bytes, a predefined set of canonicalization rules aiming to match browser parsing behavior, and an alternative URL serialization format called SSURT. The library is stable and in production use, though API and output stability are not yet guaranteed, and feature sets differ between its Python and Java implementations. It does not have a strict release cadence but updates as needed.

pip install urlcanon
INSTALL
IMPORT
SIG · URLCANON
U
urlcanon
http-networkingpythonv0.3.1
Install
2.5s avg
Import
62ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.066s · 20MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.5s · import 0.059s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse_url
from urlcanon import parse_url
import urlcanon
Canonicalizer
from urlcanon import Canonicalizer
ParsedUrl
from urlcanon import ParsedUrl

Demonstrates parsing a URL, applying WHATWG canonicalization rules, obtaining the SSURT representation, and checking a URL against a MatchRule. Note that canonicalization functions like `whatwg` modify the `ParsedUrl` object in place.

import urlcanon input_url = "http://///EXAMPLE.com:80/foo/../bar" # Parse the URL. This preserves the original input string. parsed_url = urlcanon.parse_url(input_url) print(f"Original parsed URL: {parsed_url}") # Apply WHATWG canonicalization rules (modifies parsed_url in place) urlcanon.whatwg(parsed_url) print(f"Canonicalized URL (WHATWG): {parsed_url}") # Get the SSURT representation (suitable for sorting/prefix-matching) ssurt_representation = parsed_url.ssurt() print(f"SSURT: {ssurt_representation}") # Example of using a MatchRule rule = urlcanon.MatchRule(ssurt=b'com,example,//:http/bar') url_to_check = b'HTtp:////eXAMple.Com/bar//baz//..///quu' applies = urlcanon.whatwg.rule_applies(rule, url_to_check) print(f"Does rule apply to '{url_to_check.decode()}': {applies}")
Debug
Known issues
breakingThe library explicitly states 'no API or output stability guarantees yet'. Future versions may introduce breaking changes without prior notice.
fix
Always pin to a specific patch version (e.g., `urlcanon==0.3.1`) and thoroughly test when upgrading.
affects: 0.3.1 and earlier
gotchaCanonicalization functions (e.g., `urlcanon.whatwg()`) modify the `ParsedUrl` object in place. They do not return a new, canonicalized object.
fix
If you need to preserve the original `ParsedUrl` object, create a copy before applying canonicalization: `modified_url = urlcanon.parse_url(str(original_url))`.
affects: All versions
gotchaThere are known differences in features and behavior between the Python and Java versions of urlcanon.
fix
Do not assume feature parity between Python and Java implementations. Refer to the specific language's documentation or source code for exact behavior.
affects: All versions
Upgrade
Version history
0.3.1latest on PyPI · released Jul 2, 2019
Audit
Dependencies
idnarequiredUsed for handling internationalized domain names (IDN) in URL processing.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
urlcanon — pip install urlcanon · libregistry