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.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 358d23e90f65128214f4836351f425defe9b92b7165e3cbe9530ade58c574d1c |
|
MD5 | d355d48b05ea180563e534313586c6c4 |
|
BLAKE2b-256 | 11c48bc71289b3bed5d0f39ac318978fbd7ed908916717136696e7c750c385f3 |
Hashes for http_router-3.0.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d4a4563794d55ba80b2d07144df9946edc60327322416394822b55ce3d2658e |
|
MD5 | b3a9b52248ed04cbe3c8e0d964900253 |
|
BLAKE2b-256 | 02d7de88b33cd0d823d78da76d52619049c0312d0ecfacd1d9fad0f2c8455cef |
Hashes for http_router-3.0.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13b557502c84b97470ff3848ff5918e4ef34e5c9bf0943d5382afac1cd7f194d |
|
MD5 | afa4b3b1edcbf608845418d999705734 |
|
BLAKE2b-256 | fc71bfb66a7c60d3ea1f77940a7859286d6525f26d7981bd31d1007b1ba53f4b |
Hashes for http_router-3.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c378b0b4a23732baff72944efd9047cdc74632f22a41ae675f4c9a2afddb406c |
|
MD5 | 25339bb76350d4e6fb721b71dfcf8246 |
|
BLAKE2b-256 | c950deca444b6ac4d932cafadc275a635cb4dd3e7df776a460f6316bea8665cb |
Hashes for http_router-3.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 | 2a8273089e6dbfc9d0836ce0b2222ee41f268044523db61c94ae44e53a35680c |
|
MD5 | e13d77e6ad52b68db30cf579cc5cbf34 |
|
BLAKE2b-256 | 401b8ebaefed28d8a2c99b4fa565acff05b74d785c21c6f4a319886c6f66ae15 |
Hashes for http_router-3.0.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f5dcca1d38f9bff0f41b2d5a86f77da16e554d9db7b1406d0f52cdbcfcc5c32 |
|
MD5 | e02f5124f4590ce90e4ab44eea176984 |
|
BLAKE2b-256 | 4bcadfc998ef5ef70090c899dd29c8b94524b868eb00c55b5bec65986fcfd017 |
Hashes for http_router-3.0.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b9cf6263b414f39e3807edf939a2d3fba5658cb1cdebad4acd015010d3aec38 |
|
MD5 | cf5c5618294a4e552df177ae86d537db |
|
BLAKE2b-256 | 75522c2e89f7f6a539be801ebe1d11d9a95c45713910bd6723bcf3f5824e6976 |
Hashes for http_router-3.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 244bdd14e4f26ff582f96e2dc6fb4eb484f40b3a035670634d8d2939eb976ff7 |
|
MD5 | aa85d093395311700017a25fcf7951dd |
|
BLAKE2b-256 | 5f7edec6935cd2bf2a97081d6ae3691973c020e9801309b210ef073b87c5ff2a |
Hashes for http_router-3.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a4952f7b5f75829c0a905c76d8b785a1ac5d61ff00cf24c03ddc3dda9e9eafc |
|
MD5 | 08cbd4332eaae5274a4368adea676f10 |
|
BLAKE2b-256 | 73394c4ea1d41aed69d8d6f538285cc0add225505c74803e145153bf8d2072c9 |
Hashes for http_router-3.0.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5894b89e7356d9e142b372e4ed28b757b127880d01c9f20b8e35d7a675121ae2 |
|
MD5 | 4c91e0ddc911ab5c06b4a11bda7303b2 |
|
BLAKE2b-256 | 15fb2387469b3c71ce23f99fd950d1d0620b8e876ee32bbfd4932798aa43fa18 |
Hashes for http_router-3.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9500f1352bc3fcf56f3055b5933ae3e78d78154bad5b46fbe5a0b9bc3ef20b59 |
|
MD5 | 40d2c8cabf41bb671e14db83a08f3099 |
|
BLAKE2b-256 | a306b1ad10ddf20ca87cc609b9bf1e3acc06bf348fdfbf714e5bd22aa761b396 |
Hashes for http_router-3.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 | 2daefd7169a6e10d025b0aa4f0a8d4d23874961f2c67e7e625c53134b7dc150d |
|
MD5 | b5e101204f6eba889a126696978a12cf |
|
BLAKE2b-256 | 32c6f2ca374f0105649d3e6dc9cffd9cf2da6abf7d5a0ce66e10708624ff7868 |
Hashes for http_router-3.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 725ba3c47b3ea5f56d139e79488d64041bd645049495d21dd62d178d408ee974 |
|
MD5 | e59b044b7877341850b338aaa09607a1 |
|
BLAKE2b-256 | 1f9306aaf46ab344bb9fa39731189ab213ce0bf6270661b1ea674375112e40d9 |
Hashes for http_router-3.0.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1f8ee8c31965a8c7565e4139186de22fe185ef847f0ccf6101a872a05dab8b9 |
|
MD5 | f61ee99cb1ca06140fe03eb66a7f0205 |
|
BLAKE2b-256 | be45d4ef03d564c8cf4e13b8027329c7e9f5e68b686eca254a52b2d96c890221 |
Hashes for http_router-3.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c71a6f2a0118eff98a13afbf0603654ff62b5d84d4c123bcf82ad60b668e72e |
|
MD5 | 48c6ecc7ffda7128a8179753d5a5004c |
|
BLAKE2b-256 | 68af0ba3d7e9326363f4b3b348c92948fd91cfe3535c6768f569871917f98837 |
Hashes for http_router-3.0.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e07797c32d42a456cca3085ce49804a2b0311ff84d14edcdd02ec93a6884dec4 |
|
MD5 | 949d46d0925f1f1944bf40d80f516e33 |
|
BLAKE2b-256 | 22fd415478dd26d382d52aea90fdc30bfd670d69fe3a556409f6c8017fefe612 |
Hashes for http_router-3.0.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51cab7aef2da43e1e5cc8eb4221c4072a82e483309e84960e947e58e765749bf |
|
MD5 | d53a0e84cb8e4612eb70b3415d74d2a9 |
|
BLAKE2b-256 | 19d943751891ae22eb5ec3e76a7cc474f1a0e82403c7daa98ff2826c205bce9f |
Hashes for http_router-3.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d206d40b24c83bc8bfa701f96e77bdbc242b4753de1c76e8a115066cb83c8998 |
|
MD5 | 3a5dff5df4aa3b0666e69063e53873c8 |
|
BLAKE2b-256 | e18173e28fe59d64283c9de3efd68c31932c0fc969345a80212366e91f771bf9 |
Hashes for http_router-3.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 | 5b346d801b127ab6d3c67ac5461a8020b480feefa4a04487c800aa953fa4b8d9 |
|
MD5 | adc5e9c66c2a2a78a6fedf5a7cdc91c9 |
|
BLAKE2b-256 | 46284bef25ac7fe4ff8d83993cd1a7a1a8614c5c190f497af12c5c2695a011a7 |
Hashes for http_router-3.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca22b1fca7eca0eaac61b78c280f85e9f080f57cbd365d35fe14688768a35f52 |
|
MD5 | 25d808a72c289e523b78b8cacdbb079e |
|
BLAKE2b-256 | c9758af9d921d9206d9f4ab9fc222cd126bf59ce6dde463144b945272c928a55 |
Hashes for http_router-3.0.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf05e8d29670d5152711a9c05ee89c78a83b82ad1f2cce080915e0997e1c7493 |
|
MD5 | e800983448e9f9a9a7f2dc020e793b09 |
|
BLAKE2b-256 | fccec337f7ebcc6952d2e62f78a6a91b7edb21e00f1bc18c8ccd19bf343bc548 |
Hashes for http_router-3.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79c923bf30999279ca3c92c3de4a33023fda147f28df6f58ef167be344452f4f |
|
MD5 | 8587e3a375281e429da1962bf7dca3b0 |
|
BLAKE2b-256 | aa6260104606d084f18c0360af7b2c7d54d140c23e64f665a0c371f42040f0e5 |
Hashes for http_router-3.0.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4225d4f10fbb4759744506b615a05b1bc0c9a399e50d2c886428fba0a3954b7f |
|
MD5 | 87d0977a3f9a005bdf0ccdabf5b101ae |
|
BLAKE2b-256 | fd88f630bb26481d593312c6619c9dd6d00ae980bc237cfbd928a03087efbfa2 |
Hashes for http_router-3.0.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a1b2ae50abb384503b9590d40bad3ba56b843f2a43af86a2bef455965eed644 |
|
MD5 | 754cccb784d104f029b3bd04cde7bd0f |
|
BLAKE2b-256 | c09c051d3ddc18e1a2de682fcc9f4e538fa430bf164f4ca3daedffdc76960cdb |
Hashes for http_router-3.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b296341cc45831bb23e7fcb16c7cd429fbbed3637a5deea376d65f851c3b75bc |
|
MD5 | de2abd5d837d0a8ffa5de9c61f054f73 |
|
BLAKE2b-256 | 4cabc8a36443f135243e74f22a7e5f7502223bdc1e3d844a8b01a929d41499c8 |
Hashes for http_router-3.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 | 153ff1505647f1d981d20a07f5838b150d1f25aa0dfcd2ad00e0858131dc1a09 |
|
MD5 | b48c7035989f4d3136f37fc02cdf6ec1 |
|
BLAKE2b-256 | 9d141bb0010a90e597476b0ec3393b3cfaac8dcb3beef3eb23581ec7144b7905 |
Hashes for http_router-3.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7f2eedcb9e14e6d1faa1c7cc3d1177802027d752a6e1701e5925bdd8a07a067 |
|
MD5 | 610db1e025fccdc917a4b1f7864d7aaa |
|
BLAKE2b-256 | d530e9aa0fc279eb395a53fd0340da97e947b1d6c7628d423dfe095650d9c546 |
Hashes for http_router-3.0.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a3eb0dc782d7adf2f406e8b205dc6290cbe654ed73e1b70bec53045198fe9b |
|
MD5 | bea86e3978135c9bf55079b41b681ca1 |
|
BLAKE2b-256 | f9dd9b8d4d9f6fac3173f89c698c940672e3415937e7f0882b5d927cacf3562d |
Hashes for http_router-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd498e51fad9e79b3ffb340e301c5279410bb4024785504954b601691c46cdb7 |
|
MD5 | 90640b205b2f4793fe5f4f90113c468a |
|
BLAKE2b-256 | 1dad02255e03925d658f6a44dd7b30e39ac2550f0325978d56058d7c0120022d |
Hashes for http_router-3.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15de53c8a85c50b2a8d90b88b1bc856f2cab9bc30869b9b16fc1e7c98c37acb9 |
|
MD5 | ca40e56fb946191e299e4969daf9e05d |
|
BLAKE2b-256 | a67117831e50f1c55f31037c0bdb325be714c4ce178f1fc19b0d279225955316 |
Hashes for http_router-3.0.0-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b680984a55f44677c13499c00d21e91ed9bb58dda3a9551c1372a833d62a79a |
|
MD5 | d84923546ba9b542ee1364d8c373ba29 |
|
BLAKE2b-256 | 1b25466912bb6172817c78d3c92e5938c40c464baacb20669c025a9c01a39182 |
Hashes for http_router-3.0.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3961ad0f27c4823b0be4291a16dc6e9c395f1c623932b3584b2290dd10120108 |
|
MD5 | 5b357d6d0dd98f69f762a2b37c3a40a9 |
|
BLAKE2b-256 | d5d20a245f77b26f9fd878596cfe19277d90a088f62d2795da5ba3986f28d2ff |
Hashes for http_router-3.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 | 6aae66aab65bd303a2db8750eb6ea73dcf6a6d87a72bded08d998392d7914747 |
|
MD5 | fcc9fc7fa9579550f573304f8af889e6 |
|
BLAKE2b-256 | 334355d2d903f94462ccd8d6bb07e08fc7eacfa3e6e15ac50abbc222fd1aebf3 |
Hashes for http_router-3.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a891855d22f8a579e8ae9e729bc77ffeed1a4231992f5627df14dc3ad011c2e1 |
|
MD5 | 18d6ec937c2bb0c462b09b53af7c7b2d |
|
BLAKE2b-256 | 5c498287606b5f524378f12caa0a4cdc2ee745ae45332f8aaa1af4b39f2d313c |