A light weight Python async framework with batteries included.¶
import dyne
from dyne.ext.auth import authenticate, BasicAuth
from dyne.ext.io.pydantic import input, output, expect
from dyne.ext.openapi import OpenAPI
app = dyne.App()
db = Alchemical(app)
api = OpenAPI(app, description=description)
basic_auth = BasicAuth()
@app.route("/book", methods=["POST"])
@authenticate(basic_auth, role="admin")
@input(BookCreateSchema, location="form")
@output(BookSchema, status_code=201)
@expect({401: "Unauthorized", 400: "Invalid file format"})
@db.transaction
async def create_book(req, resp, *, data):
"""
Create a new Book
---
This endpoint allows admins to upload a book cover and metadata.
"""
image = data.pop("image")
await image.asave(f"uploads/{image.filename}") # The image is already validated for extension and size.
book = await Book.create(**data, cover=image.filename)
resp.obj = book
Dyne delivers a production-ready ASGI foundation out of the box. It features an integrated static file server powered by (WhiteNoise), Jinja2 templating for dynamic rendering, and a high-performance uvloop-based webserver—all optimized with automatic Gzip compression for reduced latency.
Features¶
A built in testing client that uses the actual Requests you know and love.
A Pleasant Application Experience: Designed for developer happiness with a clean, intuitive, and consistent API.
Native ASGI Foundation: Built on the ASGI standard for high-performance, fully asynchronous applications.
Expressive Routing: Declare routes using familiar f-string syntax, improving readability and maintainability.
First-Class Configuration: Strongly typed, auto-casted configuration with .env auto-discovery, environment variable overrides, and validation at startup.
Database Integration: First-class
SQLAlchemysupport powered byAlchemical, providing clean session management, async-friendly patterns, and declarative configuration.Seamless API Documentation: Fully self-generated
OpenAPIdocumentation with an interactive UI and native support for both Pydantic and Marshmallow schemas.Flexible View Layer: Support for function-based or class-based views (without mandatory inheritance) and a mutable response object that simplifies response handling.
GraphQL Support: Native integration with
StrawberryandGraphene, includingGraphiQLfor interactive schema exploration.Webhooks & Async Events: First-class webhook definition and documentation via the
@webhookdecorator, enabling clearly defined outbound callbacks and event-driven workflows.Request & Response Lifecycle: Powerful decorators such as
@inputfor validation,@outputfor serialization, and@expectfor enforcing headers, cookies, and request metadata.Bidirectional Communication: Built-in support for
WebSocketsalongside traditional HTTP and GraphQL endpoints.Background Tasks: Easily offload long-running or blocking work using a built-in ThreadPoolExecutor.
Extensible Architecture: Mount any ASGI-compatible application at a subroute and serve single-page applications (SPAs) natively.
Integrated Security: First-class authentication support for BasicAuth, TokenAuth, and DigestAuth.
Advanced File Uploads: Robust file handling via a configurable
FileField, enabling seamless binary data validation and storage integration for bothPydanticandMarshmallowschemas.
User Guides¶
- Quick Start!
- Feature Tour
- Introduction
- Installation
- Background Tasks
- Error Handling
- File Uploads
- GraphQL
- Configuration
- SQLAlchemy Integration (Alchemical)
- CRUDMixin (Active Record Utilities)
- Transaction Decorator
- Request Validation
- Response Serialization
- Expected Responses
- Webhooks
- Grouping Request & Response Decorators
- Stateless Authentication
- Session Authentication
- OpenAPI Documentation
- Single-Page Web Apps
- Reading / Writing Cookies
- Using Cookie-Based Sessions
- Using
before_request - WebSocket Support
- Application and Request State
- Dyne CLI
- Extending the Dyne CLI
- Using Requests Test Client
- HSTS (Redirect to HTTPS)
- CORS
- Trusted Hosts
- Deploying Dyne
- Building and Testing with Dyne
- MAINTAINERS