A simple router system for HTTP applications
Project description
http-router – A simple router for HTTP applications
Requirements
python 3.8, 3.9, 3.10, 3.11, 3.12, pypy3
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.route('/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.1.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 848fc6c32e9bd0cdda804a51825c20207940f56bf2fe7bac6f36844f89c3dccc |
|
MD5 | d176eea3ecb8a6edd882667af026ad72 |
|
BLAKE2b-256 | 82d62832ae7fc4be22ad9d2926439ba3df85e77c772ad891ddf758d42d9c32fc |
Hashes for http_router-4.1.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41e5245cdbee71355e072f9f6ad3283aa4bf400235d188e04d9a1b7d54f77c48 |
|
MD5 | 04da4d4d246806a26cecc238b6c4cc9c |
|
BLAKE2b-256 | 110793e14a81defa9120817b5228cc4e3ac89a6e491d16907eadf420e10542f5 |
Hashes for http_router-4.1.0-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f25c432fc22d1cc006250871805c379e12b086f56f566859f1b9b884dacd795 |
|
MD5 | 68777205759ea50388e8e4c169c64504 |
|
BLAKE2b-256 | 8132540d96312e3c362c0a0acbc66c2340ed76366709afac3df49450cb06ad43 |
Hashes for http_router-4.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 718104db0b3a9a18b2667fa03d7b8406d164d94d806602b5afeeb3d8dc7fab0a |
|
MD5 | 0915c694239bf3d3e91ac55717fc5bc4 |
|
BLAKE2b-256 | cb075746299c6cb1be2a8ced7858de972b0b378731ac2a9dc628e0159be4c33a |
Hashes for http_router-4.1.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aadc53f23f7733037d8fcf2e1fe776fabc6ee38d04f3003cd8052c72aa24278b |
|
MD5 | cfdc5dda079c27f05e41660c5161c8d1 |
|
BLAKE2b-256 | f096736d1280c6bc8157602a508e0a08a7ff6c1ceed5d2d2b72a35822a4ef1cb |
Hashes for http_router-4.1.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 495e5b776f1f489181c4f4a3579952b5a42d0f0c54d19e870c6462032c231497 |
|
MD5 | 60ad839f191ec7da6f55490ed822ebaa |
|
BLAKE2b-256 | 7267e34d157275fe4d04f2597fb7fcd977db9961e0453d378b1d766de60cd754 |
Hashes for http_router-4.1.0-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40bff9cd117457e717d51a5cdb67eccecbd9bdcbe7a263abcc38c354bc6ec43f |
|
MD5 | ce8651d6255dab32ec9e8cd2d44119e1 |
|
BLAKE2b-256 | e7f9f14e7e5e204d24f355aed76946b007c93de427d31229bba5837858e7764e |
Hashes for http_router-4.1.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91d8eba432737c49f6e491b16555b2c05d60dc965f4d17d6c49d3b36996e1f3e |
|
MD5 | d591be93beb61b16a967a21f64ba3815 |
|
BLAKE2b-256 | b741945264d9254d916e706f114604c8ffd66a1d6bebb574e1985710109ec238 |
Hashes for http_router-4.1.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d61024cb6822a904e48056f307504b562c12d2194dfbd9ecb5be876f9b70f83 |
|
MD5 | fd365a22b485cbb8eef39ce81d5c0572 |
|
BLAKE2b-256 | c43b9fb7d8c174ad91aba070328b24d9168d7df8c3182e4481ae9df876a1f369 |
Hashes for http_router-4.1.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f954550485eadec3442dcc5041e1751a438f4928b58f6c787b3e986feb22ed4 |
|
MD5 | 91ebfcce25bc60a29d7c225f8fe970d8 |
|
BLAKE2b-256 | 83ca024ce88336f4996f67591b2e2ef17ad7af6dbcbdbdea30fba8944ed231b3 |
Hashes for http_router-4.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b85b970992d6fd69dbc980f0208513d3fb23390964aceefba09557f760ef72 |
|
MD5 | ff09a9fea07166453208f2e38143f8a7 |
|
BLAKE2b-256 | 71e36fe5238169acadd0237e06b983823aa8de2e5c58951bbdfab29a82407479 |
Hashes for http_router-4.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d388fe0a83b2e865bc4ae2403b2b60226f09a9e5c0f60063bedd1dac08feb192 |
|
MD5 | 7306475e10bf88cac56e4f550530f19a |
|
BLAKE2b-256 | 40cedb24c2ce9b2be98f82fa6fa687e6cf1739d5b44ee5edbcf29aa1a038af7b |
Hashes for http_router-4.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eada0e1c2d9ddb6185f1532c2ff244ef4c06a34deb4eb1ac2e135b0377218de |
|
MD5 | 2bc9c0f412de8675946a64e045ae4389 |
|
BLAKE2b-256 | dd372dd424c4f3c28ec7c3f3dd4be5f1476df0500a0518577bce0341d3d745db |
Hashes for http_router-4.1.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74ac87d0d6315f61823c3d8f3ef9c3e2ec6b0a6cdf2933364494488819145426 |
|
MD5 | a9bc0f3fb358cb98f54180c56f96b7fb |
|
BLAKE2b-256 | 8b83e1637cf933be40f2873c8b253b3f629abafca2c260861e51e2457cb9a069 |
Hashes for http_router-4.1.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dd0f3c5d79b7d1aa6890c811969b9e0001c1387dadcb35b58fbf27f2f667ca4 |
|
MD5 | 850e8f4034f84c4dd67881d42d103994 |
|
BLAKE2b-256 | e6a85c66d72674151c32a9efb86da01dd5223fa52177286461dad909ec65f859 |
Hashes for http_router-4.1.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adda9de1edd65834f2cb9429c785a1562f5ed61c351d337f00d1d4a742a965be |
|
MD5 | fb5558e2f6b3a83ceff110440b8d05ee |
|
BLAKE2b-256 | f3bd115ef6f8258319092e67e94b6090dccfc43f72ffb885d30637def2cf845e |
Hashes for http_router-4.1.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603a0b3bc17b5a4380b21ce110d03dcb6506f8b9756054f3e6e7a17d8c2ac8d9 |
|
MD5 | 28b1c56e38796bacbf648e184da4d2ac |
|
BLAKE2b-256 | e921248ce8307b27df7b57485ac12f008b7e7e44f5c15d3751308a1204697d17 |
Hashes for http_router-4.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80c4c46aa3b0b1b8561b82258f34528d9e70deb2d165dc70c093171e9752ece5 |
|
MD5 | f76c400a87b8a8e00f42ea8b3494d852 |
|
BLAKE2b-256 | 5093b2b926528936869f39f1a4cc78cd7cd1eedd50fad4acd5ed31710c5e0947 |
Hashes for http_router-4.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaaa76c451a1da9ae9290716f8b48acabaccf054822159c5a6458ba7463c8bd6 |
|
MD5 | 207a34eb5bc5c33fab2020257d2d3fc6 |
|
BLAKE2b-256 | a1a09d15ed4b284c3839f85599527a6a17be6070ef731b28f86ff320b335d4dc |
Hashes for http_router-4.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a212bf0b860125f2b761e225ebe9ad62099cc1a2d634e8dd0040b7a1f89057 |
|
MD5 | f9f39e5b2b362cadc6b9f79d9a3d54f1 |
|
BLAKE2b-256 | 3c9d18e810759144239394d761bbb7a5363d21449a1ba41f6919878a08ee8a73 |
Hashes for http_router-4.1.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7d49e14de23096dd3de4414d17c9572c0f55ca8e50d591d8b1fed9079888b7a |
|
MD5 | 8d2afe7e86d2d8789f72c894c4d73273 |
|
BLAKE2b-256 | 8f4328d5cd916904aa7b575e8951038d55b3995ea78237421e421fd5efa4c059 |
Hashes for http_router-4.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8024698c214b10d818b8d23f4c14d961741c40ab7c0e04d3f1230774d469ce7 |
|
MD5 | d0dc73e781632d11b994fd69440f3327 |
|
BLAKE2b-256 | ab7893f413b47a65b22da1edcf4e7e1bc17d1defe767d238c1cc061efb8c5edf |
Hashes for http_router-4.1.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22bb8c7adedfc200ba539816b9bcfbbd460a54a6fdb96b1e8ebc69eef2aa4705 |
|
MD5 | 0a8abae97392953be8788c7f1ec024ac |
|
BLAKE2b-256 | 5735b58977a7eb8b07affffc1a8f68e6a4d572a20f94e4ae863c6541438b6a46 |
Hashes for http_router-4.1.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a50373042d0c207b7b660c02e8e7d62e67368971d0fa97bba5e30b7869b112a |
|
MD5 | 12f5b78f53f034e73f5fa7aa239402e8 |
|
BLAKE2b-256 | f1555e21d7709ba0fe4a86c78d478fdb10bf43486add0aef6d450464f034c19b |
Hashes for http_router-4.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa546bca8951f59d0d38c48ae4c122838e80d53835f9515cc177d0d5d9b568a1 |
|
MD5 | 8c862968af5895b5920ce9dc9581def0 |
|
BLAKE2b-256 | 617465f2c9acc5f9aea1e2a418718748569d824f350c3c1d355d3953d96f9a59 |
Hashes for http_router-4.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f82d76b8d6aa8c52341edd3946db70b945e47a9f999ffa318110b6b8ddb905eb |
|
MD5 | 8fd933023b63e1f7e52d034a6ebc275d |
|
BLAKE2b-256 | 79a74b551dd596630f89b1f7004493594ab2327cb5f2024ef80174cc2200c588 |
Hashes for http_router-4.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b013148e33953eabf6172fd937acc4adc93f1e69d65696ae21b2fff3c0c0f333 |
|
MD5 | fd3500973f8edc1c9d534a130d4bf918 |
|
BLAKE2b-256 | d5014e442c932452d6a0005d7c2f385f690976623330285581a6622af583731d |
Hashes for http_router-4.1.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18b3ddce1b8b8f71812a14fa51aa1e64f7ed9d4f6ec3d1eb9b13cc0b9e68f527 |
|
MD5 | 17b2ea65bf17499b9687ae296fc21dbb |
|
BLAKE2b-256 | 96f9b9f997475e5ca9633a1859d6f7c9c2c412bbd6a7321924e67a2a56f97e08 |
Hashes for http_router-4.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7a24d8e737bda39ed4720ce55fdf468d347a29f6f7330640286f0c9b08dbac7 |
|
MD5 | 520b8eb309d23f5585f926cc2d422a3e |
|
BLAKE2b-256 | d6dd9c21b302994fe33853a2f835d030ac1bc66831571b89d28645e21fea756a |
Hashes for http_router-4.1.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c5022301afc7014cade01f96b466d9a2530700ea2b9bba8603490b6c92ef07 |
|
MD5 | 4029bb1cf2a865458c5ff1e9cee87e6c |
|
BLAKE2b-256 | 99c822a66231bba85986f3614355a62d599f16d7bd40b8ad7be4716206a50bce |
Hashes for http_router-4.1.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96255455de372a9dcf799aa082a3c4eff40ca28b266049f5030ea54040d61801 |
|
MD5 | 8da00867c6cdf6def71b863199e8983e |
|
BLAKE2b-256 | 5144450ccc8cdadfe1387f95d1572bde6432f0fe1fa61c3395d1e4371ea6f1cf |
Hashes for http_router-4.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f334ec8beffcfb2cc4b4d02e4ee20415d34568781d53305debea94d32a14e3 |
|
MD5 | c80b2791e59f1b0f73a77854c6440bb4 |
|
BLAKE2b-256 | bc0adc83a2d9027d33c5888c4b3eb365d6c7e08c6ac60e4c1f5712b2414fc9df |
Hashes for http_router-4.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28fd6a348b0613993880d7406074f769c7aacafb2756801658ad5d4a051572fd |
|
MD5 | 819bf590cff20b80c9b0ab1d616fb984 |
|
BLAKE2b-256 | 6c41e8ef62b06d09a225e93905fe2f3cb07bac531810cf56cf17bc42851bf45c |
Hashes for http_router-4.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b487244f7dd1ece5302399caca56ac3556787821b1316c81e31f45124447f4fa |
|
MD5 | b602af8ac43355f317466ee3b441259b |
|
BLAKE2b-256 | 3b9dea4c4979d6081ea6446fb52414d171f5941e680a535d2fba4f2ef8e8e232 |
Hashes for http_router-4.1.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6122c384bb54d49b75acafe1dfc28c17075eb8e40a5520830eeca1b4b6aa8f83 |
|
MD5 | 7f02087a0b89c916e912e16ee016d5d0 |
|
BLAKE2b-256 | 3cf0874e900297cdab31d34722a8fbd13d488692c396237688256d9ac04f10d8 |
Hashes for http_router-4.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a41407b8a50a291c699edbd005288671242acff7788580d52145d041187e6fe9 |
|
MD5 | 78470bb6eeeb8f1ecb40baefb7a5dfe1 |
|
BLAKE2b-256 | b6823552ad4dd79e33a04357f4205a6ab5684461a651fd95aa8f5e3ae2aae136 |
Hashes for http_router-4.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23455ec0bdb30ff38793b429cd6bc66fcebd0816f84b29254f77e3541ddb2c36 |
|
MD5 | 6c70b86aa9082e9bea0ebe9a6d90db5c |
|
BLAKE2b-256 | e804dcf8fc11200daaa36d7ee8c420a7d8a7b6ae558dc0d9f0525c7823f6438b |
Hashes for http_router-4.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6552f4ddaf6879510266a91a7bec06ad232f1b17f4942fe38d2ea019d6e78a0 |
|
MD5 | 81f4dd242463b1a17dadf2d46ca36dcf |
|
BLAKE2b-256 | 45001d6ded5d4a2e824c1d47a9c4e43da9d61b2ffeaa2153ad7f947b1610bff5 |
Hashes for http_router-4.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ea752facc651c3d0ae6c23726d8b616927d75b130295888358e0617fd5fb23d |
|
MD5 | 13f0665659f1e6d78e0b25bc85b2ec9d |
|
BLAKE2b-256 | 14ca3dbfd2d26465bd223b4b3412731062367f1fc46bae4a4f711c64176ec36c |
Hashes for http_router-4.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b67aae6745fff172875db51b5035299a30ca79ab99a38cf5a048b133b9b72b8c |
|
MD5 | 1f6ef9532cde3b90e2601059b01681fb |
|
BLAKE2b-256 | cffad1c12c91f8e02f7152d40987435cc2707bca508a13c9ec4d213ae4a53c15 |
Hashes for http_router-4.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 744e8ccd235f8a933d52a876aab15ad8558f4ef4b9f3896f71c22836d87a4bc9 |
|
MD5 | f399b0768998f53df10a7e846cb41ae2 |
|
BLAKE2b-256 | 1b1773113135897fb505890741a8c36cf4e2ff19f5ee8a42a36a62ccf0f00da9 |