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-3.0.6-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 063cf134669b500deaa9ddd8b5dd4147ca25836335ab2fefaab18ad3782840d1 |
|
MD5 | 09e584bf341949d0920e998b1d52d4e4 |
|
BLAKE2b-256 | 825de745d1455c4c9ee92869d0f17c2c46c6b75cc22811889564acbf43b31b6a |
Hashes for http_router-3.0.6-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8ef01442762d02560d28dd2c34aa994435673985deca12dc40a9f5cc5fdcc56 |
|
MD5 | 36d8f6ebc0217ee8c27fbb96061e58bf |
|
BLAKE2b-256 | 398fbd5bde7847650d7fca095e3b1553480cfe2d6deaa3fa60dd391c8fb7359b |
Hashes for http_router-3.0.6-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 759a543825fe238b2312e9f61038f75c648a8d9a250be0f26472a358613bddd4 |
|
MD5 | 5988a44527fb4c19c3d9b901e0a7252f |
|
BLAKE2b-256 | bc7961ebc9a520a920e5cc9bc535a857f4305e01f30a900ff446ee6d115e5cad |
Hashes for http_router-3.0.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c615f40da3b81802836978d5d1bc5d12a42911b7403b4f4fb348a6f4467ab04 |
|
MD5 | fec23b39ce5fb4c7e92ccbb9956cb2a1 |
|
BLAKE2b-256 | 7395496738408f295bbb5f957c97443063e2cb12bf89f8dcbee255fae071b586 |
Hashes for http_router-3.0.6-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8620795b4306eb835b4118772a099dcd9b7ad743a128198d1cdafe343ab71475 |
|
MD5 | 844554721b89b02cff13846596ab4c3f |
|
BLAKE2b-256 | c8a705446090cdcbefdc309928df1231327541b1c640ece1c7d94fe72b7111aa |
Hashes for http_router-3.0.6-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa93eb5e0a23bbf2fbfbf0dd5f7daf0fac0edbc9b6bd6c6be908ec2156a742bf |
|
MD5 | eec580202e2192be2740e5f1b998a7b6 |
|
BLAKE2b-256 | 57d8af07a96f6511036a95abda37cf905ec24b29f8a08bfb57711660b5c9644c |
Hashes for http_router-3.0.6-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe5d215b40c3d606548fe4a62aa4d259dfa6b4e8d188d9bbdca4863b43dc8da |
|
MD5 | 1f2b98c5ed5502695d72342b29c43e74 |
|
BLAKE2b-256 | e9c0249a59977798f4f489eac470964590378509f1644bcf23b6dfa43a7d73ac |
Hashes for http_router-3.0.6-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2230043dd3711942b6f4e65c51ef17908f8a6a1d854610ffcda66c4f69f7da2b |
|
MD5 | 7b01d43b1dff5e4ba0dc302cba68cb45 |
|
BLAKE2b-256 | 84a18738118d9c69584d1c4500efc7382c8e27fc42378aaea5bbd18a37c829a7 |
Hashes for http_router-3.0.6-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4530a38a8014b04ab7eb000bca3fdfdbc85a0ba656d1a6325d7ad9658cfb066e |
|
MD5 | 8376c6f6c036fefa544453ed4cb9eff6 |
|
BLAKE2b-256 | 7fe0a66212ac8aea387b4ab42164a3b68cef5530524024e8fbe2538db8c1ebdb |
Hashes for http_router-3.0.6-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e02b01032658ea8650d283b56cfd3760ca120c90950edea3439bbd07c330ed44 |
|
MD5 | 657cb0d32fbf2d65b8b8e816875da252 |
|
BLAKE2b-256 | 6ea16eabe5522c6164e427e23545a78867b74432f46d6270fdd2aa3ee55635c0 |
Hashes for http_router-3.0.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51cf0d95964a66f23b7caa7ce162641da484086562bc27b4fd275cfda40b7994 |
|
MD5 | eb25c876c134a9e502d8f727b47daf12 |
|
BLAKE2b-256 | a61080143160b6eccd3c793f4cc49a3d75d5b3842ee6d47ab705dcb4a329c7d9 |
Hashes for http_router-3.0.6-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de53556802eb8c7f60f17306f5ae24b0a9c286655d733becc19879e53bb721b2 |
|
MD5 | e8fe987d38b67465d870b1be74d80f44 |
|
BLAKE2b-256 | 61e43a888b9713ef3f2c9a2e73b9b4531b6f863e2fbbd9000cd01b9609189a33 |
Hashes for http_router-3.0.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aaa6acf924e01720e71d49527b0a0929c798fde45a5dd65dcd8bfffefd74f39 |
|
MD5 | fe925cefaa418fbc45f41d638cd80acb |
|
BLAKE2b-256 | cd52ff34200eadd1e25c2f0db0476db62041cc8a7f232e2c5729a39ca9dd2bc5 |
Hashes for http_router-3.0.6-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 831bbcf0c0adb7920a49be64976e965182a9c707d80923bdd49776d7112750e3 |
|
MD5 | 4e17bd9b2b3024e5b969307145763b67 |
|
BLAKE2b-256 | a616b798ca1ece1670819166d47f48dee60e58e9af09af4c313b5fee2c5b1c27 |
Hashes for http_router-3.0.6-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8378d2cf185ebfdf026cac603ca604963cbc9fd769952bd1e90da2afbb95676 |
|
MD5 | 07eca0bbad04a8296e3cffc18e7f231f |
|
BLAKE2b-256 | 9d8f98857b000648aa1bfeffbab451a362767ac36fb87705108aa4095bad7132 |
Hashes for http_router-3.0.6-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b350e29abc4db2793ea6923a98e2e2423fd14428ddd8f06fc3c39a07c2c7879b |
|
MD5 | 17a84d27ee6fc5253363119a25e2fc59 |
|
BLAKE2b-256 | 3fd34b230c4fb7b68c5eb2df3031472efe21053a1be7c946d4f5f34311b0fbd8 |
Hashes for http_router-3.0.6-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ce5970cdc9206cfdd0098df58ddc2fa15fae8553ccb562e32fb8aea6f551149 |
|
MD5 | 019b0ec0eda27f2e11cb251b405ae078 |
|
BLAKE2b-256 | fda59fa84c3a1765d610e65c0840bcf639e432c0f45e2a161cff45e42ec3acc8 |
Hashes for http_router-3.0.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87aa12dba6d7d5eb514911a5561fbfa75949f590a0d90e3065c2c0854847f9c2 |
|
MD5 | 0432e183f27493ba2d83ea03592b5064 |
|
BLAKE2b-256 | 1497a349f95cd2049d7869c9fdb6714a9aced57702183f4fb8802da42a1fa583 |
Hashes for http_router-3.0.6-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e157f48785062cce8e9cb721d7616422888b4e85ef4a9fd753d586084a8751 |
|
MD5 | d1cd0cabf6bf8f1c071ec4e217f01ebd |
|
BLAKE2b-256 | be269fd2b56f2b8d6a65fa565470d94d65a62018da94676bf515322fb1e47501 |
Hashes for http_router-3.0.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1735efa1d8d2f7b144f41c8f52f38be3189cf52711b1bb8b5823485b5d6dd6a |
|
MD5 | 8247afc62f1ce9c1fe3184cef6aa3b52 |
|
BLAKE2b-256 | b324970d6fd41c4561bf94b875c3282aa098160c90aa2ec6e732f7ed2cebb5d0 |
Hashes for http_router-3.0.6-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51b53abd61a1cbee1006b409a84b27b54a4e4fbdff21bbe035259f8c3d7201f6 |
|
MD5 | d94d7953f73d293d858124e666afa779 |
|
BLAKE2b-256 | d3352eec1f3b052c23163218e6cb22723dcc72997fabdd9a0ebe6aa6e2aedcb3 |
Hashes for http_router-3.0.6-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a01a421edee7da55b9311a45f367dd52e0a83e4c52b11ab5f0fe8a58654c17b |
|
MD5 | c47d7ea7810ebf06f82c4d1e241e2c0d |
|
BLAKE2b-256 | ae6a517a7b7628bf12e16fdeb18418b00a8d6994202fbcb870bc6da05792b2ce |
Hashes for http_router-3.0.6-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 385e52bd6d7c9dba6455c5d49afcb2976fe23d28ff3bb8f84fd959c8ede43180 |
|
MD5 | 909d0f40dd543cebbfda263d37373069 |
|
BLAKE2b-256 | 85cb47094cc957bd9222046bc1d26c7245a4d23b74c04a9982a77257b73ab5bb |
Hashes for http_router-3.0.6-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3387c4884dd37d30cfd84b1292088bf5d99ebff9f78180af6ef491d661ba3d30 |
|
MD5 | 44f0b88e74e3c375ff5567db44da03de |
|
BLAKE2b-256 | 56699996c99f6082c8600eef8e211146872cade2a38f875696e7988910ae491f |
Hashes for http_router-3.0.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 091d7ebca4dc4797dc2ecfdacb8e01c24cb4c03daabcf6f8e9b9cca4f688b06e |
|
MD5 | c3c9c53db6932811bdd2a69d3332dff5 |
|
BLAKE2b-256 | c10b8277e7af1cd5eb16ea6dcf63a5d25862f0f18225a672f93bdc2d2d93a347 |
Hashes for http_router-3.0.6-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71dfcaf939f1e90c46d98f824e05c609052555534ea145a4ec8a21ce380641b2 |
|
MD5 | c676fc5f18a69552938d98bbb79ea280 |
|
BLAKE2b-256 | 7e96cfdc0890d75acfc3113f3ead8bf0ce2ad737f7249d91dc1bb3c62f10bb03 |
Hashes for http_router-3.0.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34c8dd6ac46489ac10e166dbe7ebf55152473ffa23e0031c043b27b2ecb1f03a |
|
MD5 | 5b0e7940f41cef212e9c25c8178e65f0 |
|
BLAKE2b-256 | 92c8fae96a5217a564e6d731bb423a8709fc2b5e46a37394fb71dc26c89e1f09 |
Hashes for http_router-3.0.6-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 037f1bb0ac75496fc2756d10f9da94a276acf71dcc101673f9142244b5ef9ce3 |
|
MD5 | 6cda213369324b25a4995c76eb878358 |
|
BLAKE2b-256 | 2bc38f8787292a69e99615d7a4b9339af47cab046218e0ccc4122e2184e7d6ef |
Hashes for http_router-3.0.6-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7089366a697579d91d2b870707d5d6211df34a5385753fa53f023464a9eb4e |
|
MD5 | fb3a93d393256ff80d2355fabcf41f5e |
|
BLAKE2b-256 | 8c7aec648c1e7d19f8e55524458eae591b8dfde1f7442dccdb1117c850d0d41f |
Hashes for http_router-3.0.6-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa153611402096eb6838f8a792df8f66086dde89f5f610de7e7c249f831b872a |
|
MD5 | 7a12c826a4ff8c0f0fdb98b8570b8c3a |
|
BLAKE2b-256 | 3e47ad9b0680d28c258d496a5aad86cc7e9903f1e6b2282a17c0fdd5dd71eeb2 |
Hashes for http_router-3.0.6-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0dbc008275f5f00dc886b07ee2cf50244fd316dd9d409c80e1ac613aec15006 |
|
MD5 | 4ada26ad042c3f5d641019789a2309fb |
|
BLAKE2b-256 | 558e7c8c6049d45e675edd4ce522e9a7589f2e1d6c614b093241bb7bb45c8e6c |
Hashes for http_router-3.0.6-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7006fc53651a863b479a147d151a931208ad7457ce55301cd166afab969af214 |
|
MD5 | 42eb09e79136995843458d07ffd7629b |
|
BLAKE2b-256 | c95781e8e51cfd9ad46c66794ede78788fd079571b6efa87c18b11e11e2b9b2f |
Hashes for http_router-3.0.6-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ba984d65497584442c7398e62e8fef8fda315021247b77010a5ff27c0eb7273 |
|
MD5 | 11991ad7e683a7c3eca13449a4b85482 |
|
BLAKE2b-256 | c9fe7305fd957171f6f87b76933c1ef68d80b84c0fb38e70ef313b03984af5ab |
Hashes for http_router-3.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97be4dcf6fab93808231277bc065a85ae4ca9b427623cc0ab9686730b3fb37b7 |
|
MD5 | 674b09d4ec9629e2ce0d3c64e5767213 |
|
BLAKE2b-256 | 148d2b1fbada8d6cc8ca6ae953ab81b902a819c64c54b7e86b865afd94e2e21e |