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-4.0.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4915a1076c8418a21ace39854582fda5fd3d101c35abf1d790e9b89e0db0b1df |
|
MD5 | 0d48c74c1589ea9bd09a303e025f581a |
|
BLAKE2b-256 | 19262d30678586b8c0e4a1798e0754cd9ed9f3bdc915d0ca8d1e47e19b2c5b9c |
Hashes for http_router-4.0.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a1209dd1431cf693c766f90fae158a6e51ee29675f9b5eda567f78d16cbfafe |
|
MD5 | a17d1bc9c2a5f4a58a0b1b47e4f06207 |
|
BLAKE2b-256 | f23b5caa404b3fe299c0a531af765d47a9fc0396bd192b5c6183910d257f7f8e |
Hashes for http_router-4.0.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c274f6d98d79c15c4329b6825fa18f103f3f8278b35b657fdb0a21566d90a4b9 |
|
MD5 | 051ffd75c6f72063f84ada35f94260ed |
|
BLAKE2b-256 | 7a8a302f660abb1377de0c6aef8421320c285429865acb6a077c602228d8f9eb |
Hashes for http_router-4.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21442761510f379f2ddec340d8c9126cd8f1425a662e36d16fe0b2410b7eb114 |
|
MD5 | 146098a788f80a4bdaca7c29d41df81e |
|
BLAKE2b-256 | 13670bb9136917b8a74d034864ed3cfb06bb1c83611a5629bc18b57e175b1cd3 |
Hashes for http_router-4.0.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2823cea519c1625d45f12fb5933c58543c6a2f5db17bcecf023fd3c35d4a495a |
|
MD5 | 33e0c1488f1a71192ff6080180568ba3 |
|
BLAKE2b-256 | 65d992422d56f8151fac2342ff6fade013afa2d73acd8e3c51463d9639b3b0b8 |
Hashes for http_router-4.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d8369ca6f7293c865a08657ae4ba57c31468ff68b9a31f01a5da02119e95255 |
|
MD5 | cce70d246abb6d78beb3bf1d78ae2b32 |
|
BLAKE2b-256 | df4c9d2116334bedc15b5a60c0d2aa8d9b39d088a8dfb22178ebff05ac754339 |
Hashes for http_router-4.0.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a9b2c24ca79078ddcdb47ed3129739dd393cc040629d66d308bbb9922da0fae |
|
MD5 | c4f06c41277b80cd2719d1383cba627c |
|
BLAKE2b-256 | 74d939b5795f8fa4205753941ac02b8a7a3400b27f30bdd0962885a9f069d9e8 |
Hashes for http_router-4.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e129ad2f6241427696872bf233340007bce3632357e9701876ebb39c5bfb520 |
|
MD5 | 5e2f5cd9aa1b086366ae5b71e0f6a766 |
|
BLAKE2b-256 | 8ab8b43c7e734d0e19a2d7f504df8aebe54546d740c5d3193c144cab44dd1fa7 |
Hashes for http_router-4.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c97b39268762640e6ef3e24387c7a555b92b6433f8dc4b39f1836f94b5e03c0a |
|
MD5 | d37e36628c0ed581069cbd53a7bfa2e8 |
|
BLAKE2b-256 | c41f7a478d38a6beec03449393104499e85192e9b6ab7bce711b6b8d83f70aff |
Hashes for http_router-4.0.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04c0d6db2f1d1708b98b1463518303216223dfe852c536dd2fd92c0bcec309f5 |
|
MD5 | 03a874e6bb0963aca58260cd32306e73 |
|
BLAKE2b-256 | 801494d447ffa33670c3e611c2969e1181c5f4799426d0bdbf097968110cfe58 |
Hashes for http_router-4.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 269140f29850bde54e21a88f8575cc954076d5d243e60ab40b765c8fb28675b1 |
|
MD5 | 73e97cd101ddc2cbe2841a6dc9cdb717 |
|
BLAKE2b-256 | a630b2d77a37903780d5a60ef7c5641135fab9bf5d96347396fdec88a93deb2e |
Hashes for http_router-4.0.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bebca9463c27c5d7779d92e530736003222227ce57f9d94b88d1935133435f5b |
|
MD5 | c3ee54f5d75a1a241d5a9ac750982903 |
|
BLAKE2b-256 | d0c63fd384aa0d5acff08b3d5e477a4099276e359d652689f3750d4d3d635382 |
Hashes for http_router-4.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2a0d8bd95069e06a44ad5294c7c0108e45f9515b283492dbaa2ee6d9b7d3695 |
|
MD5 | c18fe7c0e8c8ee9fa9835ac3d1a29320 |
|
BLAKE2b-256 | a83ee72b37486360f8ca5b769f7380ee22b6e0c27eecd68603245ceb66955653 |
Hashes for http_router-4.0.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fefeccac68fa80ebc395e7fcd04e15275a71385ccd35c5d6a91e73dc13d6eda |
|
MD5 | 985a7c7cfe96246150c69386f2b8255a |
|
BLAKE2b-256 | 8de862335de6d294ba4abc10765d04bf8ca926daf5575f083331b3840f13371a |
Hashes for http_router-4.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b321573bdcb01f54c78e924bda18575314b181d60e2459903b85ccd6ad8d1460 |
|
MD5 | 524cafaa4fea2d77dd463f6182811b4d |
|
BLAKE2b-256 | 7012b5ad58040a7e06bcf7cb67cb47884c0c53412ae0db41f0c73cba66df7cbb |
Hashes for http_router-4.0.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 800d281bb93c3a437e11a5c6c540702e6cb351ddeeef8bc01defb309c6480278 |
|
MD5 | db2f2d6bde40acbececb0dd37b948401 |
|
BLAKE2b-256 | 93c734516f94d9a1740ba391889278891a82131ca92816a407303c6f4aac33e1 |
Hashes for http_router-4.0.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 580eeecf7ff46b84f7d69c5bde89f6a5cd8a309afd65fa596ce867fc06d69f51 |
|
MD5 | eece47c5309abeda8b96ea4aa1947fa9 |
|
BLAKE2b-256 | a91b1b62ea0160957becc55cea5fa63395d0c545ea0badbd537e097ae21f40d0 |
Hashes for http_router-4.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b6c85630c3e6f4b5cfe37879e654314e5f746012118921f7dd112d74c8f0ef6 |
|
MD5 | 01b6b3ae26aa10d93cf1c73af105595f |
|
BLAKE2b-256 | cdc9e078daedde391dc6c794ed1180433c530e8b0b3bfd4ba04334e777445a72 |
Hashes for http_router-4.0.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 478a9ba02956813861242ad86ae025db4d5d1c996f5967b8cc5260f42cdb7511 |
|
MD5 | 272f28d724591f22126bfbd0c4f2082e |
|
BLAKE2b-256 | 4b00f975945c438b7b86a73f6f3ad7ed2451a5d6930eee4c24825d9136851a5c |
Hashes for http_router-4.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 778939a21f2951f07b0ba564609c2c42a8e871a3d78f9641032b9ded6c73804e |
|
MD5 | 051e3ab9a40ebf41986908912cf626f5 |
|
BLAKE2b-256 | 675ccc8509added813939404f7d923ad285d42f1b017eeb6b57f61476a55c805 |
Hashes for http_router-4.0.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0446a10b1afa3135aa0317338f47f1d9d936dd2b12603f3301bb3e7c83c3b8f7 |
|
MD5 | 61b0edc44349f55d6ff90fec0418fcb2 |
|
BLAKE2b-256 | 378faab137d57fd81ed11eb9320943df45e4c41596aaa3ae742519a2d44a8949 |
Hashes for http_router-4.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80fd83527008378153a85c513ab5de84985b68d55172a5f5e5f583ebb11da7ef |
|
MD5 | bd96922326ca46b726e3177ebc58b0dc |
|
BLAKE2b-256 | 8ca8e29635e1cf9d472cd664fdbf306f8e3a97a3b2ddcc3f3de008cd88770c11 |
Hashes for http_router-4.0.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b867a64d8ce3d2d5a2b04d338b0660eca7cb1a7dee7de5b45cc635c9075a79c |
|
MD5 | 8eca350f9d09c0ff6ed44153c7c7ab09 |
|
BLAKE2b-256 | 6227b80cb3f644effd143378c63c17fc36020824d97188ac2fadde0ce64c824f |
Hashes for http_router-4.0.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c803dfc955e82419b61dc66faa83e62ef23d938ef9d875bb271ca87a4a642bc5 |
|
MD5 | e67bfb234792d5c2ad7859e3e58e193e |
|
BLAKE2b-256 | f4223e77af53897d5c0a7cd7cf63b405470c7408ae611d07dbd9c0b36ad32b85 |
Hashes for http_router-4.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dab7f0d739fb20d6dc9b5f23e13aadfae712002eea06aca133e83fe09ee607f |
|
MD5 | 507b8bb0757241cb48a7fce562c327f5 |
|
BLAKE2b-256 | 37a88c26fa7ba681f0277ebbf259c4cd19000d67dc7e1db0d00bbc133705b491 |
Hashes for http_router-4.0.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1b86c8c9c230888abbb3a9fc2121baf9635dc86a76cdc69a4575eb574e7ea9f |
|
MD5 | b94fb1526e5c76fcdc3bfd904f72fb03 |
|
BLAKE2b-256 | 8306bd9bdc26b23452eab7056c239edacfb7e57e3aba770202201786e383ae12 |
Hashes for http_router-4.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2bc1749023aa52495926886e30739afe2e6245cd3b450761a103d95e7c2531 |
|
MD5 | dc265189afe8493a60dd4d4c5cbea546 |
|
BLAKE2b-256 | 66d25988ee523cb9235ea1046ec59692ec675ac73738ef1379347bd00f9c4e82 |
Hashes for http_router-4.0.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 557794904dd401257a63139e9a9090cec14b5df0696e6061878efbf87eddce01 |
|
MD5 | 5c996579f54ff7d7a17c03f99c343aa4 |
|
BLAKE2b-256 | 95194c5c5725cff26aef814cb00636fe825af10ef456455d95d284e004f0fcbc |
Hashes for http_router-4.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0612fe4fcd7bb9ef5494e4314e5cde34ac1592234df04b54145e7b1036d15bc5 |
|
MD5 | 17ae56b8bfdd3dbd542d3589baf34b10 |
|
BLAKE2b-256 | ed6be8ab664483710de47b799f45f68490c8ebe3cc1f454ebf3fc4f0823a572f |
Hashes for http_router-4.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea4f94d6e59d22fbcef3f3ab5f91a4be1190699663c3c60bc2cb5fee93e878cc |
|
MD5 | 85f2ada60fb6687d2dd64b5333dc6c63 |
|
BLAKE2b-256 | 105e087f501489e5cb0fc90be4df3cbb61cbdf513f9d3e86a64a5cda4fcdbed3 |
Hashes for http_router-4.0.0-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 823176acae736ff7770091e70abe284b329de51a23ac5f46e968550497a35d39 |
|
MD5 | 20a577768970b1e921a1efdf442a64ce |
|
BLAKE2b-256 | d36b62782839271cd804cf34116c4cc9725f5720423e22973dccac0347995ff7 |
Hashes for http_router-4.0.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a71ba15e62cd837b0d5fc1d513fd249a37ee43da53a3a273f2f87dea23fe040 |
|
MD5 | 2005ea5b707b4c9a1b570ee96638f4df |
|
BLAKE2b-256 | 72badf9ec7e88030abe2e39873028536b867112b626799ea0697ed58bcf70861 |
Hashes for http_router-4.0.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cbb9166901e69be8e9eb222187643826024f8c5a5840375471265fc122d5b22 |
|
MD5 | f728eb5f061ae02aabb88ee210f66afc |
|
BLAKE2b-256 | be903ae5b5bbd64b2432cc145544890e34b1fbc45a5fa568cc7a778132e62fe2 |
Hashes for http_router-4.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe1d1046aaf48b0dbe78137207457a85ca3ebc40a912c804f4e7819c4ceccea |
|
MD5 | 046ce08bc6da46a0bd07464061ac6b60 |
|
BLAKE2b-256 | 06193dd2e15a3f0d1fb495c0638c348bf22447f9027924d4ee7884ce684a359c |