lightapi 0.1.4__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.4 → lightapi-0.1.6}/docs/api-reference/core.md +2 -12
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/rest.md +4 -2
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/getting-started/quickstart.md +1 -3
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/index.md +2 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/core-api.md +1 -1
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/lightapi.py +1 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/pyproject.toml +1 -1
- {lightapi-0.1.4 → lightapi-0.1.6}/run_server.py +1 -3
- lightapi-0.1.4/PKG-INFO +0 -277
- lightapi-0.1.4/README.md +0 -225
- {lightapi-0.1.4 → lightapi-0.1.6}/.github/workflows/pages-publish.yml +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/.github/workflows/python-publish.yml +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/.github/workflows/test-dev.yml +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/.gitignore +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/LICENSE +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/authentication.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/caching.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/filtering.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/middleware.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/pagination.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/advanced/validation.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/auth.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/cache.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/database.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/exceptions.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/filters.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/index.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/models.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/pagination.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/swagger.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/api-reference/validation.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/deployment/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/deployment/docker.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/deployment/production.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/deployment/security.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/auth.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/basic-crud.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/basic-rest.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/caching.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/custom-application.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/filtering-pagination.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/middleware.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/examples/validation.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/getting-started/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/getting-started/configuration.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/getting-started/first-steps.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/getting-started/installation.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/getting-started/introduction.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/cache.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/endpoints.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/handlers.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/middleware.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/technical-reference/models.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/troubleshooting.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/tutorial/.pages +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/tutorial/basic-api.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/tutorial/database.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/tutorial/endpoints.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/tutorial/requests.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/docs/tutorial/responses.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/README.md +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/__init__.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/auth_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/basic_rest_api.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/caching_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/custom_snippet.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/filtering_pagination_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/middleware_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/relationships_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/swagger_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/user_goal_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/examples/validation_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/__init__.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/auth.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/base_endpoint.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/cache.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/config.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/core.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/database.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/exceptions.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/filters.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/handlers.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/models.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/pagination.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/rest.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/lightapi/swagger.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/mkdocs.yml +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/pytest.ini +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/requirements.txt +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/__init__.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/conftest.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_additional_features.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_auth.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_auth_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_basic_rest_api.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_cache.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_caching_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_clients.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_core.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_custom_snippet.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_filtering_pagination_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_filters.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_from_config.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_helpers.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_integration.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_middleware.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_middleware_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_pagination.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_rest.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_swagger.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/tests/test_validation_example.py +0 -0
- {lightapi-0.1.4 → lightapi-0.1.6}/update_version.py +0 -0
- {lightapi-0.1.4 → 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.*
|
|
@@ -83,24 +83,14 @@ app.add_middleware([
|
|
|
83
83
|
**Parameters:**
|
|
84
84
|
- `middleware_classes` (List[Type[Middleware]]): List of middleware classes to add
|
|
85
85
|
|
|
86
|
-
#### run()
|
|
86
|
+
#### run(host: str = "0.0.0.0", port: int = 8000, debug: bool = False) -> None
|
|
87
87
|
|
|
88
|
-
Starts the
|
|
89
|
-
|
|
90
|
-
```python
|
|
91
|
-
app.run(
|
|
92
|
-
host="0.0.0.0",
|
|
93
|
-
port=8000,
|
|
94
|
-
debug=True,
|
|
95
|
-
reload=True
|
|
96
|
-
)
|
|
97
|
-
```
|
|
88
|
+
Starts the server. This is the only supported way to start the application. Do not use external libraries to start the server directly.
|
|
98
89
|
|
|
99
90
|
**Parameters:**
|
|
100
91
|
- `host` (str): Server host address
|
|
101
92
|
- `port` (int): Server port number
|
|
102
93
|
- `debug` (bool): Enable debug mode
|
|
103
|
-
- `reload` (bool): Enable auto-reload on code changes
|
|
104
94
|
|
|
105
95
|
### Advanced Configuration
|
|
106
96
|
|
|
@@ -747,8 +747,10 @@ class User(RestEndpoint):
|
|
|
747
747
|
- [Core API](core.md) - Core framework functionality
|
|
748
748
|
- [Models](models.md) - Data models and schemas
|
|
749
749
|
- [Filtering](filters.md) - Advanced filtering options
|
|
750
|
-
- [Pagination](pagination.md) - Pagination configuration
|
|
750
|
+
- [Pagination](pagination.md) - Pagination configuration
|
|
751
751
|
|
|
752
752
|
- Only GET, POST, PUT, PATCH, DELETE HTTP verbs are supported. OPTIONS and HEAD are not available.
|
|
753
753
|
- All required fields must be defined as NOT NULL in your database schema for correct enforcement.
|
|
754
|
-
- 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.
|
|
754
|
+
- 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.
|
|
755
|
+
|
|
756
|
+
To start your API, always use `api.run(host, port)`. Do not use external libraries or 'app = api.app' to start the server directly.
|
|
@@ -70,10 +70,8 @@ sqlite3 mydata.db "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, nam
|
|
|
70
70
|
**3. Start the API:**
|
|
71
71
|
```python
|
|
72
72
|
from lightapi import LightApi
|
|
73
|
-
import aiohttp.web
|
|
74
73
|
api = LightApi.from_config('my_api_config.yaml')
|
|
75
|
-
|
|
76
|
-
aiohttp.web.run_app(app, port=8080)
|
|
74
|
+
api.run(host="0.0.0.0", port=8080)
|
|
77
75
|
```
|
|
78
76
|
|
|
79
77
|
**4. Use the API (with curl):**
|
|
@@ -158,3 +158,5 @@ LightAPI is released under the [MIT License](https://github.com/henriqueblobato/
|
|
|
158
158
|
|
|
159
159
|
> **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.
|
|
160
160
|
|
|
161
|
+
> To start your API, always use `api.run(host, port)`. Do not use external libraries or 'app = api.app' to start the server directly.
|
|
162
|
+
|
|
@@ -50,7 +50,7 @@ Adds application-wide middleware.
|
|
|
50
50
|
|
|
51
51
|
#### run(host: str = "0.0.0.0", port: int = 8000, debug: bool = False) -> None
|
|
52
52
|
|
|
53
|
-
Starts the
|
|
53
|
+
Starts the server. This is the only supported way to start the application. Do not use external libraries to start the server directly.
|
|
54
54
|
|
|
55
55
|
- **Parameters:**
|
|
56
56
|
- `host`: Host address to bind (default: `"0.0.0.0"`).
|
|
@@ -119,6 +119,7 @@ class LightApi:
|
|
|
119
119
|
port (int): The port number on which the server will listen. Defaults to 8000.
|
|
120
120
|
"""
|
|
121
121
|
self.app.add_routes(self.routes)
|
|
122
|
+
# Only use this method to start the server
|
|
122
123
|
web.run_app(self.app, host=host, port=port)
|
|
123
124
|
|
|
124
125
|
@classmethod
|
|
@@ -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"
|