Socket
Socket
Sign inDemoInstall

silvanus

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

silvanus

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


Maintainers
1

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:

  • full example

  • simple asgi app example

  • examples directory

  • tests directory

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc