Logo Django Bolt

Django Bolt

Tổ chức
CodeAtCode
django-bolt

Use when building high-performance APIs with django-bolt - routing, JWT auth, msgspec serializers, WebSockets, SSE streaming, file uploads, ORM patterns, runbolt deployment, or migrating from DRF

Tổng quan

Nhà phát hànhCodeAtCode
Kho mãoss-ai-skills
Tên kỹ năngdjango-bolt
Sao
30
Bản fork
3
Tệp đi kèm
6
Giấy phépGPL-3.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 6 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được CodeAtCode công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Django Bolt trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/CodeAtCode/oss-ai-skills/tree/master/frameworks/django-bolt
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/CodeAtCode/oss-ai-skills.git /tmp/oss-ai-skills
mkdir -p .claude/skills
cp -r /tmp/oss-ai-skills/frameworks/django-bolt .claude/skills/django-bolt
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Django Bolt trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Django Bolt ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Django Bolt không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Objective: Use this skill to prevent async ORM blocking, WebSocket resource leaks, and performance regressions in Django Bolt APIs by enforcing async query patterns, connection lifecycle management, and msgspec serializer discipline.

Django Bolt

Django Bolt is a high-performance Django framework that bypasses the Python GIL using Rust, delivering 300k+ RPS for simple endpoints.

Overview

Django Bolt combines Django's ORM and ecosystem with Rust's performance. Built on top of:

  • Hyper (Rust HTTP server)
  • Tokio (async runtime)
  • msgspec (5-10x faster than Pydantic)

Key features:

  • Async ORM - Use aget(), alist(), acreate() because sync ORM in async handlers blocks the event loop
  • Built-in WebSocket - Real-time communication without channels (no django-channels complexity)
  • SSE Streaming - Server-Sent Events for live updates because polling wastes resources
  • JWT Authentication - Built-in auth with refresh token rotation to prevent token replay attacks
  • msgspec Serializers - Fast schema validation and serialization because Pydantic adds 5-10x overhead
  • OpenAPI Docs - Auto-generated at /docs for API discoverability

Installation

bash
pip install django-bolt

Add to INSTALLED_APPS:

python
INSTALLED_APPS = [
    ...
    "django_bolt",
]

Quick Start

python
# myapp/api.py
from django_bolt import BoltAPI

api = BoltAPI()

@api.get("/")
async def hello():
    return {"message": "Hello, World!"}

@api.get("/users")
async def list_users():
    users = await User.objects.all()
    return [{"id": u.id, "username": u.username} for u in users]

Mount in urls.py:

python
# myproject/urls.py
from django.urls import path
from myapp.api import api

urlpatterns = [
    path("api/", api.urls),
]

Run:

bash
python manage.py runbolt --dev

Routing

Basic Routes

python
@api.get("/users")
@api.post("/users")
@api.put("/users/{pk}")
@api.delete("/users/{pk}")
@api.patch("/users/{pk}")

Path Parameters

python
@api.get("/users/{user_id}")
async def get_user(user_id: int):
    user = await User.objects.aget(id=user_id)
    return {"id": user.id, "username": user.username}

Query Parameters

python
@api.get("/users")
async def list_users(page: int = 1, limit: int = 10):
    users = await User.objects.all()[limit*(page-1):limit*page]
    return [{"id": u.id} for u in users]

Request Body

python
import msgspec

class UserCreate(msgspec.Struct):
    username: str
    email: str

@api.post("/users")
async def create_user(data: UserCreate):
    user = await User.objects.acreate(username=data.username, email=data.email)
    return {"id": user.id}, 201

Middleware

python
from django_bolt.middleware import CompressionMiddleware

api.add_middleware(CompressionMiddleware())

Class-Based Views

ViewSet

python
from django_bolt.views import ViewSet, route

class UserViewSet(ViewSet):
    @route.get("/users")
    async def list(self, request):
        users = await User.objects.alist()
        return {"users": [{"id": u.id, "username": u.username} for u in users]}

    @route.get("/users/{pk}")
    async def retrieve(self, request, pk: int):
        user = await User.objects.aget(id=pk)
        return {"id": user.id, "username": user.username}

    @route.post("/users")
    async def create(self, request):
        data = await request.json()
        user = await User.objects.acreate(**data)
        return {"id": user.id}

    @route.put("/users/{pk}")
    async def update(self, request, pk: int):
        data = await request.json()
        user = await User.objects.aget(id=pk)
        for k, v in data.items():
            setattr(user, k, v)
        await user.asave()
        return {"id": user.id}

    @route.delete("/users/{pk}")
    async def destroy(self, request, pk: int):
        user = await User.objects.aget(id=pk)
        await user.adelete()
        return {"deleted": True}

api.register_viewset(UserViewSet, prefix="/api")

ModelViewSet

python
from django_bolt.views import ModelViewSet
from django.contrib.auth import get_user_model
from django_bolt.serializers import ModelSerializer

User = get_user_model()

class UserSerializer(ModelSerializer):
    class Meta:
        model = User
        fields = ["id", "username", "email"]

class UserModelViewSet(ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

api.register_viewset(UserModelViewSet, prefix="/api")

OpenAPI / API Documentation

Django Bolt auto-generates OpenAPI 3.1 documentation.

Access Docs

  • Swagger: /docs
  • ReDoc: /redoc
  • Scalar: /scalar
  • RapidDoc: /rapiddoc

Configure OpenAPI

python
from django_bolt import BoltAPI
from django_bolt.openapi import OpenAPIInfo

api = BoltAPI(
    info=OpenAPIInfo(
        title="My API",
        version="1.0.0",
        description="API description",
    )
)

Include/Exclude from Schema (v0.10.2+/0.11.0+)

python
@api.get("/internal", include_in_schema=False)
async def internal_handler():
    return {"secret": True}

Testing

Test Client

python
from django_bolt.test import AsyncAPITestClient

class UserAPITest(AsyncAPITestClient):
    async def test_create_user(self):
        response = await self.post(
            "/api/users",
            json={"username": "testuser", "email": "test@example.com"}
        )
        self.assertEqual(response.status_code, 201)
        data = await response.json()
        self.assertEqual(data["username"], "testuser")

    async def test_get_user(self):
        user = await User.objects.acreate(username="testuser", email="test@example.com")
        response = await self.get(f"/api/users/{user.id}")
        self.assertEqual(response.status_code, 200)

Note: TestClient shares DB connection with handler threads for accurate concurrency testing.


Performance Benchmarks

Reference Setup

  • Hardware: AMD Ryzen 5 5600G (6 cores / 12 threads), 16 GB RAM, Linux
  • Server: python manage.py runbolt --processes 8 (8 processes × 1 Actix worker)
  • Load generator: bombardier, C=100, N=100000, loopback on same machine
  • Baseline comparisons: Plain Django views, DRF, FastAPI, Litestar, JavaScript runtimes (see sources)
  • Run-to-run variance: ±5% (gaps under ~10% are ties)

Important: The load generator shares the 12 cores with the 8 server processes, so numbers are a floor, not a ceiling. Absolute numbers are hardware-specific—always publish the conditions with the number.

Key Results

Endpoint TypeReq/sWhat it measures
JSON hello-world (GET /)311,270Routing + JSON serialization overhead
10 KB JSON (sync handler)187,186Response serialization bottleneck
10 KB JSON (async handler)184,059Async overhead negligible at scale
10-row ORM query (SQLite)20,963–26,694Django ORM executor + SQLite file lock
JWT auth + DB load user40,312Rust JWT verify + ORM user fetch
Full middleware stack8,744Sessions, CSRF, auth, messages, CSP

What These Numbers Do NOT Tell You

  • Not per-request latency figures — p50/p99 are available for select endpoints but these RPS numbers measure throughput under load
  • Excludes database time for ORM benchmarks — measured with SQLite (single-writer file lock is the bottleneck); PostgreSQL uses more threads
  • Does not include network latency — loopback test on same machine
  • Not a measure of developer productivity — pure throughput comparison

Cross-Framework Comparison (same machine, one process each, PostgreSQL)

Source: https://github.com/FarhanAliRaza/python-api-frameworks-benchmark (2026-08-30)

EndpointDjango-BoltLitestar + uvicornFastAPI + uvicorn
1 KB JSON43,54115,4777,517
10 KB JSON27,61012,9251,805
10 rows from PostgreSQL2,8811,3211,237
JWT auth + load user4,4781,155941

Reproduce

bash
git clone https://github.com/dj-bolt/django-bolt.git && cd django-bolt
uv sync && just build
go install github.com/codesenberg/bombardier@latest
just save-bench  # → python/benchmark/BENCHMARK.md

Source: https://bolt.farhana.li/benchmarks/ | https://github.com/dj-bolt/django-bolt/blob/master/python/benchmark/BENCHMARK.md


Configuration

Settings

python
# settings.py

# Django-Bolt Configuration
BOLT = {
    "HOST": "0.0.0.0",
    "PORT": 8000,
    "PROCESSES": 4,
    "BACKLOG": 2048,
    "KEEP_ALIVE": 30,
    "DEBUG": False,
    "EMIT_SIGNALS": False,
}

# JWT Configuration
JWT_SECRET_KEY = "your-secret-key"
JWT_ALGORITHM = "HS256"
JWT_EXPIRATION = 3600

# File Upload Settings
from django_bolt import FileSize
BOLT_MAX_UPLOAD_SIZE = FileSize.MB_50
BOLT_MEMORY_SPOOL_THRESHOLD = 5 * 1024 * 1024

# CORS Configuration
BOLT_CORS = {
    "allow_origins": ["https://example.com"],
    "allow_methods": ["GET", "POST", "PUT", "DELETE"],
    "allow_headers": ["*"],
    "allow_credentials": True,
}

Production Server: runbolt

Worker Recycling (v0.11.0+)

bash
# Recycle workers after memory threshold
python manage.py runbolt --max-rss 512000

# Limit worker lifetime
python manage.py runbolt --workers-lifetime 3600

# Auto-respawn failed workers
python manage.py runbolt --respawn-failed-workers

Development Mode (v0.11.0+)

bash
# Native Rust reloader
python manage.py runbolt --dev

# Custom reload directory
python manage.py runbolt --dev --reload-dir src/

Best Practices

Performance

  1. Use async ORM methods - Always use aget(), alist(), acreate() in handlers
  2. Avoid N+1 queries - Use select_related() for ForeignKey, prefetch_related() for ManyToMany
  3. Enable compression - Use CompressionMiddleware for responses > 500 bytes
  4. Tune process count - Set --processes to CPU core count for CPU-bound workloads

Security

  1. Always validate input - Use msgspec structs for request body validation
  2. Use HTTPS in production - Terminate TLS at nginx/load balancer
  3. Configure BOLT_TRUSTED_PROXIES - Required behind reverse proxies for accurate rate limiting
  4. Rotate JWT secrets - Implement key rotation for long-lived deployments

Maintainability

  1. Organize by feature - Group related endpoints in feature modules
  2. Use dependency injection - Extract reusable logic with Depends()
  3. Write tests - Use AsyncAPITestClient for integration tests
  4. Document APIs - Leverage auto-generated OpenAPI docs at /docs

Command-Line Reference

bash
# Development server with native Rust reloader
python manage.py runbolt --dev

# Production with custom settings
python manage.py runbolt --host 0.0.0.0 --port 8000 --processes 4

# Worker recycling
python manage.py runbolt --max-rss 512000 --workers-lifetime 3600

# Increase socket backlog
python manage.py runbolt --processes 4 --backlog 2048

# Adjust keep-alive timeout
python manage.py runbolt --processes 4 --keep-alive 30

# Skip startup checks
python manage.py runbolt --skip-checks

Version Migration Gates

VersionBreaking ChangeBefore / After
v0.4.0Python 3.12+ requiredRequires upgrading runtime; no code changes
v0.6.0SessionAuthentication removedBefore:from django_bolt.auth import SessionAuthenticationapi = BoltAPI(auth=[SessionAuthentication()])After:Use JWTAuthentication or APIKeyBearer
v0.10.0Cookie-JWT CSRF check ON by defaultBefore:JWTAuthentication(cookie=True)(no CSRF check for API clients)After:JWTAuthentication(cookie=False)for non-browser clients
v0.10.3BOLT_TRUSTED_PROXIES required behind proxiesBefore:(rate limiting shared across all callers behind proxy)After:BOLT_TRUSTED_PROXIES = ["10.0.0.0/8", "192.168.0.0/16"]in settings.py
v0.11.0Nested() removed — use plain type hintsBefore:author: Nested(AuthorSerializer)After:author: AuthorSerializer

References


Deep Dives

The following reference files contain detailed coverage of advanced topics. Load them on demand when working on specific features:

  1. auth-security.md — Authentication, Permissions & Guards, Middleware, Rate Limiting, Error Handling
  2. responses-serialization.md — Responses, msgspec Serializers, Pagination, Request Object, Dependency Injection
  3. websockets-uploads.md — WebSockets, File Uploads
  4. orm-background.md — Django ORM Patterns, Background Tasks
  5. deployment.md — Deployment, MCP Servers
  6. drf-migration.md — Comparison with DRF/Django Ninja, Migration from DRF

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Django Bolt làm được gì?

Use when building high-performance APIs with django-bolt - routing, JWT auth, msgspec serializers, WebSockets, SSE streaming, file uploads, ORM patterns, runbolt deployment, or migrating from DRF

Vì sao nên dùng Django Bolt trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Django Bolt là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Django Bolt trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/CodeAtCode/oss-ai-skills/tree/master/frameworks/django-bolt. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Django Bolt?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Django Bolt với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Django Bolt với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Django Bolt có miễn phí không?

Có. Kỹ năng này được CodeAtCode phát hành trên GitHub theo giấy phép GPL-3.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇