python-url-normalize
Subpackage Descriptions
| single |
# url-normalize
[tests]
[Coveralls]
[PyPI]
[Python Versions]
[License]
[Ruff]
Normalize URL spelling consistently for storage, comparison, and display.
Use `url_normalize()` for normalized URLs and `url_humanize()` for readable
display URLs.
Requires **Python 3.11 or newer**. Normalization operates on URL text; it
does not fetch pages or follow redirects.
## Installation
Install the library and CLI:
```sh
python -m pip install url-normalize
```
Or install the CLI in its own environment with [uv]:
```sh
uv tool install url-normalize
```
## Quick start
```python
from url_normalize import url_normalize
print(url_normalize("HTTP://Example.COM:80/a/../b"))
# Output: http://example.com/b
print(url_normalize("bücher.de/résumé"))
# Output: https://xn--bcher-kva.de/r%C3%A9sum%C3%A9
```
From the terminal:
```sh
url-normalize "HTTP://Example.COM:80/a/../b"
# Output: http://example.com/b
```
## Normalization behavior
| Behavior | Input | Output |
| --- | --- | --- |
| Add a missing scheme | `example.com` | `https://example.com/` |
| Lowercase scheme and host; remove a default port |
`HTTP://Example.COM:80/` | `http://example.com/` |
| Resolve dot segments | `https://example.com/a/../b` |
`https://example.com/b` |
| Encode Unicode hosts and paths | `https://bücher.de/résumé` |
`https://xn--bcher-kva.de/r%C3%A9sum%C3%A9` |
| Remove trailing host dots, including Unicode equivalents |
`https://example.com。/` | `https://example.com/` |
| Preserve encoded path separators; uppercase escape hex |
`https://example.com/a%2fb` | `https://example.com/a%2Fb` |
| Preserve query order and repeated keys |
`https://example.com/?b=2&a=1&a=3` | `https://example.com/?b=2&a=1&a=3` |
| Preserve explicit empty query values | `https://example.com/?flag=&flag`
| `https://example.com/?flag=&flag` |
In query parameters, `+`, `%2B`, and `%20` remain distinct. Parameter
filtering is disabled by default. Fragments are preserved and normalized;
hashbang fragments (`#!`) are converted to the `_escaped_fragment_` query
parameter.
Normalization applies consistent spelling rules; it does not establish
whether two URLs serve the same content. Applications using normalized URLs
as persistent cache keys or identifiers should review the [changelog] when
upgrading.
## Python API
Both functions accept a URL as `str` or `None` and return `str` or `None`.
An empty string and `None` are returned unchanged. Malformed input can
raise `ValueError`, including `UnicodeError` for invalid hostnames.
The following options are keyword-only and apply to both functions:
| Option | Default | Purpose |
| --- | --- | --- |
| `default_scheme` | `"https"` | Scheme to add when the URL has none. |
| `default_domain` | `None` | Domain to add to an absolute path such as
`/images/logo.png`. |
| `filter_params` | `False` | Retain only allowlisted query parameters. |
| `param_allowlist` | `None` | Override built-in rules with a list of names
or a dictionary mapping domains to lists. Requires `filter_params=True`. |
Unicode URL characters always use UTF-8 percent encoding.
### Query parameter filtering
|
Configuration Switches (platform-specific settings discarded)
PY313 ON Build using Python 3.13
PY314 OFF Build using Python 3.14
Package Dependencies by Type
Download groups
| main |
mirror://PYPIWHL/7d/3d/ae9ba568240002f25d676df745208aec077767cd63e68cbb93bd2650c4ec |
Distribution File Information
34c386c6b2dbde760eaaaa8542dc29995c75f2baf94acceee18e5b6b29579469 18692 python-src/url_normalize-3.1.0-py3-none-any.whl
Ports that require python-url-normalize:v13