Skip to main content

Pure Python implementation of the WHATWG URL Pattern Standard

Project description

urlpattern-py

Pure Python implementation of the WHATWG URL Pattern Standard (as of 3 December 2025).

Docs include two folders: docs/urlpattern for the official WPT suite and docs/urlpattern-polyfill for the official polyfill.

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 docs/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 docs/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 (docs/index.md and docs/spec.bs) to keep documentation examples aligned with implementation behavior.

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.1.0.tar.gz (36.4 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.1.0-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file urlpattern_py-0.1.0.tar.gz.

File metadata

  • Download URL: urlpattern_py-0.1.0.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for urlpattern_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 01a8f0b08592bad3fcddfa09fc1a9afb1da414e3e5e0019f517578282515ba20
MD5 106504ba2d2e5bb3d2e59fed4aadab30
BLAKE2b-256 870cd18e83c101552ab1a30517465160cc78b50aadba42f600d7620fad7b440d

See more details on using hashes here.

File details

Details for the file urlpattern_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: urlpattern_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for urlpattern_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbeff30284a45dfe5ddd4e419cf938337d99d764efe59cc60100a81387b03427
MD5 d15cc5c204b62d9fef6fbc4095306aeb
BLAKE2b-256 fd5238e36092c855b2d46f7d641fc8f28151028aa87889de031469d15c9d3bd1

See more details on using hashes here.

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