Skip to content

An implementation of the URL Pattern Standard for Python written in Rust

License

Notifications You must be signed in to change notification settings

urlpattern/python-urlpattern

Repository files navigation

URL Pattern

PyPI - Version PyPI - Python Version Ruff CI

This library is an implementation of the URL Pattern Standard for Python written in Rust.

It provides a pattern matching syntax like /users/:id/, similar to Express or Path-to-RegExp in Node.js. You can use it as a foundation to build your own web server or framework.

It's a thin wrapper of denoland/rust-urlpattern with PyO3 + Maturin.

Example

from urlpattern import URLPattern

pattern = URLPattern("https://example.com/admin/*")
print(pattern.test("https://example.com/admin/main/"))  # output: True
print(pattern.test("https://example.com/main/"))  # output: False

pattern = URLPattern({"pathname": "/users/:id/"})
result = pattern.exec({"pathname": "/users/4163/"})
print(result["pathname"]["groups"]["id"])  # output: 4163

Installation

On Linux/UNIX or macOS:

pip install urlpattern

On Windows:

py -m pip install urlpattern

Limitations

Due to limitations in the dependency denoland/rust-urlpattern, it may not support all features specified in the standard.

About

An implementation of the URL Pattern Standard for Python written in Rust

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published