Pure Python implementation of the WHATWG URL Pattern Standard
Project description
urlpattern-py
Pure Python, dependency-free implementation of the WHATWG URL Pattern Standard (as of 3 December 2025).
Quick Start
Installation
pip install urlpattern-py
Installation (Development)
# Clone repository
cd urlpattern-py
# Install dev dependencies
python -m pip install -e ".[dev]"
Usage
from urlpattern import URLPattern
pattern = URLPattern("https://example.com/books/:id")
assert pattern.test("https://example.com/books/123") is True
assert pattern.exec("https://example.com/books/123")["pathname"]["groups"]["id"] == "123"
Development Guidelines
Code Formatting & Linting
We use Ruff for formatting and linting. To ensure consistency, please set up pre-commit to run automatically before each commit.
# Install the git hooks (pre-commit is installed via dev dependencies)
pre-commit install
Once installed, Ruff will run automatically on git commit. You can also run it manually on all files:
pre-commit run --all-files
Configuration for Ruff (line length, import sorting, etc.) can be found in pyproject.toml.
Architecture
URLPattern string → Tokenizer → Normalizer → Compiler → Python regex
Running Tests
# Run the full suite
python -m pytest
# Run a single module
python -m pytest tests/test_compliance.py
808 passed, 7 skipped in 0.56s
The pytest suite mirrors all WPT URLPattern cases under upstream/urlpattern, including compare, generate, hasRegExpGroups, and constructor coverage; the WPT data options (expected_obj, expected_match, exactly_empty_components, and input/baseURL/ignoreCase variants) are all exercised in tests/.
Polyfill-specific test data under upstream/urlpattern-polyfill/test is also mirrored in tests/resources/polyfill, with dedicated pytest coverage for the additional cases and compare/hasRegExpGroups behavior; any polyfill expectations that conflict with WPT are skipped.
The suite also includes tests generated from the examples in MDN and the WHATWG spec (upstream/index.md and upstream/spec.bs) to keep documentation examples aligned with implementation behavior.
Upstream Sources
Upstream files are version-pinned and fetched via update_upstream.sh, so the repo only tracks commit pointers and not the downloaded artifacts. The pinned commits are the source for the tests.
./update_upstream.sh
- WPT URLPattern tests are fetched into
upstream/urlpattern. - MDN and WHATWG spec sources are fetched into
upstream/index.mdandupstream/spec.bs. - The URLPattern polyfill is a git submodule at
upstream/urlpattern-polyfill.
Update the commit hashes at the top of update_upstream.sh to refresh pinned versions.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file urlpattern_py-0.2.0.tar.gz.
File metadata
- Download URL: urlpattern_py-0.2.0.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dfc2d8044f40ba6bc77867aef2430b916923e6742630a418a3e0e17e27b3a8d
|
|
| MD5 |
2e1d76bcf224d343ba50deaf85648bfd
|
|
| BLAKE2b-256 |
70719a367b5931c7d3c56a97a8968c5093be26bd8cc45fdabb5ec5d0d4a9775e
|
Provenance
The following attestation bundles were made for urlpattern_py-0.2.0.tar.gz:
Publisher:
publish.yml on karasinski/urlpattern-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
urlpattern_py-0.2.0.tar.gz -
Subject digest:
1dfc2d8044f40ba6bc77867aef2430b916923e6742630a418a3e0e17e27b3a8d - Sigstore transparency entry: 774600516
- Sigstore integration time:
-
Permalink:
karasinski/urlpattern-py@3f4f655e9265c6c7342e268dc459e88dabf8a933 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/karasinski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3f4f655e9265c6c7342e268dc459e88dabf8a933 -
Trigger Event:
release
-
Statement type:
File details
Details for the file urlpattern_py-0.2.0-py3-none-any.whl.
File metadata
- Download URL: urlpattern_py-0.2.0-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fa08324754ab10cd9f67cb32f6fc0c888fcc782be5a24fc563ef55d854e1638
|
|
| MD5 |
dccf1e4b6d5b06e3b02903bd22ee039f
|
|
| BLAKE2b-256 |
fced17bb2c6e1a90331cf64868fdc41bcec24221fb452cf567addedae0db47f3
|
Provenance
The following attestation bundles were made for urlpattern_py-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on karasinski/urlpattern-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
urlpattern_py-0.2.0-py3-none-any.whl -
Subject digest:
8fa08324754ab10cd9f67cb32f6fc0c888fcc782be5a24fc563ef55d854e1638 - Sigstore transparency entry: 774600518
- Sigstore integration time:
-
Permalink:
karasinski/urlpattern-py@3f4f655e9265c6c7342e268dc459e88dabf8a933 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/karasinski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3f4f655e9265c6c7342e268dc459e88dabf8a933 -
Trigger Event:
release
-
Statement type: