Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- uses: astral-sh/setup-uv@v7
with:
version: "0.6.x"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: |
uv sync
uv run maturin develop --uv
uv run python test.py

linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
Expand Down Expand Up @@ -162,7 +180,7 @@ jobs:
name: Release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [linux, musllinux, windows, macos, sdist]
needs: [test, linux, musllinux, windows, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
Expand Down
94 changes: 27 additions & 67 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "python-matchit"
version = "0.3.0"
version = "0.4.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,9 +9,9 @@ name = "matchit"
crate-type = ["cdylib"]

[dependencies]
matchit = "0.9.1"
matchit = "0.9.2"

[dependencies.pyo3]
version = "0.27.0"
version = "0.29.0"
# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8
features = ["abi3-py38"]
57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
**python-matchit** package contains binding for [matchit](https://docs.rs/matchit/latest/matchit/) rust library.
**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

Expand All @@ -10,7 +12,8 @@ pip install python-matchit

```python
from matchit import Router
router = Router()

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

res = router.at("/users/123")
Expand All @@ -19,24 +22,62 @@ assert res.value == "test_id"
assert res.params == {"id": "123"}

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

# Development
`Router()` without type argument also works.

## Updating matchit
# Development

To update `matchit`:
## Setup

```shell
cargo update -p matchit
uv sync
```

## Testing

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

```shell
maturin develop --uv
uv run test.py
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/`.
Loading