Skip to main content

Pure Python implementation of the WHATWG URL Pattern Standard

Project description

urlpattern-py

PyPI Tests

Pure Python 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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: urlpattern_py-0.1.1.tar.gz
  • Upload date:
  • Size: 36.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.1.1.tar.gz
Algorithm Hash digest
SHA256 873c73f2317c1625edab2313f82bf9ad41b9c498a590bcae004d005f72c8c9d8
MD5 fdcbc796761abbeb5cc5e416fb44d21d
BLAKE2b-256 af971d8b2b368e0ed43fa7b7b300e03697dcdb0d7abf72f12e9d469b43563101

See more details on using hashes here.

Provenance

The following attestation bundles were made for urlpattern_py-0.1.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: urlpattern_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.5 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32869fdca1685d67142a3b5bfe3ed658fee522ec34d3760956e1fea467b7dbfd
MD5 907c3bcea1b6f99df304ea3b12a2d4f1
BLAKE2b-256 79f94a3f04f22858332f1fd84430dcacc3eb8bd011e8ab68615f209ec13e0511

See more details on using hashes here.

Provenance

The following attestation bundles were made for urlpattern_py-0.1.1-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