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.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 805e9d9ba56344691b4e9cd9066d453006ba783858b4d38f4d5dd696e09582f8 |
|
MD5 | 5f8140ba5fcaa55f058f11f201a15b44 |
|
BLAKE2b-256 | 80d83ba5b16cd2d3355a7dc52a6321ec2ac36a8009a750a90a255bfcd6958ba3 |
Hashes for http_router-2.6.7-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08f39a6a6b344bd80d089d6c5bc07a3a9364afcbcad9f24b45245bb5fa090244 |
|
MD5 | e87d7a6529b8d972050553f04ea0eef8 |
|
BLAKE2b-256 | 22e9dc8c92eece1d6f3f9ac13f6bd922f5a86679d674bc412ecb036d55af82dd |
Hashes for http_router-2.6.7-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aefba138a698695fe8f910fe5bf6659bbbd72cf9c4112de1e62e5fb5ca7f292 |
|
MD5 | 8f8d6efe8bdea5f3f1ce82228de639fe |
|
BLAKE2b-256 | b1a5a80de1406d44e1994333c0d05ffa4f51c625f41629efc2f1ee25fff0825c |
Hashes for http_router-2.6.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bc53ef649345c1026bba9e712bfe469667fefc45eee72518463c22b7f81bea1 |
|
MD5 | 3ce8fe4d49f54a478caf3ce5beef36a9 |
|
BLAKE2b-256 | cf4d1767cc40abb91336f64ef45210ff720d8bfb2eb07aec35884e976378d031 |
Hashes for http_router-2.6.7-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a016d4a72b7abf4bbea3804641c2e547f7ddf53c6fc27831e4a38f8d3e040a61 |
|
MD5 | 58b7f3f01742af72dc5aa6ebb2ad78fe |
|
BLAKE2b-256 | 7ab806f06d1b2bedab3ee6ba54696c6641792af5359b2b449e7ed8042c4a1382 |
Hashes for http_router-2.6.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4115967f5345ea8cdd9e935c08e277e560710665f64024956caabfc3e40f42c4 |
|
MD5 | 2b969cd572806b615765f7adb4ff9f5a |
|
BLAKE2b-256 | f8ce7c3700ae64153465e79acf2d46dac272f955989c20a23db6b76763d2b433 |
Hashes for http_router-2.6.7-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecfe7921613fa190e90be3d681582636e4eb91dc73758d6737f3d0452eb31c59 |
|
MD5 | 92c8586bdb3a3d23adbf19f7f8be55f9 |
|
BLAKE2b-256 | 79e892c4c2825c335c6e6206e7d3da336210eb22bbd3136272a454ede9c6c22a |
Hashes for http_router-2.6.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07e23f626bec195a9d8e5b83168034a8093b892fb1b5e275601a1358e58de089 |
|
MD5 | 3200094cc8c9ae24eabf2cbec8ebd582 |
|
BLAKE2b-256 | aae5ca35c2654802fc3ead4fd496e0885d5f5541073619e3830ca79d3d07c6c2 |
Hashes for http_router-2.6.7-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8165ef3cc13c66883217a1677762b6330bd63e5154329df5d8b222190b7048f7 |
|
MD5 | 30cd4f48e451c698792fe0a82c38d183 |
|
BLAKE2b-256 | d2dc2d7e72c69f1bccc15bddf3793d410d8fa96626a493a07f4defdc06cde3a9 |
Hashes for http_router-2.6.7-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d11958d36177baf128aa053f5e9d5ba7f4c8b716e5cf9da1d66a0d5ffda708c |
|
MD5 | cfa3ef6333965b1467b382517df854a7 |
|
BLAKE2b-256 | 6bcc16d14767d690535a27127dcfb5b4ba3ef61fa0b0e285738c92a7b41a204f |
Hashes for http_router-2.6.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48db9a9764f63402871e048de0783f261667317bbb3e24f3785c70477c3308f0 |
|
MD5 | 95c34b226f1261e05286caf1abd855c9 |
|
BLAKE2b-256 | 7343fcd2bfe0a5215d381f7f5486756d4201dd7e756e5c87955b3da16b1c1a52 |
Hashes for http_router-2.6.7-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8b8f27561bc0959aa6298d4a222c554fb16c853fb4294e530e16a24becc49e9 |
|
MD5 | d8875c868596b3823d69e20394ff623c |
|
BLAKE2b-256 | 768f3f8747991fe13b3ae812f8fc17b6a53dda058718f117cf887de878807ecb |
Hashes for http_router-2.6.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 726b50d3de9ef39645b8d70f5aa62261b70bae56d9764a9b819c3ee97a250e97 |
|
MD5 | 1a2a553ace3c5525ff9d89b504b0a68e |
|
BLAKE2b-256 | a86fd3471bcdfa4f95b6fa001dc3dd3cbe88462c3ef913586cc1cec43798eda6 |
Hashes for http_router-2.6.7-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce2bee66eeea51eda8524e345a83d03db783fd6ec63c69404c867dd2c5b11f0c |
|
MD5 | 8ec5ec2f3914e4275f985dea442cd6aa |
|
BLAKE2b-256 | ea269c8b7966b624e55e424e0c7127e26f1b6f724ddc8e1bf8e584a7c0c94822 |
Hashes for http_router-2.6.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0715d14afb13bc5ebb831ae8c5a4280196a42fa7fbddba98f4d3d940f2c5136b |
|
MD5 | 431a003ce01efac6102a3677b484ce6d |
|
BLAKE2b-256 | a770163a9b4fcaa6e923b5a2dcd2f74e4e484f6407cc09d01605989219da2ea7 |
Hashes for http_router-2.6.7-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a2af7a4353321f134f17d73d1d522c5498a623103b45a1bfa28e1e6056287d5 |
|
MD5 | 24506011f3a98f22f426bf5bebacdf72 |
|
BLAKE2b-256 | d7db1a5be14f155e1773af1ee12a3edba716bc50c5a30395d963632fc3e1b6e8 |
Hashes for http_router-2.6.7-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a8f6840b9b37d87aaee48638e76627a5ed4cbd8db1cb9e84779ad3b955ad986 |
|
MD5 | c20713148787b236f643b0d5ab95d7a9 |
|
BLAKE2b-256 | ecdb7f4ae16cf3857be616668db157adbe72cb939a5f34b53c9b6a08ae3a01da |
Hashes for http_router-2.6.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd7eff88e54a094c33a73e64377f387e738b3395a9f24ce1ecea84fb19151cd9 |
|
MD5 | 8feeabc790b8d6b9c1cc86a14c08ddef |
|
BLAKE2b-256 | 700c6ff4d1c343f22903084530e7a3814f61a726c20c83694ba117d5580c8144 |
Hashes for http_router-2.6.7-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30cb423b9b43044e5d04f5f6fe55c089735e65fe1e6ed402456d5148959b22d8 |
|
MD5 | b11bfaf5ef197b893b30fdec6a57e2ee |
|
BLAKE2b-256 | 997293f5c92da95b3c600d5964b189da5b8607f9b72a7e1723c848edf80b3140 |
Hashes for http_router-2.6.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fc7ec65ff569f6f79b58b2e4454b5dfe250252632a1ecbb1bbb24f0703de3d7 |
|
MD5 | c2c3b5cc8991aa76f791001ffa2a0f06 |
|
BLAKE2b-256 | 3d8b3a6886fc978e342f18acc562c3dcaa0d4da5a08790f302adfabd11eec405 |
Hashes for http_router-2.6.7-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893b4d8297b4c0459b5426fa272deb50ce93ed04af633d18b6880a3dae74a625 |
|
MD5 | 864b592775a8dbc291ee5450bd175bcb |
|
BLAKE2b-256 | 4825f9418d977985cf7e5208eb6677ceed536b38cb6913f2f570dd6095651650 |
Hashes for http_router-2.6.7-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d69959bae815f83fdcbc1f3b5a512581491fa32f52eec1b14a752a987abc649a |
|
MD5 | ba43e56a25a2cdd7881f396efa75e698 |
|
BLAKE2b-256 | cb46b48894d09a99bc6f0571ac648cccd3993367f5f0b688e27ad3d19f5635a4 |
Hashes for http_router-2.6.7-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70d4dc06d7f5c371f68345af7d3ea00c7adf93f4ad78fccd0f4de77865ab49bf |
|
MD5 | bc974a6153d7d53d81739a32adfe64c2 |
|
BLAKE2b-256 | 24547d9006e2c54def43f402e7cf24db20a02c90915f9261f01206e656e030fc |
Hashes for http_router-2.6.7-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bc3ce8a27ae24cd92c3bbccc134ee7089f8903bfff9ebcc930186073b96fd8b |
|
MD5 | d2495227a8919df4e5a61822ab2ff9b4 |
|
BLAKE2b-256 | 345f84eab6e19230664090af3446f7094aee5f3f12f8a537841d9d4b173cf722 |
Hashes for http_router-2.6.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b9cfc58d585750c07419a65555d7e61da8c70705af76b53cc0a4ca7161230e5 |
|
MD5 | cdc86a0aa2524d4aecf3be517fbbc12a |
|
BLAKE2b-256 | 8236196f87767494e33e4979290cf06a46afc1a41e6953b021d3b4752d075d89 |
Hashes for http_router-2.6.7-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82321acc902b10bb64d607f2d32fc440898e20d64638f295ad5e9082e4313743 |
|
MD5 | 89cf55bcfaffeb7fc6e128be026b3242 |
|
BLAKE2b-256 | d4155d84b2aabb4a2ade352b53e4b4b3e5a9a097e09437e26922958cd7b2f1ef |
Hashes for http_router-2.6.7-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eff2454909f2aac0a78e44def1859163e0eeff5037fa7f45d5da431f91e61558 |
|
MD5 | b60c9176469a7aa2e7a22467e872f138 |
|
BLAKE2b-256 | c8f7db685359ffa0bbff999570b072a490d8e94f93d0e6d4f44e017b6215ffd6 |
Hashes for http_router-2.6.7-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc090ab7f40923ff982eed098ca8a4da5eee0402f7de8577272b464ad69d589d |
|
MD5 | 5e2130c2b91b1aedfddd8c161dd4f132 |
|
BLAKE2b-256 | d9dca8a688975b5593922d99ae1acf88e7b383015ec0f9dcf0668fb019139ade |
Hashes for http_router-2.6.7-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2afefc84c7b93d93c2f7053f37c8b06365d4475b5b9fb69b77d9169230477d92 |
|
MD5 | fad136595f4878db0a1b80e5575e9f3a |
|
BLAKE2b-256 | 4cf7b840dcafd0bf776ca6eb4ec0540435d05d7cc6945a8d8c5f2a7d592e01a5 |
Hashes for http_router-2.6.7-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4ade28818ace71c05d4cc576e15b8a7f6309497078d0caa48f6f21e44a22ac8 |
|
MD5 | 5f5f661891a9793007c917b5dbbadbdc |
|
BLAKE2b-256 | 49425ae4051a8c341d2f824a55dd02016472e8f88a2af549a9d9125c81076913 |
Hashes for http_router-2.6.7-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2300ed7756e06c075c3b1fc3df6997888eeb53abc4d3c166cd977f6ba7f808 |
|
MD5 | 7ebc3e9ad3d887a60bd1719584d4ee4d |
|
BLAKE2b-256 | abc7af6d51ebe5d6a431aac4e68878a53f411af0cb67f7ab1d57c932ff84578d |
Hashes for http_router-2.6.7-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e2902fc84fbc7798858f1e46d9331e211152ca1e6d4180a7985d15ccbd2f3dc |
|
MD5 | 03852dbdeb5e8b6013fc714c63446edd |
|
BLAKE2b-256 | 3af171e5e06f1c6facd4c44dee401c21be107b980ce0aa77cf980c13051fb905 |
Hashes for http_router-2.6.7-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae8f606a9185519f2c528df0162804e0c92e51538817cbec0b89a9210ecac24 |
|
MD5 | 16af47837410c40db910f95ad6891d84 |
|
BLAKE2b-256 | e5a727abfa0641bc7dcae9e9ac917e89065097b8b998a55430f67af2eeea5d3e |
Hashes for http_router-2.6.7-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06ee513dbacc58c455097625d39cb4a19d57db578dadf70ef97603ba5c01ef5e |
|
MD5 | 339ec41cc59c3d564355b0975f93d2c6 |
|
BLAKE2b-256 | ce5e2129ad810663286da8937b7a719e26c635d2a87f7e844a0ebb0a1495bae8 |