Metadata-Version: 2.4
Name: python-matchit
Version: 0.4.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Summary: Bindings for matchit rust library.
Keywords: routing,web,url,rust,matchit,bindings
Maintainer-email: Roman Tolkachyov <roman@tolkachyov.name>
License-Expression: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: github, https://github.com/romantolkachyov/python-matchit
Project-URL: issues, https://github.com/romantolkachyov/python-matchit/issues
Project-URL: releasenotes, https://github.com/romantolkachyov/python-matchit/releases

**python-matchit** is a Python binding for the [matchit](https://docs.rs/matchit/latest/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

```shell
pip install python-matchit
```

# Usage

```python
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

```shell
uv sync
```

## Testing

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

```shell
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](https://github.com/ibraheemdev/matchit/releases) for breaking changes.
2. Update the version in `Cargo.toml`:

   ```toml
   [dependencies]
   matchit = "0.10.0"
   ```

3. Update `Cargo.lock`:

   ```shell
   cargo update -p matchit
   ```

4. Adapt `src/lib.rs` if the `matchit` API changed.
5. Rebuild and test:

   ```shell
   maturin develop --uv
   uv run python test.py
   ```

## Building a release

```shell
maturin build --release
```

The built wheel will be placed in `dist/`.

