自動產生 CRUD API 的 Python 函式庫
Project description
AutoCRUD
✨ Features
- 🧠 Focus only on business and models: Developers only need to focus on business logic and domain model schema; metadata, indexing, events, permissions, and other foundational capabilities are automatically handled by the framework.
- ⚙️ Automated FastAPI: Apply a model with one line of code to automatically generate CRUD routes and OpenAPI/Swagger—zero boilerplate, zero manual binding.
- 🗂️ Versioning: Native support for full revision history, draft in-place editing, revision switching and restore—ideal for auditing, rollback, and draft workflows.
- 🔧 Highly customizable: Flexible route naming, indexed fields, event handlers, and permission checks.
- 🏎️ High performance: Built on FastAPI + msgspec for low latency and high throughput.
🧙 Starter Wizard
Use the interactive Starter Wizard to generate a ready-to-run AutoCRUD project with your models, storage, and permissions configured — no boilerplate needed.
👉 https://hychou0515.github.io/autocrud/wizard/
Feature Overview
| Feature | Description |
|---|---|
| ✅ Auto-generation (Schema → API/Storage) | Schema as Infrastructure: automatically generates routes, logic bindings, and storage mappings |
| ✅ Versioning (Revision History) | Draft→Update / Stable→Append, complete parent revision chain |
| ✅ Migration | Functional Converter, Lazy Upgrade on Read + Save |
| ✅ Storage Architecture | Hybrid: Meta (SQL/Redis) + Payload (Object Store) + Blob |
| ✅ Scalability | Object Storage with decoupled indexing for horizontal scaling |
| ✅ Partial Update (PATCH) | Precise JSON Patch updates for speed and bandwidth efficiency |
| ✅ Partial Read | Skip unnecessary fields at msgspec decode time for speed and bandwidth efficiency |
| ✅ GraphQL Integration | Auto-generated Strawberry GraphQL Endpoint |
| ✅ Blob Optimization | BlobStore deduplication and lazy loading |
| ✅ Permissions | Three-tier RBAC (Global / Model / Resource) and custom checkers |
| ✅ Event Hooks | Customizable Before / After / OnSuccess / OnError for every operation |
| ✅ Route Templates | Standard CRUD plus plug-in custom endpoints |
| ✅ Search & Index | Meta Store provides efficient filtering, sorting, pagination, and complex queries |
| ✅ Audit / Logging | Post-event audit records and review workflows |
| ✅ Message Queue | Built-in async job processing; manage Jobs as resources with versioning and states |
Installation
pip install autocrud
Optional Dependencies
For S3 storage support:
pip install "autocrud[s3]"
For BlobStore automatic Content-Type detection:
pip install "autocrud[magic]"
autocrud[magic] depends on python-magic.
- Linux: Ensure
libmagicis installed (e.g., on Ubuntu runsudo apt-get install libmagic1). - Other OS: See the python-magic installation guide.
Documentation
https://hychou0515.github.io/autocrud/
Your First API
from datetime import datetime, timedelta
from fastapi import FastAPI
from fastapi.testclient import TestClient
from autocrud import AutoCRUD
from msgspec import Struct
class TodoItem(Struct):
title: str
completed: bool
due: datetime
class TodoList(Struct):
items: list[TodoItem]
notes: str
# Create AutoCRUD
crud = AutoCRUD()
crud.add_model(TodoItem)
crud.add_model(TodoList)
app = FastAPI()
crud.apply(app)
crud.openapi(app)
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info")
Auto-generated CRUD Endpoints
POST /todo-item- CreateGET /todo-item/{id}/data- ReadPATCH /todo-item/{id}- JSON Patch updateDELETE /todo-item/{id}- Soft deleteGET /todo-list/data- List with search support- A dozen more auto endpoints
➡️ AutoCRUD User Guide
Operate Resources via ResourceManager
ResourceManager is the entry point for resource operations in AutoCRUD. It manages create, query, update, delete, and versioning of resources.
Its core is versioning: every create/update/patch generates a new revision_id (create new revision) and preserves full history; drafts (draft) can be repeatedly edited with modify (in-place, without creating a new revision), then switched to stable when confirmed. You can also list all revisions, read any revision, switch the current revision, or restore after a soft delete. Indexed queries support filtering, sorting, and pagination by metadata and data fields (indexed fields), making it ideal for auditing, rollback, and large-scale retrieval.
➡️ ResourceManager Guide
🚀 Quick Start
from datetime import datetime, timedelta
from fastapi import FastAPI
from fastapi.testclient import TestClient
from autocrud import AutoCRUD
from msgspec import Struct
class TodoItem(Struct):
title: str
completed: bool
due: datetime
class TodoList(Struct):
items: list[TodoItem]
notes: str
# Create CRUD API
crud = AutoCRUD()
crud.add_model(TodoItem)
crud.add_model(TodoList)
app = FastAPI()
crud.apply(app)
# Test
client = TestClient(app)
resp = client.post("/todo-list", json={"items": [], "notes": "My todos"})
todo_id = resp.json()["resource_id"]
# Add an item using JSON Patch
client.patch(f"/todo-list/{todo_id}", json=[{
"op": "add",
"path": "/items/-",
"value": {
"title": "Complete item",
"completed": False,
"due": (datetime.now() + timedelta(hours=1)).isoformat()
}
}])
# Get the result
result = client.get(f"/todo-list/{todo_id}/data")
print(result.json())
Start the development server:
python -m fastapi dev main.py
Visit http://localhost:8000/docs to view the auto-generated API documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autocrud-0.8.2.tar.gz.
File metadata
- Download URL: autocrud-0.8.2.tar.gz
- Upload date:
- Size: 155.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7f06526f541d82346683c86c169b613e5cef640b8c21c7bcc16810aa503b2db
|
|
| MD5 |
64162c5ba6790a1bbb120f1a1ca15d92
|
|
| BLAKE2b-256 |
37a26952899215b420e5f09592e6140b04af4299d58e4ec75c8132d62e5c2617
|
File details
Details for the file autocrud-0.8.2-py3-none-any.whl.
File metadata
- Download URL: autocrud-0.8.2-py3-none-any.whl
- Upload date:
- Size: 193.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5f88a146b0f476dc49b368806c8ea1001225a8729f3a04790063cf8b8ed561b
|
|
| MD5 |
4d2bee5d326e77aebb0c2a5cef0d3367
|
|
| BLAKE2b-256 |
42b9db377fa27e36abcc6193c95967ebb03289dbb40e376851d74138826c31e9
|