Skip to main content

A simple router for HTTP applications

Project description

http-router – A simple router for HTTP applications

Tests Status PYPI Version Python Versions

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

http-router-2.6.4.tar.gz (139.9 kB view details)

Uploaded Source

Built Distributions

http_router-2.6.4-cp310-cp310-win_amd64.whl (226.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

http_router-2.6.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (645.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

http_router-2.6.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (659.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

http_router-2.6.4-cp310-cp310-macosx_10_9_x86_64.whl (239.5 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

http_router-2.6.4-cp310-cp310-macosx_10_9_universal2.whl (331.2 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

http_router-2.6.4-cp39-cp39-win_amd64.whl (226.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

http_router-2.6.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (644.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

http_router-2.6.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (656.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

http_router-2.6.4-cp39-cp39-macosx_10_9_x86_64.whl (239.5 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

http_router-2.6.4-cp39-cp39-macosx_10_9_universal2.whl (330.7 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

http_router-2.6.4-cp38-cp38-win_amd64.whl (226.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

http_router-2.6.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (661.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

http_router-2.6.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (682.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

http_router-2.6.4-cp38-cp38-macosx_10_9_x86_64.whl (236.9 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

http_router-2.6.4-cp38-cp38-macosx_10_9_universal2.whl (326.2 kB view details)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

http_router-2.6.4-cp37-cp37m-win_amd64.whl (223.9 kB view details)

Uploaded CPython 3.7m Windows x86-64

http_router-2.6.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (595.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

http_router-2.6.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (596.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

http_router-2.6.4-cp37-cp37m-macosx_10_9_x86_64.whl (235.4 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file http-router-2.6.4.tar.gz.

File metadata

  • Download URL: http-router-2.6.4.tar.gz
  • Upload date:
  • Size: 139.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http-router-2.6.4.tar.gz
Algorithm Hash digest
SHA256 e9e65c164b15864ed8d469318eb72a4a1ca5d07e86b05e8c35212b0ff33fcade
MD5 74d9631919f5ad89a175786d5ef32571
BLAKE2b-256 cbcae1d5508f606414ee28d5b87669fdd3abb9f623b96ac31d16451d3f20fbea

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 226.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5e71f5a0b5df26ce0d63b861cf4845465022b0b020c1fa63e37544f1f7e4dd96
MD5 158c12ffe1e2f797dc1ad8fde8b2e751
BLAKE2b-256 f6e857a22205861bc5c619aeb90e2b1b9b1067e6c96a2ffcbdad1a06cf2875b6

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c5e80202729bfda2b7c5a0e061f2722cc4e455fbe99897b6162d529ba5b21f62
MD5 e18d1a422e2145b054fbb32f1339bd57
BLAKE2b-256 feb8ef0559c6a57268966931a95e03dcd9b15299eda91f0b8ed8986ed416395b

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ca03a605aadf268c03f4e661bde2872cd000e6564f6ca7c8b3523c757b6772d0
MD5 22f1596e7ceb856a4b97e3ba3c85e32b
BLAKE2b-256 407ef4d8d25ba148bbad96addc04985f6f06e1d503d7d345bd03b4bb92304f96

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 239.5 kB
  • Tags: CPython 3.10, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 66993b8a7224567ed65c2c11871aaf70e30ecce560b10bcd1f3ecc3be36e8e0c
MD5 0fd46b89bd4bb78fbe81ad7ba202bacd
BLAKE2b-256 28465d3dbc012627541e667c9e579950fe44bf141a8351de4f4565d05af33579

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

  • Download URL: http_router-2.6.4-cp310-cp310-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 331.2 kB
  • Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6ca1bb1e1cad164cf247ca593131e9adfd6ef6213b7331daff905bdb5328e24a
MD5 c8dab863cfe6bcd2fe48e972730a4789
BLAKE2b-256 0776f6beb57250e8f9ef59fb29b0796bbd041b99b7da0c71eb17132453884585

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 226.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4b813c12ad37757cdf86cd02f84972cb7e0ab18a6cbf2d26c1735339af4b0b94
MD5 a87b9a5862f5eb8db20a007b26c2e20e
BLAKE2b-256 5d003850e1b3598d4b015d76d4c0c959e1951ef3e87a4f5a9d17c3ada666189b

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a87e8340d7943f29fa54555d59cbd7ba6726dc684597e0eb546baae17876d57
MD5 f0c2364bd62296243493088b35c59db1
BLAKE2b-256 eb014971a6443404b3031640e1dddbe9e4eaf6fe59387bd79094d14ac8f834a8

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 caa00e85c0433016ea056919530f1877142e2cf86efcb412cdd94070ea78a44d
MD5 420af535fc779939be6a875e75f25c97
BLAKE2b-256 7dbdd6676ad839f681e9d56fb077786804fc7854af1c5bcf6d2e71ff538783c8

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 239.5 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8b0bc725750be43bc6058265756b0d37f0984c1a30a73eb1539454731e99a4b0
MD5 24e0788b4ee29314a9e6ea70d390b813
BLAKE2b-256 2da350ffa4435c77d3945822bb1c03e1226cac05bf6095c484d03c95fcd8fcd7

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

  • Download URL: http_router-2.6.4-cp39-cp39-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 330.7 kB
  • Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4085a1dd7e701877e0e00be64f68f466a33fc96f51bffeafb6f86c36531ec070
MD5 9862bcf6676fc40a5a724fb51e3542a4
BLAKE2b-256 30b7b6f63eedec23112175f7d95b833e41ef1b9a538a03df27243a3610dbd2b7

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 226.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f4a2e256b38b8e91e4825e5cda47f278959732563fa4140cb9f7df9a17f52274
MD5 cc7eda2eba9c44222b81072e737f79ff
BLAKE2b-256 32537a8228f05484a3a0572db7d43975b31f02e4dd4a39066390381efef1bf0f

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c85211e166d6faa56ebc1e53da92d91152f78006bbc791b72cd86db45e243fb7
MD5 fb70256989df22cf49446f491988e1ca
BLAKE2b-256 6d8247413af2d673adba89d2de5f3ffb872a2ab62bd5833b148a0d4db9e4f380

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 7e9b1aa18eff995360913d4cb252638401673e42686d32c1df0f0b853dc0f5ea
MD5 9f47689bfae3c5dd48db1f7f0f5336fb
BLAKE2b-256 45c03d53af947ce1d39393166ead85fa9b4f5a7b614c3c91e91f8fc5ce2c5cab

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 236.9 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e28cacf39e12d442e7f6bffc44d8662615f398727aa88a79c90ae6a89fddeafb
MD5 74ceccfadd101cb09149a71a291b7cfb
BLAKE2b-256 cefbbc30902db39b14b4f45da298de5d3eb87459ce206d6b254c55634e14cab9

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

  • Download URL: http_router-2.6.4-cp38-cp38-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 326.2 kB
  • Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 7d073d65b6eb31b7928fb4c072a6e47ee14683436d635d9d19fe54dccfaa6352
MD5 bb8314b79c1e46b6abd35742b5724d8e
BLAKE2b-256 77f79e5d5eb3c9edebda80b2a92166a9e8472ac470d97f865d2dbb9688cec05a

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 223.9 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6796f77315900f1f1a100ec06ace3268f9c9a5e2146c6a53f9eeabbf8e33d4b5
MD5 b4445baeaef342c4776f6be6ed0452dd
BLAKE2b-256 5f177dea94488512a0cc9a5ab3ee1d481ad6ec3a2a5b84a15b7cf64d8c96358b

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f7437eb6664aed01cc446fa3cdd269b58a771527a1d8f5087a6f0724bcd326c7
MD5 208a678f654dfdbb6ccf9f668ef3e327
BLAKE2b-256 dcac278736f06e9d611ad19b857e407c4054f04dc00226ff28f92b541e459449

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for http_router-2.6.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 18ad2fec3d469b3354bf211f14b602af10bc1835d4b829d47b7c2a69113519c1
MD5 f24665987fe9b96358312cce920c33fd
BLAKE2b-256 244610bc21f3c09185571ad2cdc50308eb956a947915a3f22b96f91ec5b00ac7

See more details on using hashes here.

File details

Details for the file http_router-2.6.4-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: http_router-2.6.4-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 235.4 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for http_router-2.6.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1df3dde79b3e80b8df3f512d99884f9fa8d30d3970b7b68686dd1a8a2746dba9
MD5 38df3d29f93df956d1372b4bc88b414c
BLAKE2b-256 c8c687c42388f97be2a177ada1e3d471c4bf640188cb26ef74403697c152220b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page