Metadata-Version: 2.4
Name: fastapi-crud-generator
Version: 0.1.0
Summary: 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-URL: Homepage, https://github.com/mozgsml/fastapi_crud_generator
Project-URL: Repository, https://github.com/mozgsml/fastapi_crud_generator
Project-URL: Issues, https://github.com/mozgsml/fastapi_crud_generator/issues
Author-email: Nikolai Lukianov <laserwargpt@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2026 Nikolai Lukianov
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
License-File: LICENSE.txt
Keywords: api,crud,fastapi,rest,sqlalchemy,sqlmodel,tortoise
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: fastapi
Requires-Dist: pydantic
Provides-Extra: sqlalchemy
Requires-Dist: sqlalchemy[asyncio]; extra == 'sqlalchemy'
Provides-Extra: sqlmodel
Requires-Dist: sqlmodel; extra == 'sqlmodel'
Provides-Extra: tortoise
Requires-Dist: tortoise-orm>=1.1.7; extra == 'tortoise'
Description-Content-Type: text/markdown

# fastapi-crud-generator

[![Tests](https://github.com/mozgsml/fastapi_crud_generator/actions/workflows/tests.yml/badge.svg)](https://github.com/mozgsml/fastapi_crud_generator/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/fastapi-crud-generator)](https://pypi.org/project/fastapi-crud-generator/)
[![Python](https://img.shields.io/pypi/pyversions/fastapi-crud-generator)](https://pypi.org/project/fastapi-crud-generator/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.txt)

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:desc` or multiple: `?sort=published:desc&sort=title:asc`
- **Pagination** — `?page=2&per_page=20`, response always includes total `count`
- **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

```python
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

```python
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:

```bash
pip install fastapi-crud-generator
```

To install an ORM together with the package:

```bash
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](https://mozgsml.github.io/fastapi_crud_generator)**

## License

MIT
