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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.066s · 20MB
glibcpy 3.10–3.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.fixAlways 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.fixIf 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.fixDo 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.