Skip to main content

Pure Python implementation of the WHATWG URL Pattern Standard

Project description

urlpattern-py

PyPI Tests

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.md and upstream/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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urlpattern_py-0.2.0.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

urlpattern_py-0.2.0-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

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

Hashes for urlpattern_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1dfc2d8044f40ba6bc77867aef2430b916923e6742630a418a3e0e17e27b3a8d
MD5 2e1d76bcf224d343ba50deaf85648bfd
BLAKE2b-256 70719a367b5931c7d3c56a97a8968c5093be26bd8cc45fdabb5ec5d0d4a9775e

See more details on using hashes here.

Provenance

The following attestation bundles were made for urlpattern_py-0.2.0.tar.gz:

Publisher: publish.yml on karasinski/urlpattern-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for urlpattern_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fa08324754ab10cd9f67cb32f6fc0c888fcc782be5a24fc563ef55d854e1638
MD5 dccf1e4b6d5b06e3b02903bd22ee039f
BLAKE2b-256 fced17bb2c6e1a90331cf64868fdc41bcec24221fb452cf567addedae0db47f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for urlpattern_py-0.2.0-py3-none-any.whl:

Publisher: publish.yml on karasinski/urlpattern-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page