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.
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
On Linux/UNIX or macOS:
pip install urlpattern
On Windows:
py -m pip install urlpattern
Due to limitations in the dependency denoland/rust-urlpattern, it may not support all features specified in the standard.