Skip to main content

url-normalize

URI Normalization function:

  • Take care of IDN domains.
  • Always provide the URI scheme in lowercase characters.
  • Always provide the host, if any, in lowercase characters.
  • Only perform percent-encoding where it is essential.
  • Always use uppercase A-through-F characters when percent-encoding.
  • Prevent dot-segments appearing in non-relative URI paths.
  • For schemes that define a default authority, use an empty authority if the default is desired.
  • For schemes that define an empty path to be equivalent to a path of "/", use "/".
  • For schemes that define a port, use an empty port if the default is desired
  • All portions of the URI must be utf-8 encoded NFC from Unicode strings

Inspired by Sam Ruby's urlnorm.py

Features

  • IDN (Internationalized Domain Name) support
  • Configurable default scheme (https by default)
  • Query parameter filtering with allowlists
  • Support for various URL formats including:
    • Empty string URLs
    • Double slash URLs (//domain.tld)
    • Shebang (#!) URLs
  • Cross-version Python compatibility (3.8+)
  • 100% test coverage
  • Modern type hints and string handling

Installation

pip install url-normalize

Usage

Basic usage:

from url_normalize import url_normalize

# Basic normalization (uses https by default)
print(url_normalize("www.foo.com:80/foo"))
# Output: https://www.foo.com/foo

# With custom default scheme
print(url_normalize("www.foo.com/foo", default_scheme="http"))
# Output: http://www.foo.com/foo

# With query parameter filtering enabled
print(url_normalize("www.google.com/search?q=test&utm_source=test", filter_params=True))
# Output: https://www.google.com/search?q=test

# With custom parameter allowlist
print(url_normalize(
    "example.com?page=1&id=123&ref=test",
    filter_params=True,
    param_allowlist={"example.com": ["page", "id"]}
))
# Output: https://example.com?page=1&id=123
print(url_normalize(
    "example.com?page=1&id=123&ref=test",
    filter_params=True,
    param_allowlist=["page", "id"]
))
# Output: https://example.com?page=1&id=123

Documentation

For a complete history of changes, see CHANGELOG.md.

License

MIT License

Metadata

Release files for url-normalize 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for url-normalize 2.0.1
File Size Uploaded
url_normalize-2.0.1.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for url-normalize 2.0.1
File Interpreter ABI Platform
url_normalize-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.3 kB

Release files / url_normalize-2.0.1.tar.gz

Download URL url_normalize-2.0.1.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f45566acecd1a10b198b22bac6737887a261d08f4254c058294bd10e777fb5cf
BLAKE2b-256 checksum
How to use checksums
4e43544f33f375c1936459448cf403da60917d87afa4188ba129f1d4a4b8bf8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / url_normalize-2.0.1-py3-none-any.whl

Download URL url_normalize-2.0.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c15cabbee757b94c86868bc2adb1d31679851307681e2f3d424b40e652799231
BLAKE2b-256 checksum
How to use checksums
1fedfd351be051bc083cc44bd7c7e7bf2e596074221f2779ccae23d67db57d36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release history Release notifications | RSS feed

3.0.1

2 release files

3.0.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.3

2 release files

1.3.1

2 release files

1.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page