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-3.0.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b437febc8906eb87ddc649f0767ee37ebc1062147b9bcb083a63f17e9966b53b |
|
MD5 | cabf26efcb21e824ab03f28e4e2b145c |
|
BLAKE2b-256 | dc2fd24c9fb450a2731051435bfff12c7ef3d2b611edee6ac47e9b4fe8caf3c9 |
Hashes for http_router-3.0.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0611d5fc30e9d40d012a69bc35da9d20c06569618762cf6e99ef100166808380 |
|
MD5 | cbef3c834f6d467f67f8412fbee37cae |
|
BLAKE2b-256 | eedc424b07773db99cd257a3054b3203b4210e8ac67d472aa23c9af3305915e7 |
Hashes for http_router-3.0.1-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9264ef28ce95474b4a8d3d5090955048c95e1c30f4c2bb7b0b1ea46da61b3623 |
|
MD5 | 0e6526f7c8cf2d50cc0defc230919b78 |
|
BLAKE2b-256 | 9854ead6c25ccda2746fdb5e9f1451135a5c1b717f8c1624675384b2ddb2201f |
Hashes for http_router-3.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7456beb15c30801212018bfd3df1df8d33b17782270a89f8be89786424a37c33 |
|
MD5 | 61de7ffece70f88d456419c8c85169e5 |
|
BLAKE2b-256 | e9eacb952648c8fe5bb18923e317e668901b80e7518a32ea0f9658c55b97941b |
Hashes for http_router-3.0.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa1062fe6181324ccb3dd3f43e02519cc2ac849937cb796673d28694c0091f24 |
|
MD5 | 69ba814242f0f619fe08a9690cb972f9 |
|
BLAKE2b-256 | f718000efa7e4bc2b40443b791592c9814d5571b1a4f75258639a17a802def26 |
Hashes for http_router-3.0.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8abaedfbea1b264edcd22136a69bdb924307bc8adad8ecd8c51dd71c20277a |
|
MD5 | 33ce53cd8d4ee4c426e14cc2f3542859 |
|
BLAKE2b-256 | 3ff9db49e28c56aca751c8cd320d49df76ed3b2b4f59e3c1b432ce172970547a |
Hashes for http_router-3.0.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aef8d379fefa829d5cf99ed1abc8740008e3fa33685aac2cae261ff4bd985876 |
|
MD5 | ac8dc64f414a340daebb417875f57944 |
|
BLAKE2b-256 | b0f067b3cc55d43e3f46ace6d4e6df499b43e332a920d695b7292fa0a4378380 |
Hashes for http_router-3.0.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 699715241fc81f067e9dd85f2d1900ebd9649af87623ab8920ddddfaefab2a08 |
|
MD5 | 18c6013e62a34f9f83718b40c5539073 |
|
BLAKE2b-256 | 5d175bc75a4f1952dc5c2ea2b32b8e6119ad3f99101c72e904e30990a09f906d |
Hashes for http_router-3.0.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64a54f7fb32fabe51a561fd25b7c0448760e04242862549a425f29fd0cbbf232 |
|
MD5 | 735241fbcb04ab148212270e2b2ab333 |
|
BLAKE2b-256 | 3dde73dfc7c3bd3a61c0a6ee32ed3b02dd87af0fc80b1124c800052d4fc1e042 |
Hashes for http_router-3.0.1-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a95331b5d2c044da60aa719340dfc7dea66fbcd46f58b4f17013f9d9311724 |
|
MD5 | 191e24513f06b1280c9c9bd0725fe632 |
|
BLAKE2b-256 | 4f63eb207fb5ce2a260e28cef76f53d704946ec3b7ec0a45b1965537aee9bff3 |
Hashes for http_router-3.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5f89112ecec4d8b4fdda94af9dfaf78dedc4091aab0f4058949ea2c3d7f2665 |
|
MD5 | 9a8922de738e6d9773fba3fe721a20a6 |
|
BLAKE2b-256 | ed0e8f6ac3eef2a3fc608a08a8a396e8e0be89f8edcb0d8c9fdfbc6ee31478e0 |
Hashes for http_router-3.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 480843e29b332a7b23cb877a9cc50d894d80cf2e7544c8bfdbaac9a98ce47925 |
|
MD5 | a9b87d665ee1e8da12524d7e1c55ea00 |
|
BLAKE2b-256 | f3b9a8cf06d34fbbadff01b1476b94f33155a1a74cba7e094afce4fe9d795e59 |
Hashes for http_router-3.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a54e3797653be0616cb934dba271242d35526b40343da3ae845d0171741b100 |
|
MD5 | 006b9c5c736f2a9a40f1f51d69f649a9 |
|
BLAKE2b-256 | e39dddf39d7cebc0a91428f4b4ed6550985004719ecb7c261adbea8629178839 |
Hashes for http_router-3.0.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f98e1b7496c9f8ff6128254f12f6b7e40b2ff49316bb13b26f9ba044eb25989a |
|
MD5 | c21ae0f9242889cabb15ca75b88c6a5f |
|
BLAKE2b-256 | 00760f65526fcce09fc31758cc9635211eb54f221b6e27a3b6bda678f63c7fdc |
Hashes for http_router-3.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c5d2753337475d2afde8cba36079b2ecf03ab67b232a869b4454bc3e830df53 |
|
MD5 | 0509c0bb64381659f01582f424951afa |
|
BLAKE2b-256 | 75cfa311b8ca97df2d3a629e3b923f08f68bacd95f0448af3dca6390ca2e4eb1 |
Hashes for http_router-3.0.1-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95e5fea06b48a02a6ea4af0b3b6f4fd7d309bc819ff32546453cac8228684cbc |
|
MD5 | 838433e943f26ffc1ec838d386be16c4 |
|
BLAKE2b-256 | e21c6b9613d42725dcd5a4f5b63a85c46b65367096c0ff95335c7f444e33b7c4 |
Hashes for http_router-3.0.1-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ff19d704cfb96ce585ab07e58717c00df787a0143ceecf7561d5e9457b05c5 |
|
MD5 | a78dbf65a66f89196efcc7f5cfde621f |
|
BLAKE2b-256 | 6f14f90191617caa67151b591ba0898edbb7a80565d1f1ba67b6bb9e0b794aea |
Hashes for http_router-3.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff74ac1bacd0b770488eeaca2f5f940ee6ff749ced3772bb5ef56fb1e2c6bae4 |
|
MD5 | 401a44900978305fb32034e96bdff25d |
|
BLAKE2b-256 | 2cae42978cf5424f630bbcf5853f17516cee4cdf6393d0e282c69a2b980404f8 |
Hashes for http_router-3.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fd8b2809f70e062a8579d1a7d2eaf8cfc67b11638946a5a0e5dbe5ac944e66a |
|
MD5 | 4c1993c39694d13b8b63629680aef6b7 |
|
BLAKE2b-256 | 020dcd0913ad3833564595e66142b72775f10b735c5039333b19669b4b57da8d |
Hashes for http_router-3.0.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0ce5f12b55a2f1d503e9a61fe5e0dc0cffb2717ea5f78edd035f233ceab5c51 |
|
MD5 | 41a23226966e58caaaa12ca1e56072c9 |
|
BLAKE2b-256 | 354763b2d0d639222122dc5bc84d574bf11f64f1d2aab55c47cca653446b60f6 |
Hashes for http_router-3.0.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9e0f8f8b3a6cf9af21df5c358a3270f64d179ff1beefe0a31de8c5fea4e6776 |
|
MD5 | 011ae32caa0380f5aaa62d4eb51b05d7 |
|
BLAKE2b-256 | af8f1ca0ca05d9017e43c75f0c90ce3499ebc17d2cda028aa53e735370487e35 |
Hashes for http_router-3.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bc97807c35dded7f704e21ead15a02bc4468195e132d59d026e26c21cb23724 |
|
MD5 | 4b654ec2bda17d6b8a775412461fb521 |
|
BLAKE2b-256 | ffd2f8abb6a5bae3ef6062c902fa526473c70b00b4f3a28bd7dbc398f438c9b8 |
Hashes for http_router-3.0.1-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da74821c869af21af3d4b35603e2cf3c8c82e1d417dc0160bcece83aca42606d |
|
MD5 | c2b1d2d49334f083753a4060eaaeef41 |
|
BLAKE2b-256 | 4783de7da70afe3d1f4c425c465a22f30cae6d76636581931ee9201c34f7ebe5 |
Hashes for http_router-3.0.1-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7e085a48882c893acd2cc6deb87f666af957fbaba8e206f4cfb9b64de2799ea |
|
MD5 | e8d095e39e7019bfe958a48641f6b8f4 |
|
BLAKE2b-256 | 3beef2494c4cf320d3321c6ef11916f93fbe99c21eb95d9345536df30f1a7bb1 |
Hashes for http_router-3.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90c6564db67c86664643e152f99bc6e9599de8f72f80df121ad35788378a98fc |
|
MD5 | c49e95c27bd0d0d24972edf669d71409 |
|
BLAKE2b-256 | c20ecadf039d8a5f3ae5088fd761422bfa903cd7b3eb4ada56a04230c60485c0 |
Hashes for http_router-3.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb0cec0e11d76a20e3a4894607831cf1ee43c9d67d8256a00956158d7a3e2319 |
|
MD5 | 75785279ff255892d196c0a1a6585253 |
|
BLAKE2b-256 | b905ae722f8671cba8a6b61e0f512a971258b1c245c473eb3849a8348eef0d76 |
Hashes for http_router-3.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a10e1c6f26738ca6aa814c6ef520e8ce4b3090be91b2b4b7881c5268b492194 |
|
MD5 | a2d50af584d8469bf34b5cdccbd11543 |
|
BLAKE2b-256 | 00693d53f675d4fbe88ee29856a2303cadb16f2ae8d81a6ea043153b61bbcf8f |
Hashes for http_router-3.0.1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68a780897c8b81ba3ae40c64c2ccdca1d74545314086082515ba6d0e9d34b3b |
|
MD5 | 66bffa640ac7bb4d8fc29f8188e929da |
|
BLAKE2b-256 | bb7d1162377e4d1caf0a5e6c1b9ebe817f9adea7e05784056bd0d9bba64f6511 |
Hashes for http_router-3.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e3e16f7cac7de888029c87447f0a44f0e7e07ab462c25ebbb79ed41fbccc67f |
|
MD5 | 0f25d083fda264bf0dae09f014763bdf |
|
BLAKE2b-256 | 812e5e6a9f08a9825fe85b9bb0714f64d5bc5a2ab6dc3039bb799058407396b8 |
Hashes for http_router-3.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76bc251b0050c053d0dcb267499ec54f4df634420cfba1ce253d3b5f317876cc |
|
MD5 | 069a97a5e7bf134d9d9f89d8eec4c369 |
|
BLAKE2b-256 | 0cc3de3f3f457ceb8f20a80cdaddf999e36bddc131d72ab864857aa0adebf7bb |
Hashes for http_router-3.0.1-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f586d95fd576bab384f30ba22cacd8696e689a4673d2e87f90497e0e8f8c6b28 |
|
MD5 | 85b1968b3364a13fc2b8dd660969d096 |
|
BLAKE2b-256 | 85300a56b6924ea1554d31d0d240caf05d79b7b80b1e59747829ce799e14633c |
Hashes for http_router-3.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab9ac7cc4688d2b36f917fa2e748e01f3fc3d325a53f6c0c9d598c3c728a7606 |
|
MD5 | 886897271c1d9fa0af2e6dbf01376cee |
|
BLAKE2b-256 | 5ce336cc81dc42c72a94370bb7922d438eb96c2d6fffaea6b5de00bd50cfae5b |
Hashes for http_router-3.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d87f20fc5585d7189556946241d3346e1e34aa15692c29d542e3a8a76b6f9550 |
|
MD5 | e5984e0d2087152754b9ad9b34362c92 |
|
BLAKE2b-256 | 1cc1a92cae1dfed4055dac65f3369e4c71aefcaeb71574aeca7006d6d610ae7c |
Hashes for http_router-3.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f69e868697278c15e598103cda014e7df7f2b538f7a616e6d50eb7e26b5df5d |
|
MD5 | 36f5676a830f89c53e78cffb6ff2b009 |
|
BLAKE2b-256 | df0e368b9ea6d28218f9f9dfba7132abe99a2c53156fbace87c348b386a756e6 |