Skip to content

Wred

Small core. Explicit behavior. Optional capabilities.

Wred is an ultra-minimal Python ASGI framework for JSON APIs, pronounced “red.” Its core handles routing, requests, and responses. orjson is its only required dependency. Applications choose their own validation, authentication, storage, and deployment tools.

from wred import App

app = App()

@app.route("/hello/{name}")
async def hello(request, name):
    return {"hello": name}

Handlers are async functions returning JSON-serializable values, bytes, (body, headers, status) tuples, or callable ASGI responses for streaming. Wred handles HTTP; optional ASGI wrappers add lifecycle, browser sharing policy, middleware, and WebSocket routes.

Philosophy

Keep the core small enough to understand. Make dependencies and execution order visible. Add capabilities where an application needs them. Extensions use ordinary decorators and ASGI wrappers without plugin discovery or changes to the core. Independent packages follow a shared extension contract so they can evolve together without becoming one large framework.

Extensions

Package Capability
wred-middleware Async request/response hooks and streaming-safe HTTP policy
wred-websockets WebSocket routes, origin policy, bounded connections/messages
wred-jinja2 Async HTML templates, autoescaping, bounded rendering
wred-pydantic Validation, serialization, OpenAPI, bundled Swagger UI
wred-auth Bearer auth, accounts, sessions, roles, social login, MFA
wred-ratelimit Memory/Redis handler quotas
wred-cache Response caching and invalidation with memory/Redis
wred-errors Explicit exception-to-response mapping
wred-pagination Offset/cursor pagination and SQLAlchemy adapters
wred-lifespan Async startup and shutdown hooks
wred-cors Browser origin policy and preflights, powered by Starlette

OpenAPI lives in wred-pydantic; there is no separate wred-openapi package.

Composition

Register the complete decorator stack with @app.route outermost:

from pydantic import BaseModel
from wred import App
from wred_pydantic import path, response
from wred_ratelimit import Limiter

app = App()
limiter = Limiter()

class ItemPath(BaseModel):
    item_id: int

@app.route("/items/{item_id}")
@limiter.limit("60/minute")
@path(ItemPath)
@response(dict)
async def item(request, item_id, path):
    return {"id": path.item_id}

Close resources with lifecycle shutdown hooks. Put auth and quotas outside caching when they must run on hits. Use shared storage for multiworker quotas and cache invalidation. See the contract and production guidance for ordering, request state, metadata, and compatibility expectations.

The current baseline targets Wred 0.15. Read the production and migration guide for per-package limits, shared storage, failure policy, and reproducible release gates. Candidate source compatibility does not imply every package is published.

Pinned Loading

  1. wred wred Public

    Wred is a Python ASGI router for JSON APIs using orjson

    Python 1

Repositories

Showing 10 of 13 repositories

Top languages

Loading…

Most used topics

Loading…