Skip to main content

A lightweight routing framework for Python Workers

Project description

Kinglet Logo

Kinglet

Lightning-fast Python web framework for Cloudflare Workers

Quick Start

Install: pip install kinglet or add dependencies = ["kinglet"] to pyproject.toml

from kinglet import Kinglet

app = Kinglet(root_path="/api")

@app.post("/auth/login")
async def login(request):
    data = await request.json()
    return {"token": "jwt-token", "user": data["email"]}

Why Kinglet?

Feature Kinglet FastAPI Flask
Bundle Size 226KB 7.8MB 1.9MB
Testing No server needed TestServer required Test client required
Workers Ready ✅ Built-in ❌ Complex setup ❌ Not compatible

Key Features

Core: Decorator routing, typed parameters, middleware, auto error handling, serverless testing Cloudflare: D1/R2/KV helpers, cache-aside pattern, CDN-aware URLs
Security: JWT validation, TOTP/2FA, geo-restrictions, fine-grained auth decorators Developer: Full type hints, debug mode, request validation, zero-dependency testing

Examples

Typed Parameters & Auth:

@app.get("/users/{user_id}")
async def get_user(request):
    user_id = request.path_param_int("user_id")  # Validates or returns 400
    token = request.bearer_token()               # Extract JWT
    limit = request.query_int("limit", 10)       # Query params with defaults
    return {"user": user_id, "token": token}

Security & Access Control:

@app.get("/admin/debug")
@require_dev()                    # 404 in production (blackhole)
@geo_restrict(allowed=["US"])     # HTTP 451 for other countries
async def debug_endpoint(request):
    return {"debug": "sensitive data"}

Testing (No Server):

def test_api():
    client = TestClient(app)
    status, headers, body = client.request("GET", "/users/123")
    assert status == 200

Documentation


Built for Cloudflare Workers Python community. Need help?

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

kinglet-1.4.1.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kinglet-1.4.1-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file kinglet-1.4.1.tar.gz.

File metadata

  • Download URL: kinglet-1.4.1.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for kinglet-1.4.1.tar.gz
Algorithm Hash digest
SHA256 8ab63d1ace1537d8f6a90f876ef9c1f01a966cd452ce960d3f4adb75e3d92c22
MD5 e3985f692d358bd49e2cf7c12ccfc649
BLAKE2b-256 d488efdd6ffd74f5a5824a33c5cb45baf7e3349eccdbe00cfaa294e7fd211863

See more details on using hashes here.

File details

Details for the file kinglet-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: kinglet-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for kinglet-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0e59a12466b1e51fffd93b0e49c8e9b30c821a96a27104ba7b1a2962c49556f
MD5 559eb86c72842a74ccff7dac613351d9
BLAKE2b-256 5a6643248b0cc73d49eadf3e3690ef18ad2e0e9aafd795f842320397ee831473

See more details on using hashes here.

Supported by

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