python-flashapi 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_flashapi-0.1.0/.github/workflows/ci.yml +33 -0
- python_flashapi-0.1.0/.gitignore +9 -0
- python_flashapi-0.1.0/CHANGELOG.md +24 -0
- python_flashapi-0.1.0/LICENSE +21 -0
- python_flashapi-0.1.0/PKG-INFO +259 -0
- python_flashapi-0.1.0/README.md +218 -0
- python_flashapi-0.1.0/docs/authentication.md +483 -0
- python_flashapi-0.1.0/docs/custom-logic.md +496 -0
- python_flashapi-0.1.0/docs/customization.md +295 -0
- python_flashapi-0.1.0/docs/examples.md +807 -0
- python_flashapi-0.1.0/docs/features.md +244 -0
- python_flashapi-0.1.0/docs/framework-notes.md +215 -0
- python_flashapi-0.1.0/docs/integration.md +504 -0
- python_flashapi-0.1.0/docs/logo.svg +25 -0
- python_flashapi-0.1.0/docs/logo1.svg +29 -0
- python_flashapi-0.1.0/docs/relations.md +207 -0
- python_flashapi-0.1.0/examples/fastapi_example.py +36 -0
- python_flashapi-0.1.0/examples/flask_example.py +33 -0
- python_flashapi-0.1.0/pyproject.toml +45 -0
- python_flashapi-0.1.0/src/flashapi/__init__.py +7 -0
- python_flashapi-0.1.0/src/flashapi/adapters/__init__.py +0 -0
- python_flashapi-0.1.0/src/flashapi/adapters/base.py +12 -0
- python_flashapi-0.1.0/src/flashapi/adapters/django.py +165 -0
- python_flashapi-0.1.0/src/flashapi/adapters/fastapi.py +293 -0
- python_flashapi-0.1.0/src/flashapi/adapters/flask.py +232 -0
- python_flashapi-0.1.0/src/flashapi/core/__init__.py +3 -0
- python_flashapi-0.1.0/src/flashapi/core/custom_routes.py +261 -0
- python_flashapi-0.1.0/src/flashapi/core/pluralize.py +80 -0
- python_flashapi-0.1.0/src/flashapi/core/relations.py +61 -0
- python_flashapi-0.1.0/src/flashapi/core/response.py +33 -0
- python_flashapi-0.1.0/src/flashapi/core/schema.py +83 -0
- python_flashapi-0.1.0/src/flashapi/django.py +5 -0
- python_flashapi-0.1.0/src/flashapi/docs/__init__.py +0 -0
- python_flashapi-0.1.0/src/flashapi/docs/openapi.py +223 -0
- python_flashapi-0.1.0/src/flashapi/fastapi.py +5 -0
- python_flashapi-0.1.0/src/flashapi/features/__init__.py +6 -0
- python_flashapi-0.1.0/src/flashapi/features/filtering.py +33 -0
- python_flashapi-0.1.0/src/flashapi/features/pagination.py +20 -0
- python_flashapi-0.1.0/src/flashapi/features/search.py +25 -0
- python_flashapi-0.1.0/src/flashapi/features/sorting.py +21 -0
- python_flashapi-0.1.0/src/flashapi/flask.py +5 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/__init__.py +3 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/base.py +11 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/dataclass.py +39 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/detect.py +48 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/django.py +83 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/pydantic.py +84 -0
- python_flashapi-0.1.0/src/flashapi/inspectors/sqlalchemy.py +75 -0
- python_flashapi-0.1.0/src/flashapi/py.typed +0 -0
- python_flashapi-0.1.0/src/flashapi/storage/__init__.py +4 -0
- python_flashapi-0.1.0/src/flashapi/storage/auto.py +106 -0
- python_flashapi-0.1.0/src/flashapi/storage/base.py +26 -0
- python_flashapi-0.1.0/src/flashapi/storage/orm.py +85 -0
- python_flashapi-0.1.0/src/flashapi/storage/sqlalchemy.py +137 -0
- python_flashapi-0.1.0/tests/__init__.py +0 -0
- python_flashapi-0.1.0/tests/test_adapters/__init__.py +0 -0
- python_flashapi-0.1.0/tests/test_adapters/test_fastapi.py +111 -0
- python_flashapi-0.1.0/tests/test_adapters/test_flask.py +90 -0
- python_flashapi-0.1.0/tests/test_adapters/test_relations.py +126 -0
- python_flashapi-0.1.0/tests/test_core/__init__.py +0 -0
- python_flashapi-0.1.0/tests/test_core/test_pluralize.py +52 -0
- python_flashapi-0.1.0/tests/test_core/test_response.py +65 -0
- python_flashapi-0.1.0/tests/test_core/test_schema.py +36 -0
- python_flashapi-0.1.0/tests/test_features/__init__.py +0 -0
- python_flashapi-0.1.0/tests/test_features/test_filtering.py +42 -0
- python_flashapi-0.1.0/tests/test_features/test_pagination.py +45 -0
- python_flashapi-0.1.0/tests/test_features/test_search.py +41 -0
- python_flashapi-0.1.0/tests/test_features/test_sorting.py +36 -0
- python_flashapi-0.1.0/tests/test_inspectors/__init__.py +0 -0
- python_flashapi-0.1.0/tests/test_inspectors/test_dataclass.py +64 -0
- python_flashapi-0.1.0/tests/test_inspectors/test_detect.py +37 -0
- python_flashapi-0.1.0/tests/test_inspectors/test_pydantic.py +69 -0
- python_flashapi-0.1.0/tests/test_storage/__init__.py +0 -0
- python_flashapi-0.1.0/tests/test_storage/test_auto.py +81 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[all,dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint with ruff
|
|
30
|
+
run: ruff check src/
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: pytest tests/ -v
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-07-09)
|
|
4
|
+
|
|
5
|
+
Initial release.
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
- Auto-generate REST API + CRUD from model definitions
|
|
9
|
+
- Framework support: FastAPI, Django, Flask
|
|
10
|
+
- Model support: Django ORM, SQLAlchemy, Pydantic, dataclass
|
|
11
|
+
- Pagination, filtering, sorting, full-text search
|
|
12
|
+
- Relation detection: nested routes and `?expand=`
|
|
13
|
+
- OpenAPI 3.1.0 schema generation + Swagger UI
|
|
14
|
+
- French + English pluralization
|
|
15
|
+
- `Model()` wrapper: readonly, exclude, only, plural
|
|
16
|
+
- `@api_doc()` decorator for custom routes in Swagger
|
|
17
|
+
- `engine=` parameter for SQLAlchemy database reuse
|
|
18
|
+
- Custom response formatter support
|
|
19
|
+
|
|
20
|
+
### Security
|
|
21
|
+
- SQL identifier validation (prevents injection via table/column names)
|
|
22
|
+
- Session rollback on SQLAlchemy errors
|
|
23
|
+
- Input validation for pagination parameters
|
|
24
|
+
- CSRF exempt on Django API views (documented behavior)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FlashAPI Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-flashapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Define your models. FlashAPI does the rest.
|
|
5
|
+
Project-URL: Homepage, https://github.com/flashapi/flashapi
|
|
6
|
+
Project-URL: Documentation, https://flashapi.dev
|
|
7
|
+
Project-URL: Repository, https://github.com/flashapi/flashapi
|
|
8
|
+
Author: FlashAPI Contributors
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,automatic,crud,django,fastapi,flask,rest
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Requires-Dist: django>=4.2; extra == 'all'
|
|
24
|
+
Requires-Dist: fastapi>=0.100.0; extra == 'all'
|
|
25
|
+
Requires-Dist: flask>=2.3.0; extra == 'all'
|
|
26
|
+
Requires-Dist: uvicorn>=0.20.0; extra == 'all'
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: httpx; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
32
|
+
Provides-Extra: django
|
|
33
|
+
Requires-Dist: django>=4.2; extra == 'django'
|
|
34
|
+
Provides-Extra: fastapi
|
|
35
|
+
Requires-Dist: fastapi>=0.100.0; extra == 'fastapi'
|
|
36
|
+
Requires-Dist: pydantic>=2.0; extra == 'fastapi'
|
|
37
|
+
Requires-Dist: uvicorn>=0.20.0; extra == 'fastapi'
|
|
38
|
+
Provides-Extra: flask
|
|
39
|
+
Requires-Dist: flask>=2.3.0; extra == 'flask'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
<img src="docs/logo.svg" alt="FlashAPI" width="400">
|
|
44
|
+
</p>
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
<strong>Define your models. FlashAPI does the rest.</strong>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<a href="https://pypi.org/project/flashapi/"><img src="https://img.shields.io/pypi/v/flashapi?color=blue" alt="PyPI version"></a>
|
|
52
|
+
<a href="https://github.com/flashapi/flashapi/actions/workflows/ci.yml"><img src="https://github.com/flashapi/flashapi/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
53
|
+
<a href="https://pypi.org/project/flashapi/"><img src="https://img.shields.io/pypi/pyversions/flashapi" alt="Python versions"></a>
|
|
54
|
+
<a href="https://github.com/flashapi/flashapi/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License"></a>
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
<p align="center">
|
|
58
|
+
<a href="#installation">Installation</a> •
|
|
59
|
+
<a href="#quick-start">Quick Start</a> •
|
|
60
|
+
<a href="docs/integration.md">Docs</a> •
|
|
61
|
+
<a href="CHANGELOG.md">Changelog</a>
|
|
62
|
+
</p>
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
FlashAPI generates a full REST API with CRUD, pagination, filtering, sorting, full-text search, relations, and interactive documentation from your existing models — in one line.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
| Doc | Description |
|
|
73
|
+
|-----|-------------|
|
|
74
|
+
| **[Integration Guide](docs/integration.md)** | Where to put FlashAPI in your project, new vs existing project, all 3 frameworks |
|
|
75
|
+
| **[Features](docs/features.md)** | CRUD, pagination, filtering, sorting, search — detailed usage |
|
|
76
|
+
| **[Relations](docs/relations.md)** | Nested routes, expand, how relations are detected |
|
|
77
|
+
| **[Customization](docs/customization.md)** | Model wrapper, readonly, exclude, only, plural, response format, database |
|
|
78
|
+
| **[Authentication](docs/authentication.md)** | How to protect endpoints (Django middleware, FastAPI deps, Flask before_request) |
|
|
79
|
+
| **[Custom Logic](docs/custom-logic.md)** | How FlashAPI coexists with your business logic, when to use what |
|
|
80
|
+
| **[Framework Notes](docs/framework-notes.md)** | Django, FastAPI, Flask specifics (serialization, URLs, field behavior) |
|
|
81
|
+
| **[Full Examples](docs/examples.md)** | E-commerce, school, restaurant, blog, SaaS, minimal todo |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install flashapi[fastapi] # or flashapi[django] or flashapi[flask] or flashapi[all]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Quick Start
|
|
94
|
+
|
|
95
|
+
### FastAPI (new project)
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# main.py
|
|
99
|
+
from pydantic import BaseModel
|
|
100
|
+
from flashapi.fastapi import FlashAPI
|
|
101
|
+
|
|
102
|
+
class Product(BaseModel):
|
|
103
|
+
name: str
|
|
104
|
+
price: float
|
|
105
|
+
in_stock: bool = True
|
|
106
|
+
|
|
107
|
+
app = FlashAPI(models=[Product]).app
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
uvicorn main:app --reload
|
|
112
|
+
# Open http://localhost:8000/docs
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### FastAPI (existing project)
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# main.py — you already have app = FastAPI(...)
|
|
119
|
+
from fastapi import FastAPI
|
|
120
|
+
from flashapi.fastapi import FlashAPI
|
|
121
|
+
from models import Product, Order
|
|
122
|
+
|
|
123
|
+
app = FastAPI(title="My App")
|
|
124
|
+
|
|
125
|
+
# Your existing routes stay untouched
|
|
126
|
+
@app.get("/health")
|
|
127
|
+
async def health():
|
|
128
|
+
return {"ok": True}
|
|
129
|
+
|
|
130
|
+
# Mount FlashAPI under /api
|
|
131
|
+
flash = FlashAPI(models=[Product, Order])
|
|
132
|
+
app.mount("/api", flash.app)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
See [Integration Guide](docs/integration.md) for all patterns (Option A/B/C).
|
|
136
|
+
|
|
137
|
+
### Django
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
# urls.py
|
|
141
|
+
from django.urls import path, include
|
|
142
|
+
from flashapi.django import generate_urls
|
|
143
|
+
from myapp.models import Product, Order, Customer
|
|
144
|
+
|
|
145
|
+
urlpatterns = [
|
|
146
|
+
path("admin/", admin.site.urls),
|
|
147
|
+
path("api/", include(generate_urls(models=[Product, Order, Customer]))),
|
|
148
|
+
]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Open `http://localhost:8000/api/docs/` for Swagger UI.
|
|
152
|
+
|
|
153
|
+
### Flask
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
# app.py
|
|
157
|
+
from flask import Flask
|
|
158
|
+
from flashapi.flask import register_models
|
|
159
|
+
from models import Product, Order
|
|
160
|
+
|
|
161
|
+
app = Flask(__name__)
|
|
162
|
+
register_models(app, models=[Product, Order])
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Open `http://localhost:5000/docs` for Swagger UI.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## What you get
|
|
170
|
+
|
|
171
|
+
For every model, FlashAPI generates:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
GET /{plural}/ → List (paginated, filterable, sortable, searchable)
|
|
175
|
+
POST /{plural}/ → Create
|
|
176
|
+
GET /{plural}/{id}/ → Read
|
|
177
|
+
PUT /{plural}/{id}/ → Update
|
|
178
|
+
DELETE /{plural}/{id}/ → Delete
|
|
179
|
+
GET /{parent}/{id}/{children}/ → Nested list (auto-detected relations)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Plus: `?expand=relation` to inline related objects, and Swagger UI docs.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Model support
|
|
187
|
+
|
|
188
|
+
| Type | Detection | Storage |
|
|
189
|
+
|------|-----------|---------|
|
|
190
|
+
| Django Model | `_meta` attribute | Django ORM (your DB) |
|
|
191
|
+
| SQLAlchemy | `__table__` attribute | Your SQLAlchemy engine |
|
|
192
|
+
| Pydantic | `model_fields` attribute | Auto SQLite |
|
|
193
|
+
| dataclass | `@dataclass` | Auto SQLite |
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Customization
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from flashapi import Model
|
|
201
|
+
|
|
202
|
+
FlashAPI(models=[
|
|
203
|
+
Product, # Full CRUD
|
|
204
|
+
Model(Order, exclude=["delete"]), # No delete
|
|
205
|
+
Model(Config, readonly=True), # GET only
|
|
206
|
+
Model(Log, only=["list"]), # List only
|
|
207
|
+
Model(Animal, plural="animaux"), # Custom plural
|
|
208
|
+
])
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
See [Customization docs](docs/customization.md) for all options.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Authentication
|
|
216
|
+
|
|
217
|
+
FlashAPI does NOT handle auth. You protect routes using your framework's standard mechanisms:
|
|
218
|
+
|
|
219
|
+
- **Django**: middleware ([example](docs/authentication.md#django-middleware))
|
|
220
|
+
- **FastAPI**: dependencies / middleware ([example](docs/authentication.md#fastapi-dependency-injection))
|
|
221
|
+
- **Flask**: `before_request` ([example](docs/authentication.md#flask-before_request))
|
|
222
|
+
|
|
223
|
+
See [Authentication docs](docs/authentication.md) for full examples including RBAC, JWT, API keys.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Custom business logic
|
|
228
|
+
|
|
229
|
+
FlashAPI does not interfere with your project. Add custom endpoints alongside:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
# FlashAPI handles CRUD
|
|
233
|
+
flash = FlashAPI(models=[Product, Order])
|
|
234
|
+
app = flash.app
|
|
235
|
+
|
|
236
|
+
# You handle business logic
|
|
237
|
+
@app.post("/checkout")
|
|
238
|
+
async def checkout(request):
|
|
239
|
+
# Payment, emails, inventory...
|
|
240
|
+
return {"order_id": 42}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
See [Custom Logic docs](docs/custom-logic.md) for patterns and decision guide.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Philosophy
|
|
248
|
+
|
|
249
|
+
- **FlashAPI handles CRUD, you handle business logic.** No black magic, no monkey-patching.
|
|
250
|
+
- **Zero intrusion.** Does not modify your models, migrations, or existing code.
|
|
251
|
+
- **Composable.** Use it for 2 models or 20. Mix with custom endpoints freely.
|
|
252
|
+
- **No opinion on auth.** Your project, your rules.
|
|
253
|
+
- **Framework-native.** Generates standard routes. No lock-in, no proprietary runtime.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/logo.svg" alt="FlashAPI" width="400">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>Define your models. FlashAPI does the rest.</strong>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://pypi.org/project/flashapi/"><img src="https://img.shields.io/pypi/v/flashapi?color=blue" alt="PyPI version"></a>
|
|
11
|
+
<a href="https://github.com/flashapi/flashapi/actions/workflows/ci.yml"><img src="https://github.com/flashapi/flashapi/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
12
|
+
<a href="https://pypi.org/project/flashapi/"><img src="https://img.shields.io/pypi/pyversions/flashapi" alt="Python versions"></a>
|
|
13
|
+
<a href="https://github.com/flashapi/flashapi/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License"></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="#installation">Installation</a> •
|
|
18
|
+
<a href="#quick-start">Quick Start</a> •
|
|
19
|
+
<a href="docs/integration.md">Docs</a> •
|
|
20
|
+
<a href="CHANGELOG.md">Changelog</a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
FlashAPI generates a full REST API with CRUD, pagination, filtering, sorting, full-text search, relations, and interactive documentation from your existing models — in one line.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
| Doc | Description |
|
|
32
|
+
|-----|-------------|
|
|
33
|
+
| **[Integration Guide](docs/integration.md)** | Where to put FlashAPI in your project, new vs existing project, all 3 frameworks |
|
|
34
|
+
| **[Features](docs/features.md)** | CRUD, pagination, filtering, sorting, search — detailed usage |
|
|
35
|
+
| **[Relations](docs/relations.md)** | Nested routes, expand, how relations are detected |
|
|
36
|
+
| **[Customization](docs/customization.md)** | Model wrapper, readonly, exclude, only, plural, response format, database |
|
|
37
|
+
| **[Authentication](docs/authentication.md)** | How to protect endpoints (Django middleware, FastAPI deps, Flask before_request) |
|
|
38
|
+
| **[Custom Logic](docs/custom-logic.md)** | How FlashAPI coexists with your business logic, when to use what |
|
|
39
|
+
| **[Framework Notes](docs/framework-notes.md)** | Django, FastAPI, Flask specifics (serialization, URLs, field behavior) |
|
|
40
|
+
| **[Full Examples](docs/examples.md)** | E-commerce, school, restaurant, blog, SaaS, minimal todo |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install flashapi[fastapi] # or flashapi[django] or flashapi[flask] or flashapi[all]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
### FastAPI (new project)
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
# main.py
|
|
58
|
+
from pydantic import BaseModel
|
|
59
|
+
from flashapi.fastapi import FlashAPI
|
|
60
|
+
|
|
61
|
+
class Product(BaseModel):
|
|
62
|
+
name: str
|
|
63
|
+
price: float
|
|
64
|
+
in_stock: bool = True
|
|
65
|
+
|
|
66
|
+
app = FlashAPI(models=[Product]).app
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
uvicorn main:app --reload
|
|
71
|
+
# Open http://localhost:8000/docs
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### FastAPI (existing project)
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# main.py — you already have app = FastAPI(...)
|
|
78
|
+
from fastapi import FastAPI
|
|
79
|
+
from flashapi.fastapi import FlashAPI
|
|
80
|
+
from models import Product, Order
|
|
81
|
+
|
|
82
|
+
app = FastAPI(title="My App")
|
|
83
|
+
|
|
84
|
+
# Your existing routes stay untouched
|
|
85
|
+
@app.get("/health")
|
|
86
|
+
async def health():
|
|
87
|
+
return {"ok": True}
|
|
88
|
+
|
|
89
|
+
# Mount FlashAPI under /api
|
|
90
|
+
flash = FlashAPI(models=[Product, Order])
|
|
91
|
+
app.mount("/api", flash.app)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
See [Integration Guide](docs/integration.md) for all patterns (Option A/B/C).
|
|
95
|
+
|
|
96
|
+
### Django
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
# urls.py
|
|
100
|
+
from django.urls import path, include
|
|
101
|
+
from flashapi.django import generate_urls
|
|
102
|
+
from myapp.models import Product, Order, Customer
|
|
103
|
+
|
|
104
|
+
urlpatterns = [
|
|
105
|
+
path("admin/", admin.site.urls),
|
|
106
|
+
path("api/", include(generate_urls(models=[Product, Order, Customer]))),
|
|
107
|
+
]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Open `http://localhost:8000/api/docs/` for Swagger UI.
|
|
111
|
+
|
|
112
|
+
### Flask
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
# app.py
|
|
116
|
+
from flask import Flask
|
|
117
|
+
from flashapi.flask import register_models
|
|
118
|
+
from models import Product, Order
|
|
119
|
+
|
|
120
|
+
app = Flask(__name__)
|
|
121
|
+
register_models(app, models=[Product, Order])
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Open `http://localhost:5000/docs` for Swagger UI.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## What you get
|
|
129
|
+
|
|
130
|
+
For every model, FlashAPI generates:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
GET /{plural}/ → List (paginated, filterable, sortable, searchable)
|
|
134
|
+
POST /{plural}/ → Create
|
|
135
|
+
GET /{plural}/{id}/ → Read
|
|
136
|
+
PUT /{plural}/{id}/ → Update
|
|
137
|
+
DELETE /{plural}/{id}/ → Delete
|
|
138
|
+
GET /{parent}/{id}/{children}/ → Nested list (auto-detected relations)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Plus: `?expand=relation` to inline related objects, and Swagger UI docs.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Model support
|
|
146
|
+
|
|
147
|
+
| Type | Detection | Storage |
|
|
148
|
+
|------|-----------|---------|
|
|
149
|
+
| Django Model | `_meta` attribute | Django ORM (your DB) |
|
|
150
|
+
| SQLAlchemy | `__table__` attribute | Your SQLAlchemy engine |
|
|
151
|
+
| Pydantic | `model_fields` attribute | Auto SQLite |
|
|
152
|
+
| dataclass | `@dataclass` | Auto SQLite |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Customization
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from flashapi import Model
|
|
160
|
+
|
|
161
|
+
FlashAPI(models=[
|
|
162
|
+
Product, # Full CRUD
|
|
163
|
+
Model(Order, exclude=["delete"]), # No delete
|
|
164
|
+
Model(Config, readonly=True), # GET only
|
|
165
|
+
Model(Log, only=["list"]), # List only
|
|
166
|
+
Model(Animal, plural="animaux"), # Custom plural
|
|
167
|
+
])
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
See [Customization docs](docs/customization.md) for all options.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Authentication
|
|
175
|
+
|
|
176
|
+
FlashAPI does NOT handle auth. You protect routes using your framework's standard mechanisms:
|
|
177
|
+
|
|
178
|
+
- **Django**: middleware ([example](docs/authentication.md#django-middleware))
|
|
179
|
+
- **FastAPI**: dependencies / middleware ([example](docs/authentication.md#fastapi-dependency-injection))
|
|
180
|
+
- **Flask**: `before_request` ([example](docs/authentication.md#flask-before_request))
|
|
181
|
+
|
|
182
|
+
See [Authentication docs](docs/authentication.md) for full examples including RBAC, JWT, API keys.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Custom business logic
|
|
187
|
+
|
|
188
|
+
FlashAPI does not interfere with your project. Add custom endpoints alongside:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# FlashAPI handles CRUD
|
|
192
|
+
flash = FlashAPI(models=[Product, Order])
|
|
193
|
+
app = flash.app
|
|
194
|
+
|
|
195
|
+
# You handle business logic
|
|
196
|
+
@app.post("/checkout")
|
|
197
|
+
async def checkout(request):
|
|
198
|
+
# Payment, emails, inventory...
|
|
199
|
+
return {"order_id": 42}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
See [Custom Logic docs](docs/custom-logic.md) for patterns and decision guide.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Philosophy
|
|
207
|
+
|
|
208
|
+
- **FlashAPI handles CRUD, you handle business logic.** No black magic, no monkey-patching.
|
|
209
|
+
- **Zero intrusion.** Does not modify your models, migrations, or existing code.
|
|
210
|
+
- **Composable.** Use it for 2 models or 20. Mix with custom endpoints freely.
|
|
211
|
+
- **No opinion on auth.** Your project, your rules.
|
|
212
|
+
- **Framework-native.** Generates standard routes. No lock-in, no proprietary runtime.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## License
|
|
217
|
+
|
|
218
|
+
MIT
|