Skip to main content

A simple library for URL routing with a tree-like prefix structure

Project description

silvanus

A simple library for URL routing with a tree-like prefix structure

Examples:

from silvanus import Router

router = Router()

@router.get("/{bar}")
def handler_too(bar: str):
    return f"Text: '{bar}'"


@router.get("/{foo}")
def handler_too(foo: int):
    return foo * 10


@router.get("/me")
def me_handler():
    return "it's me"

@router.get("/{foo}/{prefix}/{tree}")
def chaos_handler(prefix: str, tree: bool, foo: int):
    return prefix, tree, foo

router.sort()

handler, data = router.route("GET", "/me")
assert handler(**data) == "it's me"

handler, data = router.route("GET", "/some_text")
assert handler(**data) == "Text: 'some_text'"

handler, data = router.route("GET", "/10")
assert handler(**data) == 100

handler, data = router.route("GET", "/12345/text/true")
assert handler(**data) == ("text", True, 12345)

Other examples of using routing:

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

silvanus-0.0.0a2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

silvanus-0.0.0a2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file silvanus-0.0.0a2.tar.gz.

File metadata

  • Download URL: silvanus-0.0.0a2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Windows/10

File hashes

Hashes for silvanus-0.0.0a2.tar.gz
Algorithm Hash digest
SHA256 068dd161c359bfd01db3e8a7e73f672489e75b1c1f4d3df00887ef1bfc687815
MD5 757040426dbd009fb3f995e129004d1f
BLAKE2b-256 2506b2c37c70f226c68e30c84c532d0d2433d1f92090ee0a83fc4a590fdac247

See more details on using hashes here.

File details

Details for the file silvanus-0.0.0a2-py3-none-any.whl.

File metadata

  • Download URL: silvanus-0.0.0a2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Windows/10

File hashes

Hashes for silvanus-0.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 cbd820f89cd341c789f722bdddc18527c201b0585164d096a06e573c4718bc71
MD5 c44c376147497d6f21b5c5f1131d0aa5
BLAKE2b-256 26a1b8751a9f4a05c525f9ad13c0b328bf05be7c32f56098e9ca13a77ddc246c

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