pyuri

raw JSON →
0.3.1 verified Fri May 01 auth: no python

pyuri is a Python library for proper URI parsing and manipulation. It fully conforms to RFC 3986 and provides a clean API for working with URIs. Current version 0.3.1 is stable but in maintenance mode; releases are infrequent.

pip install pyuri
error ImportError: cannot import name 'URI' from 'pyuri'
cause Trying to import URI from a submodule that doesn't exist in older versions (pyuri <0.2.0 had different structure).
fix
Install version 0.3.1 and use from pyuri import URI.
error AttributeError: 'URI' object has no attribute 'authority'
cause Using an older version (<0.2.0) that did not expose `authority`.
fix
Upgrade to pyuri 0.3.1.
error TypeError: 'URI' object does not support item assignment
cause Attempting to assign to a URI component directly (e.g., `uri.scheme = 'https'`).
fix
Use the replace() method to create a modified copy.
deprecated Python 2 support was deprecated in 0.3.0. Use Python 3.6+.
fix Upgrade to Python 3.6+ and pyuri 0.3.1.
gotcha URI objects are immutable; you cannot modify components in-place. Use `replace()` to create a new URI.
fix Use `new_uri = uri.replace(scheme='https')` to get a modified copy.
gotcha The library does not normalize URI paths automatically. Trailing slash or relative paths are kept as-is.
fix Normalize manually if needed, e.g., using Python's `urllib.parse.urldefrag()` or external tools.
breaking In 0.3.0, the `URI` class replaced the old `URI` from `pyuri.uri`. Old imports from `pyuri.uri` will fail.
fix Use `from pyuri import URI` instead of `from pyuri.uri import URI`.

Parse and access components of a URI.

from pyuri import URI

uri = URI('http://example.com/path?q=test')
print(uri.scheme)  # http
print(uri.host)    # example.com
print(uri.path)    # /path
print(uri.query)   # q=test
print(uri.authority)  # example.com