lightapi 0.1.5__tar.gz → 0.1.6__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.
- lightapi-0.1.6/PKG-INFO +214 -0
- lightapi-0.1.6/README.md +162 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/pyproject.toml +1 -1
- lightapi-0.1.5/PKG-INFO +0 -273
- lightapi-0.1.5/README.md +0 -221
- {lightapi-0.1.5 → lightapi-0.1.6}/.github/workflows/pages-publish.yml +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/.github/workflows/python-publish.yml +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/.github/workflows/test-dev.yml +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/.gitignore +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/LICENSE +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/authentication.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/caching.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/filtering.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/middleware.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/pagination.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/advanced/validation.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/auth.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/cache.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/core.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/database.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/exceptions.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/filters.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/index.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/models.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/pagination.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/rest.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/swagger.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/api-reference/validation.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/deployment/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/deployment/docker.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/deployment/production.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/deployment/security.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/auth.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/basic-crud.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/basic-rest.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/caching.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/custom-application.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/filtering-pagination.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/middleware.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/examples/validation.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/getting-started/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/getting-started/configuration.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/getting-started/first-steps.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/getting-started/installation.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/getting-started/introduction.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/getting-started/quickstart.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/index.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/cache.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/core-api.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/endpoints.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/handlers.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/middleware.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/technical-reference/models.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/troubleshooting.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/tutorial/.pages +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/tutorial/basic-api.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/tutorial/database.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/tutorial/endpoints.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/tutorial/requests.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/docs/tutorial/responses.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/README.md +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/__init__.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/auth_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/basic_rest_api.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/caching_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/custom_snippet.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/filtering_pagination_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/middleware_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/relationships_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/swagger_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/user_goal_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/examples/validation_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/__init__.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/auth.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/base_endpoint.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/cache.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/config.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/core.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/database.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/exceptions.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/filters.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/handlers.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/lightapi.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/models.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/pagination.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/rest.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/lightapi/swagger.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/mkdocs.yml +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/pytest.ini +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/requirements.txt +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/run_server.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/__init__.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/conftest.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_additional_features.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_auth.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_auth_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_basic_rest_api.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_cache.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_caching_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_clients.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_core.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_custom_snippet.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_filtering_pagination_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_filters.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_from_config.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_helpers.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_integration.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_middleware.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_middleware_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_pagination.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_rest.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_swagger.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/tests/test_validation_example.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/update_version.py +0 -0
- {lightapi-0.1.5 → lightapi-0.1.6}/uv.lock +0 -0
lightapi-0.1.6/PKG-INFO
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightapi
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: A lightweight framework for building API endpoints using Python's native libraries.
|
|
5
|
+
Project-URL: Repository, https://github.com/henriqueblobato/LightApi
|
|
6
|
+
Project-URL: Issues, https://github.com/henriqueblobato/LightApi/issues
|
|
7
|
+
Project-URL: Homepage, https://github.com/henriqueblobato/LightApi
|
|
8
|
+
Author-email: iklobato <iklobato1@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,endpoint,framework,lightweight,rest,restful
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
22
|
+
Requires-Python: >=3.8.1
|
|
23
|
+
Requires-Dist: aiohttp<4.0.0,>=3.9.5
|
|
24
|
+
Requires-Dist: pyjwt<3.0.0,>=2.8.0
|
|
25
|
+
Requires-Dist: pyyaml>=5.1
|
|
26
|
+
Requires-Dist: redis<6.0.0,>=5.0.0
|
|
27
|
+
Requires-Dist: sqlalchemy<3.0.0,>=2.0.30
|
|
28
|
+
Requires-Dist: starlette<1.0.0,>=0.37.0
|
|
29
|
+
Requires-Dist: uvicorn<1.0.0,>=0.30.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: black<24.0.0,>=23.3.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: flake8<7.0.0,>=6.0.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: isort<6.0.0,>=5.12.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: mypy<2.0.0,>=1.3.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest<8.0.0,>=7.3.1; extra == 'dev'
|
|
36
|
+
Provides-Extra: docs
|
|
37
|
+
Requires-Dist: mkdocs-awesome-pages-plugin; extra == 'docs'
|
|
38
|
+
Requires-Dist: mkdocs-git-authors-plugin; extra == 'docs'
|
|
39
|
+
Requires-Dist: mkdocs-git-committers-plugin-2; extra == 'docs'
|
|
40
|
+
Requires-Dist: mkdocs-git-revision-date-localized-plugin; extra == 'docs'
|
|
41
|
+
Requires-Dist: mkdocs-glightbox; extra == 'docs'
|
|
42
|
+
Requires-Dist: mkdocs-material; extra == 'docs'
|
|
43
|
+
Requires-Dist: mkdocstrings[python]; extra == 'docs'
|
|
44
|
+
Provides-Extra: test
|
|
45
|
+
Requires-Dist: httpx<1.0.0,>=0.27.0; extra == 'test'
|
|
46
|
+
Requires-Dist: pyjwt<3.0.0,>=2.8.0; extra == 'test'
|
|
47
|
+
Requires-Dist: pytest<8.0.0,>=7.3.1; extra == 'test'
|
|
48
|
+
Requires-Dist: redis<6.0.0,>=5.0.0; extra == 'test'
|
|
49
|
+
Requires-Dist: starlette<1.0.0,>=0.37.0; extra == 'test'
|
|
50
|
+
Requires-Dist: uvicorn<1.0.0,>=0.30.0; extra == 'test'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# LightAPI: Instant Python REST APIs from SQL Databases
|
|
54
|
+
|
|
55
|
+
[](https://pypi.org/project/lightapi/)
|
|
56
|
+
[](https://www.python.org/downloads/)
|
|
57
|
+
[](https://opensource.org/licenses/MIT)
|
|
58
|
+
|
|
59
|
+
**LightAPI** is a modern Python framework for building high-performance REST APIs directly from your SQL database—no boilerplate, no manual endpoint wiring. Instantly expose CRUD endpoints from SQLAlchemy models or a YAML config, with full support for authentication, caching, validation, filtering, and OpenAPI documentation.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Why use LightAPI?
|
|
64
|
+
|
|
65
|
+
- **Zero-boilerplate Python REST API**: Instantly generate CRUD endpoints from your database schema.
|
|
66
|
+
- **YAML-driven API generator**: Reflect your database and expose only the tables and operations you want.
|
|
67
|
+
- **Async and Fast**: Built on aiohttp for high concurrency and low latency.
|
|
68
|
+
- **Production-ready**: JWT authentication, Redis caching, request validation, and robust error handling.
|
|
69
|
+
- **Automatic OpenAPI docs**: Swagger UI and OpenAPI JSON out of the box.
|
|
70
|
+
- **Flexible**: Use with SQLite, PostgreSQL, MySQL, or any SQLAlchemy-supported database.
|
|
71
|
+
- **Modern Python**: Type hints, async/await, and best practices throughout.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Who is this for?
|
|
76
|
+
|
|
77
|
+
- **Backend developers** who want to ship APIs fast, with minimal code.
|
|
78
|
+
- **Data engineers** needing to expose existing databases as RESTful services.
|
|
79
|
+
- **Prototypers** and **startups** who want to iterate quickly and scale later.
|
|
80
|
+
- **Anyone** who wants a clean, maintainable, and extensible Python API stack.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
- 🚀 **Automatic CRUD endpoints** from SQLAlchemy models or YAML config
|
|
87
|
+
- 🔄 **Database reflection**: Expose existing tables instantly
|
|
88
|
+
- 🔐 **JWT authentication** with CORS support
|
|
89
|
+
- ⚡ **Async performance** (aiohttp)
|
|
90
|
+
- 💾 **Redis caching** with auto-invalidation
|
|
91
|
+
- 🧪 **Request validation** and error handling
|
|
92
|
+
- 🔍 **Filtering, pagination, and sorting**
|
|
93
|
+
- 📖 **OpenAPI/Swagger documentation** auto-generated
|
|
94
|
+
- 🔧 **Custom middleware** support
|
|
95
|
+
- 🗄️ **Works with SQLite, PostgreSQL, MySQL, and more**
|
|
96
|
+
- 📝 **Environment-based configuration**
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Quick Start
|
|
101
|
+
|
|
102
|
+
### 1. Install LightAPI
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install lightapi
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Define your model (SQLAlchemy)
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from lightapi import LightApi
|
|
112
|
+
from lightapi.database import Base
|
|
113
|
+
from sqlalchemy import Column, Integer, String
|
|
114
|
+
|
|
115
|
+
class User(Base):
|
|
116
|
+
__tablename__ = "users"
|
|
117
|
+
id = Column(Integer, primary_key=True)
|
|
118
|
+
name = Column(String(50))
|
|
119
|
+
email = Column(String(100))
|
|
120
|
+
|
|
121
|
+
app = LightApi()
|
|
122
|
+
app.register(User)
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
app.run()
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 3. Or use YAML for instant API from your database
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
# config.yaml
|
|
132
|
+
database_url: sqlite:///mydata.db
|
|
133
|
+
tables:
|
|
134
|
+
- name: users
|
|
135
|
+
crud: [get, post, put, patch, delete]
|
|
136
|
+
- name: orders
|
|
137
|
+
crud: [get, post]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from lightapi import LightApi
|
|
142
|
+
api = LightApi.from_config('config.yaml')
|
|
143
|
+
api.run(host="0.0.0.0", port=8081)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Example Endpoints (from YAML above)
|
|
149
|
+
|
|
150
|
+
- `GET /users/` - List users
|
|
151
|
+
- `POST /users/` - Create user
|
|
152
|
+
- `GET /users/{id}` - Get user by ID
|
|
153
|
+
- `PUT /users/{id}` - Replace user
|
|
154
|
+
- `PATCH /users/{id}` - Update user
|
|
155
|
+
- `DELETE /users/{id}` - Delete user
|
|
156
|
+
- `GET /orders/` - List orders
|
|
157
|
+
- `POST /orders/` - Create order
|
|
158
|
+
- `GET /orders/{id}` - Get order by ID
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Documentation
|
|
163
|
+
|
|
164
|
+
- [Full Documentation](https://iklobato.github.io/lightapi/)
|
|
165
|
+
- [Getting Started](https://iklobato.github.io/lightapi/getting-started/installation/)
|
|
166
|
+
- [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
|
|
167
|
+
- [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## FAQ
|
|
172
|
+
|
|
173
|
+
**Q: Can I use LightAPI with my existing database?**
|
|
174
|
+
A: Yes! Use the YAML config to reflect your schema and instantly expose REST endpoints.
|
|
175
|
+
|
|
176
|
+
**Q: What databases are supported?**
|
|
177
|
+
A: Any database supported by SQLAlchemy (PostgreSQL, MySQL, SQLite, etc.).
|
|
178
|
+
|
|
179
|
+
**Q: How do I secure my API?**
|
|
180
|
+
A: Enable JWT authentication and CORS with a single line.
|
|
181
|
+
|
|
182
|
+
**Q: Can I customize endpoints or add business logic?**
|
|
183
|
+
A: Yes, you can extend or override any handler, add middleware, and use validators.
|
|
184
|
+
|
|
185
|
+
**Q: Is this production-ready?**
|
|
186
|
+
A: Yes. LightAPI is designed for both rapid prototyping and production deployment.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Comparison
|
|
191
|
+
|
|
192
|
+
| Feature | LightAPI | FastAPI | Flask | Django REST |
|
|
193
|
+
|------------------------|----------|--------|-------|-------------|
|
|
194
|
+
| Zero-boilerplate CRUD | ✅ | ❌ | ❌ | ❌ |
|
|
195
|
+
| YAML-driven API | ✅ | ❌ | ❌ | ❌ |
|
|
196
|
+
| Async support | ✅ | ✅ | ❌ | ❌ |
|
|
197
|
+
| OpenAPI docs | ✅ | ✅ | ❌ | ✅ |
|
|
198
|
+
| Built-in Auth/Caching | ✅ | ❌ | ❌ | ✅ |
|
|
199
|
+
| DB Reflection | ✅ | ❌ | ❌ | ❌ |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT License. See [LICENSE](LICENSE).
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
> **Note:** Only GET, POST, PUT, PATCH, DELETE HTTP verbs are supported. Required fields must be NOT NULL in the schema. Constraint violations (NOT NULL, UNIQUE, FK) return 409.
|
|
210
|
+
> To start your API, always use `api.run(host, port)`. Do not use external libraries or `app = api.app` to start the server directly.
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
**LightAPI** - *The fastest way to build Python REST APIs from your database.*
|
lightapi-0.1.6/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# LightAPI: Instant Python REST APIs from SQL Databases
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/lightapi/)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**LightAPI** is a modern Python framework for building high-performance REST APIs directly from your SQL database—no boilerplate, no manual endpoint wiring. Instantly expose CRUD endpoints from SQLAlchemy models or a YAML config, with full support for authentication, caching, validation, filtering, and OpenAPI documentation.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why use LightAPI?
|
|
12
|
+
|
|
13
|
+
- **Zero-boilerplate Python REST API**: Instantly generate CRUD endpoints from your database schema.
|
|
14
|
+
- **YAML-driven API generator**: Reflect your database and expose only the tables and operations you want.
|
|
15
|
+
- **Async and Fast**: Built on aiohttp for high concurrency and low latency.
|
|
16
|
+
- **Production-ready**: JWT authentication, Redis caching, request validation, and robust error handling.
|
|
17
|
+
- **Automatic OpenAPI docs**: Swagger UI and OpenAPI JSON out of the box.
|
|
18
|
+
- **Flexible**: Use with SQLite, PostgreSQL, MySQL, or any SQLAlchemy-supported database.
|
|
19
|
+
- **Modern Python**: Type hints, async/await, and best practices throughout.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Who is this for?
|
|
24
|
+
|
|
25
|
+
- **Backend developers** who want to ship APIs fast, with minimal code.
|
|
26
|
+
- **Data engineers** needing to expose existing databases as RESTful services.
|
|
27
|
+
- **Prototypers** and **startups** who want to iterate quickly and scale later.
|
|
28
|
+
- **Anyone** who wants a clean, maintainable, and extensible Python API stack.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- 🚀 **Automatic CRUD endpoints** from SQLAlchemy models or YAML config
|
|
35
|
+
- 🔄 **Database reflection**: Expose existing tables instantly
|
|
36
|
+
- 🔐 **JWT authentication** with CORS support
|
|
37
|
+
- ⚡ **Async performance** (aiohttp)
|
|
38
|
+
- 💾 **Redis caching** with auto-invalidation
|
|
39
|
+
- 🧪 **Request validation** and error handling
|
|
40
|
+
- 🔍 **Filtering, pagination, and sorting**
|
|
41
|
+
- 📖 **OpenAPI/Swagger documentation** auto-generated
|
|
42
|
+
- 🔧 **Custom middleware** support
|
|
43
|
+
- 🗄️ **Works with SQLite, PostgreSQL, MySQL, and more**
|
|
44
|
+
- 📝 **Environment-based configuration**
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### 1. Install LightAPI
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install lightapi
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 2. Define your model (SQLAlchemy)
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from lightapi import LightApi
|
|
60
|
+
from lightapi.database import Base
|
|
61
|
+
from sqlalchemy import Column, Integer, String
|
|
62
|
+
|
|
63
|
+
class User(Base):
|
|
64
|
+
__tablename__ = "users"
|
|
65
|
+
id = Column(Integer, primary_key=True)
|
|
66
|
+
name = Column(String(50))
|
|
67
|
+
email = Column(String(100))
|
|
68
|
+
|
|
69
|
+
app = LightApi()
|
|
70
|
+
app.register(User)
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
app.run()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Or use YAML for instant API from your database
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
# config.yaml
|
|
80
|
+
database_url: sqlite:///mydata.db
|
|
81
|
+
tables:
|
|
82
|
+
- name: users
|
|
83
|
+
crud: [get, post, put, patch, delete]
|
|
84
|
+
- name: orders
|
|
85
|
+
crud: [get, post]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from lightapi import LightApi
|
|
90
|
+
api = LightApi.from_config('config.yaml')
|
|
91
|
+
api.run(host="0.0.0.0", port=8081)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Example Endpoints (from YAML above)
|
|
97
|
+
|
|
98
|
+
- `GET /users/` - List users
|
|
99
|
+
- `POST /users/` - Create user
|
|
100
|
+
- `GET /users/{id}` - Get user by ID
|
|
101
|
+
- `PUT /users/{id}` - Replace user
|
|
102
|
+
- `PATCH /users/{id}` - Update user
|
|
103
|
+
- `DELETE /users/{id}` - Delete user
|
|
104
|
+
- `GET /orders/` - List orders
|
|
105
|
+
- `POST /orders/` - Create order
|
|
106
|
+
- `GET /orders/{id}` - Get order by ID
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
- [Full Documentation](https://iklobato.github.io/lightapi/)
|
|
113
|
+
- [Getting Started](https://iklobato.github.io/lightapi/getting-started/installation/)
|
|
114
|
+
- [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
|
|
115
|
+
- [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## FAQ
|
|
120
|
+
|
|
121
|
+
**Q: Can I use LightAPI with my existing database?**
|
|
122
|
+
A: Yes! Use the YAML config to reflect your schema and instantly expose REST endpoints.
|
|
123
|
+
|
|
124
|
+
**Q: What databases are supported?**
|
|
125
|
+
A: Any database supported by SQLAlchemy (PostgreSQL, MySQL, SQLite, etc.).
|
|
126
|
+
|
|
127
|
+
**Q: How do I secure my API?**
|
|
128
|
+
A: Enable JWT authentication and CORS with a single line.
|
|
129
|
+
|
|
130
|
+
**Q: Can I customize endpoints or add business logic?**
|
|
131
|
+
A: Yes, you can extend or override any handler, add middleware, and use validators.
|
|
132
|
+
|
|
133
|
+
**Q: Is this production-ready?**
|
|
134
|
+
A: Yes. LightAPI is designed for both rapid prototyping and production deployment.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Comparison
|
|
139
|
+
|
|
140
|
+
| Feature | LightAPI | FastAPI | Flask | Django REST |
|
|
141
|
+
|------------------------|----------|--------|-------|-------------|
|
|
142
|
+
| Zero-boilerplate CRUD | ✅ | ❌ | ❌ | ❌ |
|
|
143
|
+
| YAML-driven API | ✅ | ❌ | ❌ | ❌ |
|
|
144
|
+
| Async support | ✅ | ✅ | ❌ | ❌ |
|
|
145
|
+
| OpenAPI docs | ✅ | ✅ | ❌ | ✅ |
|
|
146
|
+
| Built-in Auth/Caching | ✅ | ❌ | ❌ | ✅ |
|
|
147
|
+
| DB Reflection | ✅ | ❌ | ❌ | ❌ |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT License. See [LICENSE](LICENSE).
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
> **Note:** Only GET, POST, PUT, PATCH, DELETE HTTP verbs are supported. Required fields must be NOT NULL in the schema. Constraint violations (NOT NULL, UNIQUE, FK) return 409.
|
|
158
|
+
> To start your API, always use `api.run(host, port)`. Do not use external libraries or `app = api.app` to start the server directly.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
**LightAPI** - *The fastest way to build Python REST APIs from your database.*
|
|
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "lightapi"
|
|
9
|
-
version = "0.1.
|
|
9
|
+
version = "0.1.6"
|
|
10
10
|
description = "A lightweight framework for building API endpoints using Python's native libraries."
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.8.1"
|
lightapi-0.1.5/PKG-INFO
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: lightapi
|
|
3
|
-
Version: 0.1.5
|
|
4
|
-
Summary: A lightweight framework for building API endpoints using Python's native libraries.
|
|
5
|
-
Project-URL: Repository, https://github.com/henriqueblobato/LightApi
|
|
6
|
-
Project-URL: Issues, https://github.com/henriqueblobato/LightApi/issues
|
|
7
|
-
Project-URL: Homepage, https://github.com/henriqueblobato/LightApi
|
|
8
|
-
Author-email: iklobato <iklobato1@gmail.com>
|
|
9
|
-
License: MIT
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Keywords: api,endpoint,framework,lightweight,rest,restful
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Operating System :: OS Independent
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Topic :: Internet :: WWW/HTTP
|
|
20
|
-
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
21
|
-
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
22
|
-
Requires-Python: >=3.8.1
|
|
23
|
-
Requires-Dist: aiohttp<4.0.0,>=3.9.5
|
|
24
|
-
Requires-Dist: pyjwt<3.0.0,>=2.8.0
|
|
25
|
-
Requires-Dist: pyyaml>=5.1
|
|
26
|
-
Requires-Dist: redis<6.0.0,>=5.0.0
|
|
27
|
-
Requires-Dist: sqlalchemy<3.0.0,>=2.0.30
|
|
28
|
-
Requires-Dist: starlette<1.0.0,>=0.37.0
|
|
29
|
-
Requires-Dist: uvicorn<1.0.0,>=0.30.0
|
|
30
|
-
Provides-Extra: dev
|
|
31
|
-
Requires-Dist: black<24.0.0,>=23.3.0; extra == 'dev'
|
|
32
|
-
Requires-Dist: flake8<7.0.0,>=6.0.0; extra == 'dev'
|
|
33
|
-
Requires-Dist: isort<6.0.0,>=5.12.0; extra == 'dev'
|
|
34
|
-
Requires-Dist: mypy<2.0.0,>=1.3.0; extra == 'dev'
|
|
35
|
-
Requires-Dist: pytest<8.0.0,>=7.3.1; extra == 'dev'
|
|
36
|
-
Provides-Extra: docs
|
|
37
|
-
Requires-Dist: mkdocs-awesome-pages-plugin; extra == 'docs'
|
|
38
|
-
Requires-Dist: mkdocs-git-authors-plugin; extra == 'docs'
|
|
39
|
-
Requires-Dist: mkdocs-git-committers-plugin-2; extra == 'docs'
|
|
40
|
-
Requires-Dist: mkdocs-git-revision-date-localized-plugin; extra == 'docs'
|
|
41
|
-
Requires-Dist: mkdocs-glightbox; extra == 'docs'
|
|
42
|
-
Requires-Dist: mkdocs-material; extra == 'docs'
|
|
43
|
-
Requires-Dist: mkdocstrings[python]; extra == 'docs'
|
|
44
|
-
Provides-Extra: test
|
|
45
|
-
Requires-Dist: httpx<1.0.0,>=0.27.0; extra == 'test'
|
|
46
|
-
Requires-Dist: pyjwt<3.0.0,>=2.8.0; extra == 'test'
|
|
47
|
-
Requires-Dist: pytest<8.0.0,>=7.3.1; extra == 'test'
|
|
48
|
-
Requires-Dist: redis<6.0.0,>=5.0.0; extra == 'test'
|
|
49
|
-
Requires-Dist: starlette<1.0.0,>=0.37.0; extra == 'test'
|
|
50
|
-
Requires-Dist: uvicorn<1.0.0,>=0.30.0; extra == 'test'
|
|
51
|
-
Description-Content-Type: text/markdown
|
|
52
|
-
|
|
53
|
-
# LightAPI
|
|
54
|
-
|
|
55
|
-
[](https://badge.fury.io/py/lightapi)
|
|
56
|
-
[](https://www.python.org/downloads/)
|
|
57
|
-
[](https://opensource.org/licenses/MIT)
|
|
58
|
-
|
|
59
|
-
A lightweight, fast, and easy-to-use web API framework for Python with automatic REST endpoint generation, built-in authentication, caching, and more.
|
|
60
|
-
|
|
61
|
-
## Features
|
|
62
|
-
|
|
63
|
-
- 🚀 **Zero-boilerplate REST APIs** - Automatically generate CRUD operations from SQLAlchemy models
|
|
64
|
-
- 🔐 **Built-in Authentication** - JWT authentication with automatic CORS handling
|
|
65
|
-
- ⚡ **High Performance** - Built on Starlette for async support and speed
|
|
66
|
-
- 💾 **Smart Caching** - Redis-based caching with automatic invalidation
|
|
67
|
-
- 📊 **Request Validation** - Automatic request validation and error handling
|
|
68
|
-
- 🔍 **Advanced Filtering** - Query filtering, pagination, and sorting out of the box
|
|
69
|
-
- 📖 **Auto Documentation** - Automatic OpenAPI/Swagger documentation generation
|
|
70
|
-
- 🔧 **Flexible Middleware** - Easy middleware system for custom logic
|
|
71
|
-
- 🗄️ **Database Integration** - Seamless SQLAlchemy integration with automatic table creation
|
|
72
|
-
- ⚙️ **Environment Configuration** - Easy configuration management
|
|
73
|
-
|
|
74
|
-
## Quick Start
|
|
75
|
-
|
|
76
|
-
### Installation
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
pip install lightapi
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Basic Usage
|
|
83
|
-
|
|
84
|
-
```python
|
|
85
|
-
from lightapi import LightApi
|
|
86
|
-
from lightapi.database import Base
|
|
87
|
-
from sqlalchemy import Column, Integer, String
|
|
88
|
-
|
|
89
|
-
# Define your model
|
|
90
|
-
class User(Base):
|
|
91
|
-
__tablename__ = "users"
|
|
92
|
-
|
|
93
|
-
id = Column(Integer, primary_key=True)
|
|
94
|
-
name = Column(String(50))
|
|
95
|
-
email = Column(String(100))
|
|
96
|
-
|
|
97
|
-
# Create API instance
|
|
98
|
-
app = LightApi()
|
|
99
|
-
|
|
100
|
-
# Register your model - automatically creates CRUD endpoints
|
|
101
|
-
app.register(User)
|
|
102
|
-
|
|
103
|
-
# Run the server
|
|
104
|
-
if __name__ == "__main__":
|
|
105
|
-
app.run()
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
That's it! You now have a fully functional REST API with:
|
|
109
|
-
- `GET /users` - List all users with filtering and pagination
|
|
110
|
-
- `GET /users/{id}` - Get user by ID
|
|
111
|
-
- `POST /users` - Create new user
|
|
112
|
-
- `PUT /users/{id}` - Update user
|
|
113
|
-
- `DELETE /users/{id}` - Delete user
|
|
114
|
-
- `OPTIONS /users` - CORS preflight support
|
|
115
|
-
|
|
116
|
-
## Dynamic API from YAML Config (SQLAlchemy Reflection)
|
|
117
|
-
|
|
118
|
-
LightAPI can instantly generate a REST API from a YAML configuration file, reflecting your database schema at runtime using SQLAlchemy. This is ideal for exposing existing databases with zero model code.
|
|
119
|
-
|
|
120
|
-
### How It Works
|
|
121
|
-
- **Reflects** the schema of specified tables from your database (PostgreSQL, MySQL, SQLite, etc.)
|
|
122
|
-
- **Dynamically generates** SQLAlchemy models and CRUD endpoints for each table
|
|
123
|
-
- **Configurable**: You control which tables and which CRUD operations (GET, POST, PUT, PATCH, DELETE) are exposed
|
|
124
|
-
- **Composite primary keys, unique constraints, foreign keys, BLOBs, JSON, and more** are supported
|
|
125
|
-
- **Advanced edge cases** (triggers, generated columns, partial unique constraints, etc.) are handled
|
|
126
|
-
|
|
127
|
-
### End-to-End Example
|
|
128
|
-
|
|
129
|
-
#### 1. Create a YAML Config
|
|
130
|
-
```yaml
|
|
131
|
-
database_url: sqlite:///mydata.db
|
|
132
|
-
|
|
133
|
-
tables:
|
|
134
|
-
- name: users
|
|
135
|
-
crud: [get, post, put, patch, delete]
|
|
136
|
-
- name: orders
|
|
137
|
-
crud: [get, post]
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
#### 2. Create Your Database (SQLite example)
|
|
141
|
-
```bash
|
|
142
|
-
sqlite3 mydata.db "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE); CREATE TABLE orders (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, amount REAL NOT NULL, FOREIGN KEY(user_id) REFERENCES users(id));"
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
#### 3. Start the API
|
|
146
|
-
```python
|
|
147
|
-
from lightapi import LightApi
|
|
148
|
-
api = LightApi.from_config('config.yaml')
|
|
149
|
-
api.run(host="0.0.0.0", port=8081)
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
#### 4. Use the API (with curl)
|
|
153
|
-
```bash
|
|
154
|
-
# Create a user
|
|
155
|
-
curl -X POST http://localhost:8080/users/ -H 'Content-Type: application/json' -d '{"name": "Alice", "email": "alice@example.com"}'
|
|
156
|
-
|
|
157
|
-
# List users
|
|
158
|
-
curl http://localhost:8080/users/
|
|
159
|
-
|
|
160
|
-
# Create an order for Alice (id=1)
|
|
161
|
-
curl -X POST http://localhost:8080/orders/ -H 'Content-Type: application/json' -d '{"user_id": 1, "amount": 42.5}'
|
|
162
|
-
|
|
163
|
-
# List orders
|
|
164
|
-
curl http://localhost:8080/orders/
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### FAQ & Tips
|
|
168
|
-
- **Server-side defaults**: Only `server_default` (e.g., `server_default=text('...')`) are available after reflection. Python-side defaults are not reflected.
|
|
169
|
-
- **Composite PKs**: Supported transparently in routes and handlers.
|
|
170
|
-
- **Error handling**: Unique, check, not null, and foreign key constraints are enforced. Violations return 409 Conflict with details.
|
|
171
|
-
- **Partial CRUD**: You can expose only the operations you want per table.
|
|
172
|
-
- **Supported DBs**: Any DB supported by SQLAlchemy reflection (PostgreSQL, MySQL, SQLite, etc.)
|
|
173
|
-
|
|
174
|
-
See the [docs](./docs/getting-started/quickstart.md#dynamic-api-from-yaml-config-sqlalchemy-reflection) for more advanced examples and details.
|
|
175
|
-
|
|
176
|
-
## Documentation
|
|
177
|
-
|
|
178
|
-
Visit our comprehensive documentation at: https://iklobato.github.io/lightapi/
|
|
179
|
-
|
|
180
|
-
- [Getting Started Guide](https://iklobato.github.io/lightapi/getting-started/installation/)
|
|
181
|
-
- [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
|
|
182
|
-
- [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
|
|
183
|
-
|
|
184
|
-
## Advanced Features
|
|
185
|
-
|
|
186
|
-
### Authentication
|
|
187
|
-
|
|
188
|
-
```python
|
|
189
|
-
from lightapi.auth import JWTAuthentication
|
|
190
|
-
|
|
191
|
-
# Add JWT authentication
|
|
192
|
-
auth = JWTAuthentication(secret_key="your-secret-key")
|
|
193
|
-
app.add_middleware(auth)
|
|
194
|
-
|
|
195
|
-
# Protected endpoints automatically require valid JWT tokens
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### Caching
|
|
199
|
-
|
|
200
|
-
```python
|
|
201
|
-
from lightapi.cache import RedisCache
|
|
202
|
-
|
|
203
|
-
# Add Redis caching
|
|
204
|
-
cache = RedisCache(host="localhost", port=6379)
|
|
205
|
-
app.register(User, cache=cache, cache_ttl=300) # 5 minutes TTL
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
### Validation
|
|
209
|
-
|
|
210
|
-
```python
|
|
211
|
-
from lightapi.rest import Validator
|
|
212
|
-
|
|
213
|
-
class UserValidator(Validator):
|
|
214
|
-
def validate_post(self, data):
|
|
215
|
-
if not data.get("email"):
|
|
216
|
-
raise ValueError("Email is required")
|
|
217
|
-
return data
|
|
218
|
-
|
|
219
|
-
app.register(User, validator=UserValidator())
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
- All required fields must be defined as NOT NULL in your database schema for correct enforcement.
|
|
223
|
-
- The API will return 409 Conflict if you attempt to create or update a record missing a NOT NULL field, or violating a UNIQUE or FOREIGN KEY constraint.
|
|
224
|
-
|
|
225
|
-
### Middleware
|
|
226
|
-
|
|
227
|
-
```python
|
|
228
|
-
from lightapi.core import Middleware
|
|
229
|
-
|
|
230
|
-
class LoggingMiddleware(Middleware):
|
|
231
|
-
async def process(self, request, call_next):
|
|
232
|
-
print(f"Request: {request.method} {request.url}")
|
|
233
|
-
response = await call_next(request)
|
|
234
|
-
print(f"Response: {response.status_code}")
|
|
235
|
-
return response
|
|
236
|
-
|
|
237
|
-
app.add_middleware(LoggingMiddleware())
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## Why LightAPI?
|
|
241
|
-
|
|
242
|
-
- **Rapid Development**: Get REST APIs running in minutes, not hours
|
|
243
|
-
- **Production Ready**: Built-in security, caching, and error handling
|
|
244
|
-
- **Flexible**: Customize every aspect while keeping defaults simple
|
|
245
|
-
- **Modern**: Async support, type hints, and contemporary Python practices
|
|
246
|
-
- **Well Documented**: Comprehensive docs with real-world examples
|
|
247
|
-
|
|
248
|
-
## Examples
|
|
249
|
-
|
|
250
|
-
Check out the [examples directory](./examples/) for complete applications:
|
|
251
|
-
|
|
252
|
-
- [Basic REST API](./examples/basic_rest_api.py) - Simple CRUD operations
|
|
253
|
-
- [Authentication](./examples/auth_example.py) - JWT authentication
|
|
254
|
-
- [Caching](./examples/caching_example.py) - Redis caching implementation
|
|
255
|
-
- [Validation](./examples/validation_example.py) - Request validation
|
|
256
|
-
- [Middleware](./examples/middleware_example.py) - Custom middleware
|
|
257
|
-
- [Filtering & Pagination](./examples/filtering_pagination_example.py) - Advanced queries
|
|
258
|
-
|
|
259
|
-
## Contributing
|
|
260
|
-
|
|
261
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
262
|
-
|
|
263
|
-
## License
|
|
264
|
-
|
|
265
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
266
|
-
|
|
267
|
-
---
|
|
268
|
-
|
|
269
|
-
**LightAPI** - *Making web APIs light and fast* ⚡
|
|
270
|
-
|
|
271
|
-
<!-- Testing development pipeline -->
|
|
272
|
-
|
|
273
|
-
> **Note:** Only GET, POST, PUT, PATCH, DELETE HTTP verbs are supported. OPTIONS and HEAD are not available. Required fields must be NOT NULL in the schema. Constraint violations (NOT NULL, UNIQUE, FK) return 409.
|