A simple router system for HTTP applications
Project description
http-router – A simple router for HTTP applications
The library is not a HTTP framework. It’s an utilite to build the frameworks. The main goal of the library to bind targets to http routes and match them.
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/{item}')
def items():
pass
router = Router()
router.route('/api')(subrouter)
match = router('/api/items/12', method='GET')
assert match, 'HTTP path is ok'
assert match.target is items
assert match.params == {"item": "12"}
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.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffb462ba4ea9fdfbe12c5946d2e9cb1e49244d824c85fde3228c3c78ae3040a4 |
|
MD5 | 872e6876f78d284223850f03ec2c9239 |
|
BLAKE2b-256 | 7a79f1a1c16a099936ef5cdae966f84a0a030ba5b003581904882854311a6e0e |
Hashes for http_router-4.1.2-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 392a974d225e698a43916070d936e69a98646bd1212ca1d582a4b825269c0c33 |
|
MD5 | 6db7b7cecd741d1ceb42fe0c706855a0 |
|
BLAKE2b-256 | b2f790adaf1b4370ee8785e668979e52577ab778e8da362f289943ed81a12c7f |
Hashes for http_router-4.1.2-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b21b7717a41286d89db6ec3e5609d0636a0f22bb1de82658f316aeca3d3feeba |
|
MD5 | 71ec411c429a84730352dfa39e4853a8 |
|
BLAKE2b-256 | 67671992e66b356be08364bf9f2c845e7f5f1ff798366228ae1fb1d9a1c513e0 |
Hashes for http_router-4.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d4e8a3108e50d7d185513f9b2b771a39698e765bb9bcaad52ea582e0ce23406 |
|
MD5 | 45adc6106a6ebbb512dea409fe65193c |
|
BLAKE2b-256 | f0ea5407ded579ee035e8db13eedb47c604e743a6c7d8d8b663f35feb1f1b3e9 |
Hashes for http_router-4.1.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31a9492df53d7634db9106fc65f5a697a81344a8df8fa858b9e5ac862748ecc6 |
|
MD5 | e38ccd67722233dbdf56a2d9e186cf28 |
|
BLAKE2b-256 | 50c1ec8fbf03aa8758b336316e89fc725edacba981603aa9a0d328b121e372fc |
Hashes for http_router-4.1.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9409d02ba3e72d6ef68dc30b9cf07ec03744856b12f9346635971b3de0e4e80b |
|
MD5 | 48ada3d644f4832cf1015f72f11987b3 |
|
BLAKE2b-256 | 52ed824644944af57618af4a560b3dc52c0554d0d7291e443844f47a3db7597b |
Hashes for http_router-4.1.2-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a0119a36e57f2a4d511e7958b1a7e22d522d7644d3d577788366f5ba18711d |
|
MD5 | 4ce2200934c54a78a322e182af0c2d16 |
|
BLAKE2b-256 | dd5a17033309ab32c5b6eb605465cf8eaee0e4fa00a84735c2a82bb78d134f9d |
Hashes for http_router-4.1.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8d6eede2db60ec31774e7cf5c78aa2d1bad6ac3117e0ee4a909aa684de1ad47 |
|
MD5 | b572cf259be5bcd419ea13669422e8b3 |
|
BLAKE2b-256 | 98a041699d44a268f44cfbcd2ff6bd17fea30fd73a148ad9db3c55c0a578feaa |
Hashes for http_router-4.1.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4376355d41debae8b6d9670377295cf6bb84944e9916c728012a1e2079edef2 |
|
MD5 | 39344d8ae3b5b7359a723b39974fa8fe |
|
BLAKE2b-256 | 217aa2a6134b53013cc2dfa4f03b0db9a6444d18c34a0b2225d3f33cbfd97599 |
Hashes for http_router-4.1.2-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33b870b2f9b9a2a4691f9cc9c7ea0fe81c922a4ba5f423d6a0e91d97cf5492dc |
|
MD5 | d7e7c4024a2bb529fa692a7ff3fa415f |
|
BLAKE2b-256 | bde53a3c4c7e479cc97bdb3e05f05d768d426f5c34556d32f8c22b7e8300e637 |
Hashes for http_router-4.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa0389259608c026d49b2db74d1da6fb31b6e2c12d3631e81eb926eea935f7ea |
|
MD5 | dfd6b9cbe32a1fe00ae8e7bf70236bef |
|
BLAKE2b-256 | 22cd61b65570646fe099a2255c6a079fc400f69e11124a32f7ed9ef87065d145 |
Hashes for http_router-4.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f20377d2262e471bec8a0dfb9e4fa42a7b44434a491522bd716265fe597b352 |
|
MD5 | 1918b153e9a112203a001fae7ac193e2 |
|
BLAKE2b-256 | ef574ca1574feeb2d6b610ac19acc768635d642070dd4ace5d5d368facb801fb |
Hashes for http_router-4.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6a4174116339915bb83ce1801cfcc929947d79fa1d2b4cb090ee3ed1c955aae |
|
MD5 | 23d6239061db83255e02f01b4328882f |
|
BLAKE2b-256 | 7974040329a2e83697723bb124eb622e41730eb31a41da89f4f0ddd4ca5c4613 |
Hashes for http_router-4.1.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168dc4216845399a89db392d5d84d7738d4f4e9257d51e5014dbc85d9a51c4ef |
|
MD5 | 86f98742fad4c39cd19fa90a44b4f16d |
|
BLAKE2b-256 | 9417eb76fc66b0d24caa9b6cc34832884f2ccc56568e26b420fade6a012e4e25 |
Hashes for http_router-4.1.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af00ef3edb67956724cd3daa1c6f040e73cfff5f0afe46d7eb135d086c6b57fb |
|
MD5 | 79d395b4809b524a7e095aa0a32213f0 |
|
BLAKE2b-256 | 75911194d5ecda349d30cafa169a0531f3add48edb25f655fc523e14b0c3ab61 |
Hashes for http_router-4.1.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40060d329813d356784b7437d47b03c5d42718f91216a7df310325096eef8bbf |
|
MD5 | 7ee7bced931c8a7c66f7a634bfc4bb79 |
|
BLAKE2b-256 | b02b902eba875ba3b951349b29d1f555941346657109a4276ba704a356cd06d6 |
Hashes for http_router-4.1.2-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8286e0cb64f5c36dcb2e792f45816f811e2ce402ccb48c62b06ef9e7988674e0 |
|
MD5 | cff998d64cfe1755358b8f6a103f94e2 |
|
BLAKE2b-256 | 5c069b055639fbb320a32e8325489b5bb74247d77c51ecf6dc01f0982f5dadf7 |
Hashes for http_router-4.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 512ae57ea9b763c157ca54f9e2b159d88eca4d1075df7a18cb4a645eb05d34e7 |
|
MD5 | 1358131a25b1d43f4f4536e7f04684d6 |
|
BLAKE2b-256 | 8f7f1867b39418a6d1b5d203a13bba47792b62962670aa1e9260ad26845beafa |
Hashes for http_router-4.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6f2f7a023ffea56543e29694f547357a2b9b33c77b08c355fcdcf91b486d0be |
|
MD5 | 3848001fc64f6613184bee214f0e4943 |
|
BLAKE2b-256 | f77f55b481193572673d85daa79223f01d09c53f8ef25531d588a7793a0c022a |
Hashes for http_router-4.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84dd3e43356f732771621c93c9ad7513f1be73a9d1144bfc58df7e82a83f4436 |
|
MD5 | 39b4ba7b1ce8ab207ae07d4057829cfe |
|
BLAKE2b-256 | 823ded2b6a4f35b2e74a56ee1106dec63188c2700983f2826ec72eb688a30cab |
Hashes for http_router-4.1.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89334f2781aeb7c8066ba4baf1187c990b684584af89caad480ba371d7d9e69c |
|
MD5 | a7593630be35525af850767695188f6c |
|
BLAKE2b-256 | 1cc585c7bbf1e62e1b42b4b3fa1fd5f929eb6e2ab583dfcd40ab25107ab82abf |
Hashes for http_router-4.1.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12ddba636fded1d0a2c8a793748717ab37659642e509017385148c0a36b25faa |
|
MD5 | 9938c5f95d65a983503e189bc4d79bea |
|
BLAKE2b-256 | ad3790658d1f362c06a303a5f39e076187cee1c1ecd51ad6050e813ec74f43ea |
Hashes for http_router-4.1.2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b44d897dfb7da07763eb525c02ebc34ac932944cb062c041db92f5761e5690b8 |
|
MD5 | f361ebe2e23e47ba894d0882ab711bc4 |
|
BLAKE2b-256 | 9d30f169a2aa1d156c28f48b03b3c6cb3a87bb121a06575d0055929b6841bad1 |
Hashes for http_router-4.1.2-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8783324904de078841f11e991fe34633f386b4009c091e47880ea1fc2ce35fbf |
|
MD5 | 9c469ce04166b57e08a3711128bebde0 |
|
BLAKE2b-256 | 161c6dbf2cd95ea7d83613e5e5e95ca8e05f98db6eae027103c86a38a86765db |
Hashes for http_router-4.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b85904c993db689ee8725cd5e8bb991d0914bf32ca1ef8ee95c904897d4a8f2f |
|
MD5 | e0f3088fab031f0d139edb13aba45578 |
|
BLAKE2b-256 | 8b4e407e6e90a7c5964e309ddbcc7dcb76ba65d6f064e8724e46df19925b2be4 |
Hashes for http_router-4.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3d799f951b9c9f62c170ed89a2293827c070690efd05dba8c1010dd501afe75 |
|
MD5 | dd493eaa36865fe3328e32aaea103bfa |
|
BLAKE2b-256 | 1e42323d4642d4ee00034cb6d33df527bbcccfff606f76f0760ff9c942783690 |
Hashes for http_router-4.1.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bd3c59427808596cf9ef79e11044810dc7bc36e3c78a9d788b7b2b647a3082f |
|
MD5 | 6c4b35113e9f95e545cabe3cc27cfcac |
|
BLAKE2b-256 | 29ee0c51b3a4c412e1fb1da34cd116d1f685e5b8b374d88af34ce23b0f1557cf |
Hashes for http_router-4.1.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b88c0959131d139f02adc07538d342905e1984cae308f5c63e2b11fbd655a47 |
|
MD5 | 138cd8ea2de4c03448ea271ef6a9885f |
|
BLAKE2b-256 | 1f449ee057c0f9448b3eac5d234bf19895ee002266737601c048e2decb96efbc |
Hashes for http_router-4.1.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b639bd95467954929ae5d1765b205aa9f68bdbc08b13b6732178302708ba0218 |
|
MD5 | 1fc6502a55938a47d7db8825953fe27b |
|
BLAKE2b-256 | fbb745f5f417eef630a07a6ccec5df473c2bfc78a124031285116f467be3347b |
Hashes for http_router-4.1.2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20da643b37fecd405cae8d5e697371e6c9b9d0f0ca0edba41bf171ef14fbc411 |
|
MD5 | de4699738f7d7c077689ec9a770291ae |
|
BLAKE2b-256 | 33fccec757559319966b2c4c32017369b5c707c3ffd5736d31eb17bf707a446c |
Hashes for http_router-4.1.2-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58efaea2b318d14f7ff810e61511aaf3231e82f4e4dcf8ab67b532e3bfb03012 |
|
MD5 | c4a44d18b78ce09217d94a0e722389dc |
|
BLAKE2b-256 | ec585d1f44b9e12883faa938a0dae793acb91c3ba822f28b81cb76a02303b91c |
Hashes for http_router-4.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 924a9b0a9131d0e45e4007abccc88051f3041db1d37d917ab973ab3483999f2d |
|
MD5 | 8c0340a815ffdb79743ef562f2ebe6a2 |
|
BLAKE2b-256 | 93ac693b4704ec2e145233608c64e37f180981036ea0bdaf6a93c901393cc6ed |
Hashes for http_router-4.1.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67ecb93bbea33222f4a3b23c1f91d4c71cc51ff0446b9cc54b20ca260eb4ebf3 |
|
MD5 | 18bd7cf3c44b08a0da25a313413ffcac |
|
BLAKE2b-256 | 9e5207e430a460d18be6a2d4a414973e8621b3df053434879674d26e458f4890 |
Hashes for http_router-4.1.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28d5b09c9162e2a419788b201829b44f199fb8ad84b17b3b6e56a48373aaba9a |
|
MD5 | f7d999ccaf1e93886474b279f1dc5779 |
|
BLAKE2b-256 | 677a85fafb81c09f6caa8f3a77084273207cd623599919045f99434b8b4154a9 |
Hashes for http_router-4.1.2-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdf28854f05ff1b21a193cda6f5860d7983e6d68ac154410958f61bc97260a17 |
|
MD5 | 80e9d4eda92c87dadc43651679d373a0 |
|
BLAKE2b-256 | bcd3444edafd348bf2fb885c47e31469d9f4a65e0b469f3128ef7e23f4b8600f |