Generate full CRUD REST endpoints for FastAPI straight from your ORM models — filtering, sorting, pagination and nested resources, without hand-writing a single schema. Works with SQLModel, SQLAlchemy and Tortoise ORM.
Project description
fastapi-crud-generator
CRUD route generator for FastAPI. Point it at an ORM model and get a full set of endpoints — with filtering, sorting, pagination, and nested resources — without writing a single Pydantic schema by hand.
Works with SQLModel, SQLAlchemy, and Tortoise ORM.
What it does
- Auto schemas — public, create, and update schemas are derived from the ORM model automatically
- Filtering — every scalar field becomes a query parameter:
?status=published&author_id=5 - Sorting —
?sort=created_at:descor multiple:?sort=published:desc&sort=title:asc - Pagination —
?page=2&per_page=20, response always includes totalcount - Nested resources —
/threads/{thread_id}/posts/{post_id}in three lines - Related data — fetch relations in one request via
?include=author&include=tags - Customizable — disable any endpoint, override any handler, replace any schema
Quick start
from fastapi import FastAPI
from fastapi_crud_generator import CRUDCollection
from fastapi_crud_generator.orm.sqlmodel import SQLModelAdapter
app = FastAPI()
crud = CRUDCollection(orm_adapter=SQLModelAdapter(model=Article, get_session=get_session))
app.include_router(crud.get_router(prefix="/articles", tags=["articles"]))
This registers five endpoints:
GET /articles # list: filtering, sorting, pagination
GET /articles/{article_id} # get one
POST /articles # create
PATCH /articles/{article_id} # partial update
DELETE /articles/{article_id} # delete
Request and response schemas are generated from the Article model automatically —
no ArticleCreate, ArticleUpdate, or ArticlePublic classes needed.
Nested resources
thread_crud = CRUDCollection(orm_adapter=SQLModelAdapter(model=Thread, get_session=get_session))
post_crud = CRUDCollection(orm_adapter=SQLModelAdapter(model=Post, get_session=get_session))
thread_crud.add_nested_collection("/posts", post_crud)
app.include_router(thread_crud.get_router(prefix="/threads"))
This gives you the full hierarchy:
GET /threads
GET /threads/{thread_id}
POST /threads
PATCH /threads/{thread_id}
DELETE /threads/{thread_id}
GET /threads/{thread_id}/posts
GET /threads/{thread_id}/posts/{post_id}
POST /threads/{thread_id}/posts
PATCH /threads/{thread_id}/posts/{post_id}
DELETE /threads/{thread_id}/posts/{post_id}
Filtering, sorting, and pagination work on nested routes too. Post queries are automatically scoped to the parent thread.
Installation
If SQLModel, SQLAlchemy, or Tortoise is already in your project:
pip install fastapi-crud-generator
To install an ORM together with the package:
pip install "fastapi-crud-generator[sqlmodel]"
pip install "fastapi-crud-generator[sqlalchemy]"
pip install "fastapi-crud-generator[tortoise]"
Documentation
mozgsml.github.io/fastapi_crud_generator
License
MIT
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 fastapi_crud_generator-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_crud_generator-0.1.0.tar.gz
- Upload date:
- Size: 122.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b67ed044456d9904b02520407c3f1d4b8f41473505bf3d9324ded9c42426f4d
|
|
| MD5 |
115d8cfc162ddfc2c194a2967ba6f10d
|
|
| BLAKE2b-256 |
2488461605d9566139169322ceefd3abe000fa79ede8ba476b914cfe65d09d37
|
Provenance
The following attestation bundles were made for fastapi_crud_generator-0.1.0.tar.gz:
Publisher:
release.yml on mozgsml/fastapi_crud_generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_crud_generator-0.1.0.tar.gz -
Subject digest:
0b67ed044456d9904b02520407c3f1d4b8f41473505bf3d9324ded9c42426f4d - Sigstore transparency entry: 2235456133
- Sigstore integration time:
-
Permalink:
mozgsml/fastapi_crud_generator@e2b00953d0b5c72d53a571946ae5d17e2869cdcc -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mozgsml
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e2b00953d0b5c72d53a571946ae5d17e2869cdcc -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_crud_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_crud_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac26bd8279c054f8b041f46879f3fc0e2a7fa0887660d15b9838a6c2d3729c82
|
|
| MD5 |
bdf469a5cfd7761117ff979012a195c8
|
|
| BLAKE2b-256 |
b2f3f2c1355022931d7f073be51b2c2a5b21dfddb832d958d80e280dc32701ef
|
Provenance
The following attestation bundles were made for fastapi_crud_generator-0.1.0-py3-none-any.whl:
Publisher:
release.yml on mozgsml/fastapi_crud_generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_crud_generator-0.1.0-py3-none-any.whl -
Subject digest:
ac26bd8279c054f8b041f46879f3fc0e2a7fa0887660d15b9838a6c2d3729c82 - Sigstore transparency entry: 2235456197
- Sigstore integration time:
-
Permalink:
mozgsml/fastapi_crud_generator@e2b00953d0b5c72d53a571946ae5d17e2869cdcc -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mozgsml
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e2b00953d0b5c72d53a571946ae5d17e2869cdcc -
Trigger Event:
push
-
Statement type: