Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.82 KB

README.md

File metadata and controls

44 lines (29 loc) · 1.82 KB

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.