A simple router system 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-3.0.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdd8b991ba8dcd8ec2a435f6cc1019a0447e7eea15b39413b863a63bf4753173 |
|
MD5 | d49acb19ac902861a719862701b82b96 |
|
BLAKE2b-256 | 87fd92c53d02e68c0e4bc2528a333807f7112ab61017c2be0dc5a0d93f3ab700 |
Hashes for http_router-3.0.7-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7ccd48495cf50f31e0dbbf7e169237566eea19d8b51d2f95cbb7f5a10d5ec0e |
|
MD5 | ac82ee283cd98d39ddc079660d9bb71b |
|
BLAKE2b-256 | 8d38caefcbe84589e8fd63d7f15dd873fe55b8a4b8e9e63749105299c41d8db0 |
Hashes for http_router-3.0.7-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d0769d98ea1c25ceda0c50078cd6e54b226052e741c2083090b5045ae168098 |
|
MD5 | fd539a9e0ef8f9a7254b7d98fdbf91c0 |
|
BLAKE2b-256 | 1bf13b0d0ca2d0cfe66224a7033b9d544c0ce8ba783cd0f071af8ae5e159bf36 |
Hashes for http_router-3.0.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72c15c864a813e63c384db8869e0376e4b77bd3d000be1d104632d3073ee11f0 |
|
MD5 | 83137c33a14c0203f7a06d298f819c20 |
|
BLAKE2b-256 | e74e5e76b12bd9b1a73b7aec0af8b067ecd137645d0f4b5982130203e8608536 |
Hashes for http_router-3.0.7-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a22d989667b7848b3f94f308f0d5be718c3bae77378a31a7f85498981bb04cc |
|
MD5 | 58d447d7b6e09cd1227b995e6ae1c16a |
|
BLAKE2b-256 | 7b52b9a146d57a6994b511fe7cfaea2ec50a8874aaedbeb41bd82eb66d0ae1be |
Hashes for http_router-3.0.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 854da093ca4b70be9a54929800cf4d097a5cfcaf9f73a860e44d480cafa0a446 |
|
MD5 | 4120533c94b0d3137e0093d4a6d38091 |
|
BLAKE2b-256 | 674e5e2d2674a76f318e451ae27e8efa8230324005bf88a427663a124463a7b3 |
Hashes for http_router-3.0.7-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dd60d122bb2943e015fced3d247c43eb5d124cf486cd3b9270c1ba6f9f043dd |
|
MD5 | 28812aef9074c7f04c0c35afa7b41d9a |
|
BLAKE2b-256 | 10980037bcfcf450545163874541d53036a1b3018cadf956a5cf606478cf3a0a |
Hashes for http_router-3.0.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64fe388f4fa22dcd8261e6b1ee543f1cfa721e4137941eb65f16d1ad153afe1b |
|
MD5 | 62921b004979fd48c8fd5aa55b017b25 |
|
BLAKE2b-256 | 137a9e9ec2b044cf2577d5c24bcf2f211a0a8c0f0b42632d3bc32e62e34df2ae |
Hashes for http_router-3.0.7-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de6a3849af1f1abb6e7cd361f48c0dcd6ecf31101f533a6aa4963c73ba46475e |
|
MD5 | 94b2d1547772d00f2a332d08c575211b |
|
BLAKE2b-256 | 2c588a5ae0c7a3c156dc8d2d9bb2859bfc410bed6607beb04ea3529085231bda |
Hashes for http_router-3.0.7-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c19b5b4dd1ad6cbd4f8714643a3511df1e306add423f45928f34894f1bc9640 |
|
MD5 | 314e10a04b4aac6651967a60c007ef0e |
|
BLAKE2b-256 | ff702ace819a57e7811d217adec72d8b3cebd3a5fa5a6b39cd27a297e888e5f3 |
Hashes for http_router-3.0.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ab0af4cb876736c517fed41d5eae8f38455e8fa5d66e57d09ea1facf90f1717 |
|
MD5 | 1b974dc770eec171e8251151e0af5f75 |
|
BLAKE2b-256 | 850498e29241aa8026359fdb0337ee27e86fc8ce01a772dcb31554bcc038c24e |
Hashes for http_router-3.0.7-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e66fa638869832e912fa2536e64828cfb5d19212385078b207c400b770aca92 |
|
MD5 | e6e6beff0f5cdc7ff123062b3c5274fe |
|
BLAKE2b-256 | 9bb80433504ddd43529ba0df8f5cb19550e5b3af5df4a35e3181ec53a67d499e |
Hashes for http_router-3.0.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73ac126b081cf5076fe0840f46b4a6e41244b95f2098a423408972ac2620c895 |
|
MD5 | 477ff1a77ab682414046dd6b7006edd6 |
|
BLAKE2b-256 | 2c4917d4b972cb16e70de32c7493768b3b79dd5f37e5f4a3ebe6a01fd838432f |
Hashes for http_router-3.0.7-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44dd5c558905922ed6be826469da709f85eb05ba752f12ead1c4720215ecc964 |
|
MD5 | 5696559076ce78629947196234862f8f |
|
BLAKE2b-256 | 072774ec5132a771168d961542e7d2bdca2f102891b64285abd0aa4b413d890c |
Hashes for http_router-3.0.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd4b9ac72284035492e0af7c3d236af593a5e0383c925caad6b560a9d8e7c2aa |
|
MD5 | b097c6456bce7d1f902e632442a43322 |
|
BLAKE2b-256 | 3ccabb856b32cafdc8ca91c6c5d14a3d558d6aafaab490032e2b6db2e514d2d0 |
Hashes for http_router-3.0.7-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 152d251ac33d341a7c3ccbc291f664db7376d503cdc34196015c76cc4d861213 |
|
MD5 | a453937e5d016a73be31f1723695d151 |
|
BLAKE2b-256 | e5f23e1aec6b60ac5b5d491fb6f942ca7049e31ad17e7a44e50996f53703e842 |
Hashes for http_router-3.0.7-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de40614103b16b96db47d4787efa535b24a594eb55418e129628b2f62bdcd02 |
|
MD5 | e693c819b4adcd50b89e7b0bf9229bd3 |
|
BLAKE2b-256 | 03bc441f54f7a7cd052902019c9f025ca37ed48f829beb20e241d4f2fa1f2523 |
Hashes for http_router-3.0.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a1de7448cebad8e564a88fa1a96063454a58b25b21d7ac5c5e83ad9191630b6 |
|
MD5 | 79bb9d4c2ae01146736ddfc8ef30b664 |
|
BLAKE2b-256 | 8ebb5240d2ab5a9369d99e249034b09d671a8385887456955604c33e960ebddb |
Hashes for http_router-3.0.7-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b968a5823ef7d06980478bf7e9123764fae784375582f32c023baafac69aa4 |
|
MD5 | 4123d5fcec501b2a92a47c39e6a75c95 |
|
BLAKE2b-256 | 5b7d0f62030a8ce149cd754f3a35c7202ee932a063d089c34b0d16c8406caebe |
Hashes for http_router-3.0.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5578f1f484e24a4bbedb2330ab6a527bb66ea0d759eecf568de358da1b5fdea |
|
MD5 | 06357ae7786a9c1648463a0fac35a18a |
|
BLAKE2b-256 | 4d4281d86a911a807564229a3e93a7438068bc54becfe489ae1446385b8e9220 |
Hashes for http_router-3.0.7-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98e3c0a7993b4a03bdabf06eabc89b04e6ef72ff83debef74e519754fd881619 |
|
MD5 | 06631be02178a5b0e14ad74788a840a1 |
|
BLAKE2b-256 | 1b3c48ec11cfd1636b38f1ead6c7ca802fdc563ac76c29247fa7fda9aed0e674 |
Hashes for http_router-3.0.7-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6bc7ce3adf57040165ef53ddc1723f0e0d85a914808285a2a9ca1acb200508e |
|
MD5 | 01167c2a8e162edbde476096612a8cd0 |
|
BLAKE2b-256 | 92887cf4b8621813e44a38ebc9a86c1cba0481f9529287bfdbc3bdb0ee88eeb0 |
Hashes for http_router-3.0.7-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dee5b647226cced02f4d285accec02d7f388afe992468207bb115b90e674ae4 |
|
MD5 | 71912a5cc1bb3e717b2feabfde225adb |
|
BLAKE2b-256 | 936821dad9438ab30fa25445b844154f1fc03dae5148617c7eb4913ec03ee001 |
Hashes for http_router-3.0.7-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50f96db343622efd0e04d5a4656dbdf6ecd94cc250e37d7e5f26f135e5e36900 |
|
MD5 | b94684433a0df9953156942d8e5c86c5 |
|
BLAKE2b-256 | b31d0de7fcf34c5d8437bd6b7ee8c1e0957bd3606b488ab2f020d9d4dccda088 |
Hashes for http_router-3.0.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c45b131fd963f91d245c64383d050e63a9c8a1e4b735b3db60d2374b75ed1408 |
|
MD5 | 11931c0c3d4440dd2d194f4eb6aa3602 |
|
BLAKE2b-256 | 61747a831feaa8eaa6b7e9039a5c45b67937b7307f293726d781ca5511d9c21e |
Hashes for http_router-3.0.7-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9122170732b55610c093aecba395627f55a1e162e102e17ef952a159c79b29cc |
|
MD5 | 099b675ab3ef48067013127acf8fc11a |
|
BLAKE2b-256 | 0a12f49bbae22429df7b015edfb8316433fc71111dcdd3418b75e0500c9756ed |
Hashes for http_router-3.0.7-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd253e10391f8a74d72dd98edb19172bb5debe4ec4cb82ac70afcee95e48bc3f |
|
MD5 | c190fcb731304eea7ac8dc733ad991ea |
|
BLAKE2b-256 | cac8a618b1d0d9a99805ded034a049ac61fcf9213cdca01c40497fa9da1d01d8 |
Hashes for http_router-3.0.7-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9d9b5cc08937dea5e31e497dbc738fcd244639ef31e1120234ec7f887bc70a9 |
|
MD5 | cfb972a1816832bc60787e37c2912306 |
|
BLAKE2b-256 | 840540f8f925154fbaa83f32f6b9d9743c4ca17f0d74b2ce20c20622dda4a1fc |
Hashes for http_router-3.0.7-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1a859e3ba35e0f94c67948df3110e6c08856e5cf984bd9823bb0269f1aed420 |
|
MD5 | 0f2a51bcb81737cc48b11b16ff513aab |
|
BLAKE2b-256 | 404c6a54c53643d4a5e3b60f784a028558a33c13b347f444d3875d59812cb357 |
Hashes for http_router-3.0.7-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eb0eee805669017fb607c99deca6940acf8dd8a9e781437af868cdbd4254619 |
|
MD5 | aada8f46553da8a4fc71ef4c1f85514f |
|
BLAKE2b-256 | 6875d074cb2cc3d8a1cf247a394557808426e014f698ee018e632afc4ffea24e |
Hashes for http_router-3.0.7-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92c6757dd7eca49923f4717be4dec8e7d155a659f2d8b2cf61f67f8c259234d6 |
|
MD5 | f38bbe16ba1090792cfef31a67f7bfa3 |
|
BLAKE2b-256 | 9b099c240c650204c20f1e4fb27b36b218dea0a4a8d96576368a1a15517c2370 |
Hashes for http_router-3.0.7-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d05488d7c008aa7b8a2d4a4bb5a9082783647129e9b13bb4c5335dafad5d42 |
|
MD5 | c553d6d85181aac723b20ede13308ea0 |
|
BLAKE2b-256 | 13d856b9e8246e589efe0649cefbc8ed73b2a929741edf6fcf2edc491fb1483d |
Hashes for http_router-3.0.7-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7608a521840f93c8dcfd9faddc905268a4adba60ed094470a24a9a3e3773eefb |
|
MD5 | fea0712891e66cdcf433d73462955933 |
|
BLAKE2b-256 | 610f2fb5ecc334fc925a09e2b5add4ce28e593edf48e90fa902746f2039d247b |
Hashes for http_router-3.0.7-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30ed4f7c6d1ea63016b75e993c060bb038c41ba42a4e03833585970b5a2de83c |
|
MD5 | e7a3f8a9efea4cebd1d515804c7c957f |
|
BLAKE2b-256 | 0357f49acaf85f0c56053aedde40b1addf87db05bb361bd0d17a12cc488cb4ba |