Registry / http-networking / yarl
library1.24.5pypypi✓ verified 24d ago

yarl is an immutable, RFC 3986-compliant URL parsing and manipulation library for Python 3. It provides the URL class with automatic percent-encoding/decoding, pathlib-style path operations, query-string helpers, and human-readable representations. The current release is 1.23.0, published March 2026. Releases ship frequently (multiple times per minor version) as part of the aio-libs ecosystem, closely tracking aiohttp.

pip install yarl
INSTALL
IMPORT
SIG · YARL
Y
yarl
http-networkingpythonv1.24.5
Install
2.8s avg
Import
54ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.24.5 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.054s · 20MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.054s · 21MB
18MB installed
● package 18MB
Code
Verified usage

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

URL
from yarl import URL
import yarl; yarl.URL(...)
Always import URL directly from yarl; the top-level module is rarely used on its own.
cache_configure
from yarl import cache_configure cache_configure(encode_host_size=256)
cache_configure(ip_address_size=256, host_validate_size=256)
ip_address_size and host_validate_size are deprecated since ~1.17 in favour of encode_host_size and will be removed in a future release.

Parse, inspect, and mutate URLs; build from parts; path-join with /; apply query with %.

from yarl import URL # Parse an existing URL url = URL('https://user:pw@api.example.com:8080/v1/items?page=1&q=foo#section') print(url.scheme) # 'https' print(url.host) # 'api.example.com' (decoded) print(url.raw_host) # IDNA-encoded form print(url.port) # 8080 (explicit); None falls back to scheme default print(url.path) # '/v1/items' (percent-decoded) print(url.raw_path) # '/v1/items' (percent-encoded, wire form) print(url.query) # MultiDictProxy with parsed key/value pairs print(url.query_string) # 'page=1&q=foo' print(url.fragment) # 'section' # Build from components — port must be int, not str base = URL.build(scheme='https', host='api.example.com', port=8080, path='/v1') print(base) # https://api.example.com:8080/v1 # Path-join (like pathlib) endpoint = base / 'items' / '42' print(endpoint) # https://api.example.com:8080/v1/items/42 # Apply a query string with % with_query = endpoint % {'expand': 'true', 'format': 'json'} print(with_query) # Mutation methods return new URL objects (immutable) updated = endpoint.with_query({'page': '2'}).with_fragment('results') print(str(updated)) # wire-safe string for HTTP clients print(updated.human_repr()) # human-readable (non-ASCII decoded) # Non-ASCII is encoded automatically unicode_url = URL('https://example.com/пошук?q=кіт') print(str(unicode_url)) # percent-encoded print(unicode_url.human_repr()) # readable
Debug
Known issues
breakingURL.build() and URL.with_host() raise TypeError when port is passed as a string. Previously a string port silently produced a malformed URL.
fix
Always pass port as int: URL.build(scheme='https', host='example.com', port=443)
affects: >=1.10
breakingpropcache is now a required hard dependency (split out ~v1.17). Environments that vendor or vendor-pin transitive deps without propcache will fail to import yarl.
fix
Ensure propcache is present in all deployment targets. pip install yarl handles this automatically.
affects: >=1.17
deprecatedcache_configure() parameters ip_address_size and host_validate_size are deprecated in favour of encode_host_size and will be removed in a future release.
fix
Replace cache_configure(ip_address_size=N, host_validate_size=N) with cache_configure(encode_host_size=N)
affects: >=1.17
gotchaURL properties (e.g. .path, .host, .query_string) return percent-DECODED values. Pass these to other URLs or HTTP wire formats and you risk double-encoding. Use the raw_ prefixed variants (.raw_path, .raw_host, .raw_query_string) for wire-safe strings.
fix
Use str(url) or url.raw_path / url.raw_query_string when constructing HTTP request lines.
affects: all
gotchaPassing boolean values to with_query() or URL.build(query=...) raises TypeError. yarl refuses to guess how to serialize True/False.
fix
Convert bools to strings before passing: {'flag': 'true'} not {'flag': True}
affects: all
gotchaencoded=True skips all auto-encoding but any subsequent mutation method (.with_query(), /, etc.) may re-quote parts, silently corrupting pre-encoded values. The docs explicitly warn against relying on this.
fix
Use encoded=True only as a last resort and avoid chaining mutation methods on encoded URLs. Prefer URL.build() or proper string inputs instead.
affects: all
gotchaThe / operator (URL.__truediv__) and URL.joinpath() strip a trailing slash from the base path before appending the segment. URL('https://example.com/api/') / 'v1' gives /api/v1, not /api//v1. This matches pathlib semantics but surprises users expecting query-string-style appending.
fix
Use URL.joinpath(*parts) with explicit trailing slash control, or URL.with_path() for full path replacement.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'yarl'
The yarl library is not installed in the current Python environment.
fix
pip install yarl
ModuleNotFoundError: No module named 'yarl.url'
The URL class is exposed directly from the top-level yarl package, not from a nested yarl.url submodule.
fix
from yarl import URL
AttributeError: 'URL' object has no attribute 'add_query_param'
yarl.URL objects are immutable. To modify query parameters, use methods like with_query() or update_query(), which return a new URL object.
fix
new_url = url.with_query(param1='value1', param2='value2')
TypeError: argument should be str or URL, got <class 'int'>
Methods like joinpath() or the / operator for URL objects expect string or other URL objects as arguments for path segments, not other types like integers.
fix
Ensure the argument passed is a string representing a path segment or another yarl.URL object. Example: url.joinpath(str(segment_id)) or url / 'segment_name'
Upgrade
Version history
1.24.5latest on PyPI · released Jul 20, 2026
Audit
Dependencies
multidictrequiredRequired — URL.query returns a MultiDictProxy; installed automatically by pip
propcacherequiredRequired — fast property caching layer extracted from yarl ~1.17; installed automatically
Agent activity
42 hits · last 30 days
node
34
OpenAI (training)
1
Resources