urlpy
raw JSON → 0.5 verified Fri May 01 auth: no python maintenance
Simple URL parsing, canonicalization and equivalence library for Python. Current version 0.5, stable but rarely updated.
pip install urlpy Common errors
error AttributeError: module 'urlpy' has no attribute 'URL' ↓
cause Using 'import urlpy' instead of 'from urlpy import URL'
fix
Use 'from urlpy import URL'
error TypeError: 'URL' object does not support item assignment ↓
cause Trying to modify a URL property by index instead of attribute
fix
Use attribute assignment like u.scheme = 'https'
Warnings
gotcha URL objects are mutable. Modifying attributes like u.scheme affects the original object. ↓
fix Use u.canonicalize() or create a new URL() for modifications.
deprecated The library is in maintenance mode; no new features are added. May not be compatible with newer Python versions beyond 3.10. ↓
fix Consider using 'yarl' or 'urllib.parse' for active development.
gotcha Canonicalization may lowercases the scheme and host, but does not sort query parameters. ↓
fix Manually sort query params if needed: u.query = '&'.join(sorted(u.query.split('&')))
Imports
- URL wrong
import urlpycorrectfrom urlpy import URL
Quickstart
from urlpy import URL
u = URL('http://example.com/foo?bar=baz')
print(u.scheme, u.host, u.path)
print(u.canonicalize())