Skip to content

romantolkachyov/python-matchit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-matchit is a Python binding for the matchit Rust library.

matchit is a high-performance URL/path routing library. It builds a radix tree (compressed trie) from route patterns and finds the best match for a given path in logarithmic time. This makes python-matchit a very fast choice for HTTP routers, URL dispatchers, or any task where you need to match many patterns against paths.

Installation

pip install python-matchit

Usage

from matchit import Router

router = Router[str]()
router.insert("/users/{id}", "test_id")

res = router.at("/users/123")

assert res.value == "test_id"
assert res.params == {"id": "123"}

try:
    router.at("/noway")
except LookupError:
    print("Not found as expected")

Router() without type argument also works.

Development

Setup

uv sync

Testing

Build and install the package in editable mode, then run tests:

maturin develop --uv
uv run python test.py

Note: use maturin develop --uv, not uv run maturin develop. The latter runs maturin without telling it to use uv for installation, which may result in a non-editable install.

Updating matchit

To update the underlying Rust matchit library:

  1. Check matchit release notes for breaking changes.

  2. Update the version in Cargo.toml:

    [dependencies]
    matchit = "0.10.0"
  3. Update Cargo.lock:

    cargo update -p matchit
  4. Adapt src/lib.rs if the matchit API changed.

  5. Rebuild and test:

    maturin develop --uv
    uv run python test.py

Building a release

maturin build --release

The built wheel will be placed in dist/.

About

Python URL routing library via Rust matchit — radix tree path matching with route parameters

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages