Routes for speed
Project description
# Autoroutes
Routes for speed.
## Install
pip install autoroutes
## API
```python
# Create a Routes instance
from autoroutes import Routes
routes = Routes()
# Register a new route
routes.add('path/to/resource/{id}', something='value', anything='else')
# Try to match a route
routes.match('path/to/resource/1234')
> ({'something': 'value', 'anything': 'else'}, {'id': '1234'})
```
### Placeholders
Placeholders are defined by a curly brace pair: `path/{var}`. By default, this
will match any character but the slash ('/').
It's possible to control the placeholder type, either by:
- using a named type: `alnum`, `digit`, `alpha`, `path` (matches everything),
`string` (default):
path/to/{var:digit}
path/to/{var:string} # Same as path/to/{var}
- using a normal regex (slower; also note that regex containing curly braces is
not yet supported)
path/to/{var:\d\d\d}
Placeholders can appear anywhere in the path
path/to/file.{ext}
path/to/{name}.{ext}
## Building from source
pip install cython
make compile
python setup.py develop
## Tests
make test
## Benchmark
![](benchmark.png)
See [Benchmark](https://github.com/pyrates/autoroutes/wiki/Benchmark) for more
details.
## Acknowledgements
This package has been first made as a Cython port of the [R3](https://github.com/c9s/r3/)
C router.
See also [python-r3](https://framagit.org/ybon/python-r3), which was a first
attempt to wrap R3. I was unhappy with the stability, and more curious about
Cython, so I tried to make a first POC port, and was happy with it.
Routes for speed.
## Install
pip install autoroutes
## API
```python
# Create a Routes instance
from autoroutes import Routes
routes = Routes()
# Register a new route
routes.add('path/to/resource/{id}', something='value', anything='else')
# Try to match a route
routes.match('path/to/resource/1234')
> ({'something': 'value', 'anything': 'else'}, {'id': '1234'})
```
### Placeholders
Placeholders are defined by a curly brace pair: `path/{var}`. By default, this
will match any character but the slash ('/').
It's possible to control the placeholder type, either by:
- using a named type: `alnum`, `digit`, `alpha`, `path` (matches everything),
`string` (default):
path/to/{var:digit}
path/to/{var:string} # Same as path/to/{var}
- using a normal regex (slower; also note that regex containing curly braces is
not yet supported)
path/to/{var:\d\d\d}
Placeholders can appear anywhere in the path
path/to/file.{ext}
path/to/{name}.{ext}
## Building from source
pip install cython
make compile
python setup.py develop
## Tests
make test
## Benchmark
![](benchmark.png)
See [Benchmark](https://github.com/pyrates/autoroutes/wiki/Benchmark) for more
details.
## Acknowledgements
This package has been first made as a Cython port of the [R3](https://github.com/c9s/r3/)
C router.
See also [python-r3](https://framagit.org/ybon/python-r3), which was a first
attempt to wrap R3. I was unhappy with the stability, and more curious about
Cython, so I tried to make a first POC port, and was happy with it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autoroutes-0.2.1.tar.gz
(71.9 kB
view details)
File details
Details for the file autoroutes-0.2.1.tar.gz
.
File metadata
- Download URL: autoroutes-0.2.1.tar.gz
- Upload date:
- Size: 71.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5285654e740423112a519d36dfc38e61c9db7881eaea1d9a33034d8d21b36c2 |
|
MD5 | d8b36c32034f041f9b7a6ce7935db000 |
|
BLAKE2b-256 | 2381050a97b7968d9f8b2e67f5f912ee14da5b687a50647470aaf6dbed7a12a1 |