A simple router for HTTP applications
Project description
http-router – A simple router for HTTP applications
Requirements
python >= 3.7
Installation
http-router should be installed using pip:
pip install http-router
Usage
Create a router:
from http_router import Router
# Initialize the router
router = Router(trim_last_slash=True)
Define routes:
@router.route('/simple')
def simple():
return 'result from the fn'
Call the router with HTTP path and optionally method to get a match result.
match = router('/simple', method='GET')
assert match, 'HTTP path is ok'
assert match.target is simple
The router supports regex objects too:
import re
@router.route(re.compile(r'/regexp/\w{3}-\d{2}/?'))
def regex():
return 'result from the fn'
But the lib has a simplier interface for the dynamic routes:
@router.route('/users/{username}')
def users():
return 'result from the fn'
By default this will capture characters up to the end of the path or the next /.
Optionally, you can use a converter to specify the type of the argument like {variable_name:converter}.
Converter types:
str |
(default) accepts any text without a slash |
int |
accepts positive integers |
float |
accepts positive floating point values |
path |
like string but also accepts slashes |
uuid |
accepts UUID strings |
Convertors are used by prefixing them with a colon, like so:
@router.route('/orders/{order_id:int}')
def orders():
return 'result from the fn'
Any unknown convertor will be parsed as a regex:
@router.route('/orders/{order_id:\d{3}}')
def orders():
return 'result from the fn'
Multiple paths are supported as well:
@router.route('/', '/home')
def index():
return 'index'
Handling HTTP methods:
@router.route('/only-post', methods=['POST'])
def only_post():
return 'only-post'
Submounting routes:
subrouter = Router()
@subrouter('/items')
def items():
pass
router = Router()
router.route('/api')(subrouter)
match = router('/api/items', method='GET')
assert match, 'HTTP path is ok'
assert match.target is items
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/http-router/issues
Contributing
Development of the project happens at: https://github.com/klen/http-router
License
Licensed under a MIT license.
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
Built Distributions
Hashes for http_router-2.6.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66d331fabe5d9a228070ecc758df9bba8bd86105398487e5428cc3a0103b788d |
|
MD5 | 65a0d073ddfdac4f332281286b5f3e1a |
|
BLAKE2b-256 | f43764a220ea9b9090429aafdf7a4391df4a4aa9dbd597e31e7e8b1e91e134fd |
Hashes for http_router-2.6.8-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1924fe35564ba2988ac415f3ef74e9e8ca954b29cb65b1f503c05abd474491ee |
|
MD5 | 5ae98ba5faffac41452a1a00be997b3b |
|
BLAKE2b-256 | e4adb3af56dce2b37e1059649082b10a97ad526ca093db8c69219cd8401abaa5 |
Hashes for http_router-2.6.8-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 797c156e0cb6144ea7e34a5d7184fada38b9ffefda97f32f2c9fe285993a59e1 |
|
MD5 | 313654d91724bf688bdf1419e23b8486 |
|
BLAKE2b-256 | 9de6f6ccda83b21e054f00ff7974c2dd3393057e78ae3877b4e865877793f4c7 |
Hashes for http_router-2.6.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e1b22c2c871f4fb852bbb45cd0cf6764854bbbe058daafbe1533b6095dc7d17 |
|
MD5 | f757fa75b8b31590825867f02cc20f83 |
|
BLAKE2b-256 | e1c85fb88b129b552a89cc5f5f5e476034b183c7b114e6da77788fa616311821 |
Hashes for http_router-2.6.8-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce6fbbf44aad969fd903c4fef734027b2c9fac034fd08d4157ebbdbf43298088 |
|
MD5 | 46651bf6ebc32bb958b9e5d59fb01003 |
|
BLAKE2b-256 | f999144e743ae370ce464100964445bcc623a5a95d4058743cb389891f184592 |
Hashes for http_router-2.6.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e147a9033f2a501ce7686e7b55e120ad41042ddc2b6ac1aee1578fe046bbe2fc |
|
MD5 | 91ba2182bad3f2d9bc12661c85887a5a |
|
BLAKE2b-256 | 23c21871de50d090b944d059be57127e394819249e40267b9493a92874bc890a |
Hashes for http_router-2.6.8-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eca065e5af17f8ee2c6c415eec9bf0a51bc7454c290d255b0edef1c2faca48c7 |
|
MD5 | 94fe0e2b9661530e3b20f0a39e7c54cc |
|
BLAKE2b-256 | 914616675724c59584a04db07dcfa4d98d2dfe45f2faba039ed8fb93fb97ed1b |
Hashes for http_router-2.6.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb0517bf12c4480cc43086a95f364746ce9eb3ad06c2efaaf71e3fabe539df4d |
|
MD5 | 8f25a382e749b9add525f25606fbe9ac |
|
BLAKE2b-256 | 428635a5cc9c796da26abacb25f349040edbfe3632de2c637206e86879d25d95 |
Hashes for http_router-2.6.8-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f646577858b96e4cf656322f04307eb7f2131bd9c72a788f4bf103e4bdd09b5c |
|
MD5 | 3b3d7149821488cd9ce172d9469d352d |
|
BLAKE2b-256 | 93348cab19642b383cf16e39e9e4e95e31dff8506f6e73f31b0dd9b7c74ebc96 |
Hashes for http_router-2.6.8-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2de4cce906a719e797588e7be315cb81aabbf99b68cb529bc869dcd28d8e64e |
|
MD5 | 97e9bf03b1bbc251e86eb2e99194a078 |
|
BLAKE2b-256 | f4007dd67935126fa18c6669494e6e3152951a0b532a642986fd0e6a158c0f3e |
Hashes for http_router-2.6.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f55659fe7fa21c89547c7a6dd3a19aac213ac9122ff3f126721c2149994bd18 |
|
MD5 | b34b5e2455548e21e3e8dd9331f33464 |
|
BLAKE2b-256 | d017caee5b4ec53bdd926affa243254b836f3cc291ed31cd9893f2571efc0963 |
Hashes for http_router-2.6.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c210500ce3ddecd77572b426b0a1c3d3b9dbded6881420c1e5bbb27d5fe3a424 |
|
MD5 | a849f43c0355f13c03f1dec9ac56312f |
|
BLAKE2b-256 | 4deb34455551029d1ac3e493db6cae5a31cb73a1f4c995cd155685b20aeff372 |
Hashes for http_router-2.6.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ff1a0231944154bec3d7a92c22315a485618f6af8406b8aa87bb5db949af0ad |
|
MD5 | 3b1b311b7f5bb163957091815f85cc03 |
|
BLAKE2b-256 | ccb9834d1de2ae18b212dd24a87447858c6584dc7be4c2af12295cedff42bc55 |
Hashes for http_router-2.6.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 218ed292631ef081a6287eb5b51aa22141c3565a3682fcff1ce1d85a50932d53 |
|
MD5 | 5c1156e73ef543655f450fb55c7ed07f |
|
BLAKE2b-256 | be006e685c89469eb573dd92001c7dc5ef540c38c35fcfd0eabef5af54d662fc |
Hashes for http_router-2.6.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4056813bccb6aa1c32bcde47e5fcfc637e51a17e8a12bbade16896dede64ffb6 |
|
MD5 | 6ef01a24f78623acc5eb06fff3b7a4d3 |
|
BLAKE2b-256 | ebed06e5ccdea8935d67c968e134982933440f418b8ae812f94d8cdb716d8c81 |
Hashes for http_router-2.6.8-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24f704b98f3d94b833c6c84852a40d5bd13137adda8944a6afe0422c3de53635 |
|
MD5 | 2af2369200786ac5ae33d799aede4f60 |
|
BLAKE2b-256 | f3ece3c24ebed0aef303d7b170197b5e00e7eab8f67e627e703ce66c10517595 |
Hashes for http_router-2.6.8-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e2a8a0e8164b0028ef15c0dba99c6c7b47c952816eacb683877865bce2bad4a |
|
MD5 | 441aa076f4247aa39657815625b19d13 |
|
BLAKE2b-256 | be14dee580b629d26aa64aceaf328be5aee45ee81730fe32d595a40c6b8b7e2d |
Hashes for http_router-2.6.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00336d516bad7533eb0904bf7d119ca61cb0b121ddb1b7fe85bac6b6145c5c69 |
|
MD5 | ada55990bda64d7ba6af2e985b1f8c06 |
|
BLAKE2b-256 | 420f69373b08c0ebe4dbd4717cbef0e59e30ad4d2635b88f4b5afbf3ddb79bf8 |
Hashes for http_router-2.6.8-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aab4d6b0e62f9b02464e5ac26f4a3fa727fd532a2dd979bea4b1783d67708647 |
|
MD5 | de342c926c296a898121c68277d95759 |
|
BLAKE2b-256 | b1e64d9745c4c5b257df5c877e1e1ec3cb81a30d0a740bac9a2cd79f8d2b7b4c |
Hashes for http_router-2.6.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8c8932cb88b89f63b1b70db744952cb4eef295f39c182621812e8d036274664 |
|
MD5 | b3aad20003cb86bf8c9d47968a3426a3 |
|
BLAKE2b-256 | 2d876997aaaacc4504e6408fd5404bdaa7393bd2e94886eb4cc1b311d2eb2e3c |
Hashes for http_router-2.6.8-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0231c75e5bef7ae7f43fee7b7965e01d25c214f11d600ce523514fb128745faf |
|
MD5 | e55d61d6dab0f5b019b52565d67badbd |
|
BLAKE2b-256 | 349461c3b0dc83c5514d7e6e40bc39aa8f45a7a9e1da0998e00609c893f372fc |
Hashes for http_router-2.6.8-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b4a2c2c24526e22a0a734da5f1756687f563281304d6f2492bbc9f101bf855a |
|
MD5 | 8d7dfa95fa09bdcd80eee5d86613bd15 |
|
BLAKE2b-256 | bd339e5d6cf96ea37520ea3cfd1eca400139e584dfa7736575fdf84589e6956c |
Hashes for http_router-2.6.8-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bbf8d710ca605edc9e7388435cb9b2457e739715c2bcb4d761533edf7355cff |
|
MD5 | 4843a9b59238ebb156030476e42be49e |
|
BLAKE2b-256 | f78affd411735e3bb998b0177932cb6b4390cfaadf0993328832dc5278e10ae8 |
Hashes for http_router-2.6.8-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f9f5b20c36394147c86ed5bff70d47757d75a09bcf053dd30c707c625c67bcb |
|
MD5 | 58901d9f255a0b494ab82dfb315696b7 |
|
BLAKE2b-256 | 534d7b0d5d32b8e0aeb3ada95ec02dfd1804ae02232e5ccb1bdd70582918353b |
Hashes for http_router-2.6.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 224ebd29f1189dc85f6350f6048849656b558799c3bab6bbe0f08cf80c121c5c |
|
MD5 | 3843ae52ad0ac98d049df83d597bdaad |
|
BLAKE2b-256 | 30a92b093a69b5063e0d17396acff4d5a16d6edef094622170d58fe4549a76ec |
Hashes for http_router-2.6.8-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ca21b79890238636c1afc3f9e79c28235e154394c704841d23c6116cf9b8014 |
|
MD5 | 21c4257c623f0c461d9d7ec4868b2f42 |
|
BLAKE2b-256 | e29cf1ea6f8615603a2876c14f8c179aa86d107ecfac2e26663aabc6bbdaec98 |
Hashes for http_router-2.6.8-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6592cd9f6b145bedd237e39df5466cae1f949e760a97c6492a976cf330de9ce4 |
|
MD5 | 67c3f238c81b73c4fe2f0fededde7af8 |
|
BLAKE2b-256 | ed32509e7804afb2df29892ac38cd4128b171a377b60ac1cdf183a8a5dcb293a |
Hashes for http_router-2.6.8-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b204e7d57a2a66997d6188a3f6f000aaf635bfb7acb58a5ce014010a527ea9f |
|
MD5 | b3b171c400230608b91bf38e5da02b98 |
|
BLAKE2b-256 | 66eba0051a540352f9b49b7e31e2bd02b84607de31cfed824084dc4ceb3d9022 |
Hashes for http_router-2.6.8-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c48b3c1422a382b548023c9eea0914ebc91b539d8bba147072d71faf35f48b9 |
|
MD5 | 90d1fd627f44b31930bfc2aa92498a19 |
|
BLAKE2b-256 | 363d6be10a6b7f9c38ad50ed1908e9378d2b122712b94c80cb6163157e1b9a9d |
Hashes for http_router-2.6.8-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a063cb29426acfb2260e6152a21815fd7246fed4ed163af03911ddcf34c67a6 |
|
MD5 | e281e44040c25fcb847bdc63fcafcdbf |
|
BLAKE2b-256 | bf02a2e7b9a22039164eb6f8b362cc6fec8f7407de0b2b8f153e0061daf4e8c7 |
Hashes for http_router-2.6.8-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfb1a0d9b843e4c66b1f536cffe8cbdbff9e57086b6c849d5509c50b6a30c1a5 |
|
MD5 | 40758731ead2ad0e01841a84e4bf6d44 |
|
BLAKE2b-256 | 42fa383f0431c1632abd33096d19d020d41f13a5ddc5379a4928e209d433c9c8 |
Hashes for http_router-2.6.8-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9529550f4f3ea50e2baa20b3eb0b78db2c60df06ed0c55bc71f69c5e26c5a0aa |
|
MD5 | 2c5cca209d2b3e162e75ee0d378f45de |
|
BLAKE2b-256 | 9f462fbfca191905214eae0f831a84beac78917b6c305bbe781b6dea9e6084aa |
Hashes for http_router-2.6.8-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68ba47262ebb7538d783c79722e1784a7830b625ac361531880519e79d5fac69 |
|
MD5 | d33d687d1ab366b3f7dc4834a4583e45 |
|
BLAKE2b-256 | ce35a85164be1eeaf56e982d5317f9064698ecf1a51b140741530f9d0419003c |
Hashes for http_router-2.6.8-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3c016175f5c21785b17d6e234c208ca35d1212e43c965c0a552769e6b2963d3 |
|
MD5 | f6921327ad142309d1d74ac45a2a0186 |
|
BLAKE2b-256 | 4d31ba135bcbbcc56709feb7c6331bac36e0a28c54466c17075c344fb5949fc6 |