Skip to main content

No project description provided

Project description

Squall

Squall routing subsystem. Python binding for the Rust Squall router

License: MIT PyPi PyVersions

Installation

pip3 install squall-router

Usage

from squall_router import Router

router = Router()
router.add_validator("int", r"^[0-9]+$")
router.add_validator("uuid", r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")

router.add_route("GET", "/repo/{repo_name}", 0)
router.add_route("GET", "/user/{user_id:int}", 1)
router.add_route("GET", "/event/{event_id:uuid}", 2)
router.add_location("GET", "/static", 3)

assert router.resolve("GET", "/repo/squall") == (0, [("repo_name", "squall")])
assert router.resolve("GET", "/user/123") == (1, [("user_id", "123")])
assert router.resolve("GET", "/user/user") is None

event_id = "6d1a7b12-f2de-4ba7-b3c5-a4af3cab757d"
assert router.resolve("GET", f"/event/{event_id}") == (2, [("event_id", event_id)])
assert router.resolve("GET", f"/event/123432") is None

assert router.resolve("GET", f"/static/css/style.css") == (3, [])

Ignore trailing slashes mode

set_ignore_trailing_slashes - Allows to put the router in a mode where all trailing slashes will be ignored on both, route registration and resolving stages

from squall_router import Router

router = Router()
router.set_ignore_trailing_slashes()
router.add_validator("int", r"^[0-9]+$")
router.add_validator("uuid", r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")

router.add_route("GET", "/repo/{repo_name}/", 0)
router.add_route("GET", "/user/{user_id:int}/", 1)
router.add_route("GET", "/event/{event_id:uuid}", 2)
router.add_location("GET", "/static", 3)

assert router.resolve("GET", "/repo/squall") == (0, [("repo_name", "squall")])
assert router.resolve("GET", "/user/123") == (1, [("user_id", "123")])
assert router.resolve("GET", "/user/user") is None

event_id = "6d1a7b12-f2de-4ba7-b3c5-a4af3cab757d"
assert router.resolve("GET", f"/event/{event_id}/") == (2, [("event_id", event_id)])
assert router.resolve("GET", f"/event/123432/") is None

assert router.resolve("GET", f"/static/css/style.css") == (3, [])

Download files

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

Source Distribution

squall_router-0.2.1.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distributions

squall_router-0.2.1-cp310-none-win_amd64.whl (515.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

squall_router-0.2.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

squall_router-0.2.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

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

squall_router-0.2.1-cp39-none-win_amd64.whl (515.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

squall_router-0.2.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

squall_router-0.2.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

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

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