lightapi 0.1.8__tar.gz → 0.1.10__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.
Files changed (120) hide show
  1. lightapi-0.1.10/PKG-INFO +449 -0
  2. lightapi-0.1.10/README.md +397 -0
  3. {lightapi-0.1.8 → lightapi-0.1.10}/examples/mega_example.py +15 -0
  4. {lightapi-0.1.8 → lightapi-0.1.10}/pyproject.toml +1 -1
  5. lightapi-0.1.8/PKG-INFO +0 -214
  6. lightapi-0.1.8/README.md +0 -162
  7. {lightapi-0.1.8 → lightapi-0.1.10}/.github/workflows/pages-publish.yml +0 -0
  8. {lightapi-0.1.8 → lightapi-0.1.10}/.github/workflows/python-publish.yml +0 -0
  9. {lightapi-0.1.8 → lightapi-0.1.10}/.github/workflows/test-dev.yml +0 -0
  10. {lightapi-0.1.8 → lightapi-0.1.10}/.gitignore +0 -0
  11. {lightapi-0.1.8 → lightapi-0.1.10}/LICENSE +0 -0
  12. {lightapi-0.1.8 → lightapi-0.1.10}/docs/.pages +0 -0
  13. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/.pages +0 -0
  14. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/authentication.md +0 -0
  15. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/caching.md +0 -0
  16. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/filtering.md +0 -0
  17. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/middleware.md +0 -0
  18. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/pagination.md +0 -0
  19. {lightapi-0.1.8 → lightapi-0.1.10}/docs/advanced/validation.md +0 -0
  20. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/.pages +0 -0
  21. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/auth.md +0 -0
  22. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/cache.md +0 -0
  23. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/core.md +0 -0
  24. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/database.md +0 -0
  25. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/exceptions.md +0 -0
  26. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/filters.md +0 -0
  27. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/index.md +0 -0
  28. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/models.md +0 -0
  29. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/pagination.md +0 -0
  30. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/rest.md +0 -0
  31. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/swagger.md +0 -0
  32. {lightapi-0.1.8 → lightapi-0.1.10}/docs/api-reference/validation.md +0 -0
  33. {lightapi-0.1.8 → lightapi-0.1.10}/docs/deployment/.pages +0 -0
  34. {lightapi-0.1.8 → lightapi-0.1.10}/docs/deployment/docker.md +0 -0
  35. {lightapi-0.1.8 → lightapi-0.1.10}/docs/deployment/production.md +0 -0
  36. {lightapi-0.1.8 → lightapi-0.1.10}/docs/deployment/security.md +0 -0
  37. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/.pages +0 -0
  38. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/auth.md +0 -0
  39. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/basic-crud.md +0 -0
  40. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/basic-rest.md +0 -0
  41. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/caching.md +0 -0
  42. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/custom-application.md +0 -0
  43. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/filtering-pagination.md +0 -0
  44. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/middleware.md +0 -0
  45. {lightapi-0.1.8 → lightapi-0.1.10}/docs/examples/validation.md +0 -0
  46. {lightapi-0.1.8 → lightapi-0.1.10}/docs/getting-started/.pages +0 -0
  47. {lightapi-0.1.8 → lightapi-0.1.10}/docs/getting-started/configuration.md +0 -0
  48. {lightapi-0.1.8 → lightapi-0.1.10}/docs/getting-started/first-steps.md +0 -0
  49. {lightapi-0.1.8 → lightapi-0.1.10}/docs/getting-started/installation.md +0 -0
  50. {lightapi-0.1.8 → lightapi-0.1.10}/docs/getting-started/introduction.md +0 -0
  51. {lightapi-0.1.8 → lightapi-0.1.10}/docs/getting-started/quickstart.md +0 -0
  52. {lightapi-0.1.8 → lightapi-0.1.10}/docs/index.md +0 -0
  53. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/.pages +0 -0
  54. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/cache.md +0 -0
  55. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/core-api.md +0 -0
  56. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/endpoints.md +0 -0
  57. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/handlers.md +0 -0
  58. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/middleware.md +0 -0
  59. {lightapi-0.1.8 → lightapi-0.1.10}/docs/technical-reference/models.md +0 -0
  60. {lightapi-0.1.8 → lightapi-0.1.10}/docs/troubleshooting.md +0 -0
  61. {lightapi-0.1.8 → lightapi-0.1.10}/docs/tutorial/.pages +0 -0
  62. {lightapi-0.1.8 → lightapi-0.1.10}/docs/tutorial/basic-api.md +0 -0
  63. {lightapi-0.1.8 → lightapi-0.1.10}/docs/tutorial/database.md +0 -0
  64. {lightapi-0.1.8 → lightapi-0.1.10}/docs/tutorial/endpoints.md +0 -0
  65. {lightapi-0.1.8 → lightapi-0.1.10}/docs/tutorial/requests.md +0 -0
  66. {lightapi-0.1.8 → lightapi-0.1.10}/docs/tutorial/responses.md +0 -0
  67. {lightapi-0.1.8 → lightapi-0.1.10}/examples/README.md +0 -0
  68. {lightapi-0.1.8 → lightapi-0.1.10}/examples/__init__.py +0 -0
  69. {lightapi-0.1.8 → lightapi-0.1.10}/examples/authentication_jwt.py +0 -0
  70. {lightapi-0.1.8 → lightapi-0.1.10}/examples/blog_post.py +0 -0
  71. {lightapi-0.1.8 → lightapi-0.1.10}/examples/caching_redis_custom.py +0 -0
  72. {lightapi-0.1.8 → lightapi-0.1.10}/examples/comprehensive_ideal_usage.py +0 -0
  73. {lightapi-0.1.8 → lightapi-0.1.10}/examples/example.py +0 -0
  74. {lightapi-0.1.8 → lightapi-0.1.10}/examples/filtering_pagination.py +0 -0
  75. {lightapi-0.1.8 → lightapi-0.1.10}/examples/general_usage.py +0 -0
  76. {lightapi-0.1.8 → lightapi-0.1.10}/examples/middleware_cors_auth.py +0 -0
  77. {lightapi-0.1.8 → lightapi-0.1.10}/examples/middleware_custom.py +0 -0
  78. {lightapi-0.1.8 → lightapi-0.1.10}/examples/relationships_sqlalchemy.py +0 -0
  79. {lightapi-0.1.8 → lightapi-0.1.10}/examples/rest_crud_basic.py +0 -0
  80. {lightapi-0.1.8 → lightapi-0.1.10}/examples/swagger_openapi_docs.py +0 -0
  81. {lightapi-0.1.8 → lightapi-0.1.10}/examples/user_goal_example.py +0 -0
  82. {lightapi-0.1.8 → lightapi-0.1.10}/examples/validation_custom_fields.py +0 -0
  83. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/__init__.py +0 -0
  84. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/auth.py +0 -0
  85. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/base_endpoint.py +0 -0
  86. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/cache.py +0 -0
  87. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/config.py +0 -0
  88. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/core.py +0 -0
  89. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/database.py +0 -0
  90. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/exceptions.py +0 -0
  91. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/filters.py +0 -0
  92. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/handlers.py +0 -0
  93. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/lightapi.py +0 -0
  94. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/models.py +0 -0
  95. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/pagination.py +0 -0
  96. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/rest.py +0 -0
  97. {lightapi-0.1.8 → lightapi-0.1.10}/lightapi/swagger.py +0 -0
  98. {lightapi-0.1.8 → lightapi-0.1.10}/mkdocs.yml +0 -0
  99. {lightapi-0.1.8 → lightapi-0.1.10}/pytest.ini +0 -0
  100. {lightapi-0.1.8 → lightapi-0.1.10}/requirements.txt +0 -0
  101. {lightapi-0.1.8 → lightapi-0.1.10}/run_server.py +0 -0
  102. {lightapi-0.1.8 → lightapi-0.1.10}/tests/conftest.py +0 -0
  103. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_additional_features.py +0 -0
  104. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_auth.py +0 -0
  105. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_cache.py +0 -0
  106. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_caching_example.py +0 -0
  107. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_core.py +0 -0
  108. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_custom_snippet.py +0 -0
  109. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_filtering_pagination_example.py +0 -0
  110. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_filters.py +0 -0
  111. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_from_config.py +0 -0
  112. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_helpers.py +0 -0
  113. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_integration.py +0 -0
  114. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_middleware.py +0 -0
  115. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_pagination.py +0 -0
  116. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_rest.py +0 -0
  117. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_swagger.py +0 -0
  118. {lightapi-0.1.8 → lightapi-0.1.10}/tests/test_validators.py +0 -0
  119. {lightapi-0.1.8 → lightapi-0.1.10}/update_version.py +0 -0
  120. {lightapi-0.1.8 → lightapi-0.1.10}/uv.lock +0 -0
@@ -0,0 +1,449 @@
1
+ Metadata-Version: 2.4
2
+ Name: lightapi
3
+ Version: 0.1.10
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: Fast Python REST API Framework with Async, CRUD, OpenAPI, JWT, and YAML
54
+
55
+ [![PyPI version](https://badge.fury.io/py/lightapi.svg)](https://pypi.org/project/lightapi/)
56
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
57
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
58
+
59
+ **LightAPI** is a fast, async-ready Python REST API framework that lets you instantly generate CRUD endpoints from SQLAlchemy models or your existing database schema. With built-in OpenAPI documentation, JWT authentication, Redis caching, and YAML-driven configuration, LightAPI is the best choice for building scalable, production-ready APIs in Python.
60
+
61
+ ---
62
+
63
+ ## Table of Contents
64
+ - [Why LightAPI?](#why-lightapi)
65
+ - [Who is LightAPI for?](#who-is-lightapi-for)
66
+ - [Features: Python REST API, Async, CRUD, OpenAPI, JWT, Caching](#features-python-rest-api-async-crud-openapi-jwt-caching)
67
+ - [Feature Details & Usage](#feature-details--usage)
68
+ - [Automatic CRUD Endpoints with SQLAlchemy](#automatic-crud-endpoints-with-sqlalchemy)
69
+ - [YAML-Driven API Generation (Database Reflection)](#yaml-driven-api-generation-database-reflection)
70
+ - [OpenAPI/Swagger Documentation](#openapiswapper-documentation)
71
+ - [Works with All Major Databases](#works-with-all-major-databases)
72
+ - [Environment-based Configuration](#environment-based-configuration)
73
+ - [JWT Authentication and Security](#jwt-authentication-and-security)
74
+ - [CORS Support for Python APIs](#cors-support-for-python-apis)
75
+ - [Custom Middleware for Python APIs](#custom-middleware-for-python-apis)
76
+ - [Async/Await Support for High-Performance Python APIs](#asyncawait-support-for-high-performance-python-apis)
77
+ - [Redis Caching for Python APIs](#redis-caching-for-python-apis)
78
+ - [Filtering, Pagination, and Sorting](#filtering-pagination-and-sorting)
79
+ - [Request Validation](#request-validation)
80
+ - [Type Hints & Modern Python](#type-hints--modern-python)
81
+ - [Comprehensive Error Handling](#comprehensive-error-handling)
82
+ - [Quick Start: Build a Python REST API in Minutes](#quick-start-build-a-python-rest-api-in-minutes)
83
+ - [Example Endpoints](#example-endpoints)
84
+ - [Documentation](#documentation)
85
+ - [FAQ](#faq)
86
+ - [Comparison](#comparison)
87
+ - [License](#license)
88
+ - [Troubleshooting](#troubleshooting)
89
+
90
+ ---
91
+
92
+ ## Why LightAPI?
93
+
94
+ LightAPI is a modern, async-ready Python REST API framework designed for rapid development and production use. Instantly generate CRUD endpoints from your SQLAlchemy models or YAML config, with full support for OpenAPI docs, JWT authentication, Redis caching, request validation, and more. LightAPI is ideal for anyone who wants to build scalable, maintainable, and high-performance APIs in Python.
95
+
96
+ ---
97
+
98
+ ## Who is LightAPI for?
99
+
100
+ - **Backend developers** who want to ship APIs fast, with minimal code.
101
+ - **Data engineers** needing to expose existing databases as RESTful services.
102
+ - **Prototypers** and **startups** who want to iterate quickly and scale later.
103
+ - **Anyone** who wants a clean, maintainable, and extensible Python API stack.
104
+
105
+ ---
106
+
107
+ # Features: Python REST API, Async, CRUD, OpenAPI, JWT, Caching
108
+
109
+ LightAPI is designed to cover all the essentials for modern API development. Features are grouped for clarity:
110
+
111
+ ## Core Features
112
+ - **Automatic CRUD Endpoints with SQLAlchemy**
113
+ - **YAML-Driven API Generation (Database Reflection)**
114
+ - **OpenAPI/Swagger Documentation**
115
+ - **Works with All Major Databases**
116
+ - **Environment-based Configuration**
117
+
118
+ ## Security & Access Control
119
+ - **JWT Authentication and Security**
120
+ - **CORS Support for Python APIs**
121
+ - **Custom Middleware for Python APIs**
122
+
123
+ ## Performance & Scalability
124
+ - **Async/Await Support for High-Performance Python APIs**
125
+ - **Redis Caching for Python APIs**
126
+ - **Filtering, Pagination, and Sorting**
127
+
128
+ ## Developer Experience
129
+ - **Request Validation**
130
+ - **Type Hints & Modern Python**
131
+ - **Comprehensive Error Handling**
132
+
133
+ ---
134
+
135
+ # Feature Details & Usage
136
+
137
+ ## Automatic CRUD Endpoints with SQLAlchemy
138
+ Instantly generate RESTful endpoints for your models or tables, so you can create, read, update, and delete records with no manual wiring.
139
+ ```python
140
+ from lightapi import LightApi
141
+ from sqlalchemy import Column, Integer, String
142
+ class User(Base):
143
+ __tablename__ = 'users'
144
+ id = Column(Integer, primary_key=True)
145
+ name = Column(String(50))
146
+ app = LightApi()
147
+ app.register(User)
148
+ ```
149
+ *How to use:* Define your SQLAlchemy model, register it with `app.register()`, and LightAPI will expose full CRUD endpoints automatically.
150
+ *Use cases:* Quickly build admin panels, internal tools, or MVPs where you need instant API access to your data.
151
+
152
+ ## YAML-Driven API Generation (Database Reflection)
153
+ Point LightAPI at your existing database and expose tables as REST endpoints without writing model code. [Learn more about SQLAlchemy](https://www.sqlalchemy.org/).
154
+ ```yaml
155
+ # config.yaml
156
+ database_url: sqlite:///mydata.db
157
+ tables:
158
+ - name: users
159
+ crud: [get, post, put, patch, delete]
160
+ ```
161
+ ```python
162
+ from lightapi import LightApi
163
+ api = LightApi.from_config('config.yaml')
164
+ api.run()
165
+ ```
166
+ *How to use:* Create a YAML config describing your database and tables, then use `LightApi.from_config()` to generate endpoints instantly.
167
+ *Use cases:* Expose legacy or third-party databases as REST APIs for integration, analytics, or migration.
168
+
169
+ ## OpenAPI/Swagger Documentation
170
+ Get interactive API docs and OpenAPI JSON automatically, always in sync with your endpoints. [Learn more about OpenAPI](https://swagger.io/specification/).
171
+ ```python
172
+ app = LightApi(swagger_title="My API", swagger_version="1.0.0")
173
+ # Visit http://localhost:8000/docs
174
+ ```
175
+ *How to use:* Set Swagger options when creating your app. Docs are auto-generated and always up to date.
176
+ *Use cases:* Share your API with frontend teams, generate client SDKs, or provide public API documentation.
177
+
178
+ ## Works with All Major Databases
179
+ Use SQLite, PostgreSQL, MySQL, or any SQLAlchemy-supported backend. [SQLAlchemy Docs](https://docs.sqlalchemy.org/)
180
+ ```python
181
+ app = LightApi(database_url="postgresql://user:pass@localhost/db")
182
+ # or
183
+ app = LightApi(database_url="mysql://user:pass@localhost/db")
184
+ ```
185
+ *How to use:* Set the `database_url` parameter to match your database backend.
186
+ *Use cases:* Migrate between databases, support multiple environments, or connect to cloud-hosted DBs.
187
+
188
+ ## Environment-based Configuration
189
+ Configure your app for development, testing, or production using environment variables or YAML.
190
+ ```yaml
191
+ # config.yaml
192
+ database_url: sqlite:///dev.db
193
+ debug: true
194
+ ```
195
+ ```python
196
+ api = LightApi.from_config('config.yaml')
197
+ ```
198
+ *How to use:* Store your settings in a YAML file or environment variables, then load them with `from_config()` or `os.environ`.
199
+ *Use cases:* Seamlessly switch between dev, staging, and production setups, or deploy with Docker and CI/CD.
200
+
201
+ ## JWT Authentication and Security
202
+ Secure your API with industry-standard JSON Web Tokens, including login endpoints and protected resources. [Learn more about JWT](https://jwt.io/)
203
+ ```python
204
+ from lightapi.auth import JWTAuthentication
205
+ class UserEndpoint(RestEndpoint):
206
+ class Configuration:
207
+ authentication_class = JWTAuthentication
208
+ # Set secret
209
+ export LIGHTAPI_JWT_SECRET="supersecret"
210
+ ```
211
+ *How to use:* Add `authentication_class = JWTAuthentication` to your endpoint's Configuration. Set the secret key as an environment variable.
212
+ *Use cases:* Protect sensitive endpoints, implement login/logout, and control access for different user roles.
213
+
214
+ ## CORS Support for Python APIs
215
+ Easily enable Cross-Origin Resource Sharing for frontend/backend integration. [Learn more about CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
216
+ ```python
217
+ from lightapi.core import CORSMiddleware
218
+ app.add_middleware([CORSMiddleware])
219
+ ```
220
+ *How to use:* Add `CORSMiddleware` to your app's middleware list to allow cross-origin requests from browsers.
221
+ *Use cases:* Enable frontend apps (React, Vue, etc.) to call your API from a different domain during development or production.
222
+
223
+ ## Custom Middleware for Python APIs
224
+ Add logging, rate limiting, authentication, or any cross-cutting logic with a simple middleware interface.
225
+ ```python
226
+ from lightapi.core import Middleware
227
+ class LoggingMiddleware(Middleware):
228
+ def process(self, request, response=None):
229
+ print(f"{request.method} {request.url}")
230
+ return response
231
+ app.add_middleware([LoggingMiddleware])
232
+ ```
233
+ *How to use:* Subclass `Middleware` and implement the `process` method. Add your middleware to the app.
234
+ *Use cases:* Add request logging, enforce rate limits, or inject custom headers for all responses.
235
+
236
+ ## Async/Await Support for High-Performance Python APIs
237
+ Built on aiohttp for high concurrency and fast response times. All endpoints are async-ready; just use `async def` in your handlers. [Learn more about aiohttp](https://docs.aiohttp.org/)
238
+ ```python
239
+ class MyEndpoint(RestEndpoint):
240
+ async def get(self, request):
241
+ return {"message": "Async ready!"}
242
+ ```
243
+ *How to use:* Write your endpoint methods as `async def` to take full advantage of Python's async capabilities.
244
+ *Use cases:* Handle thousands of concurrent API requests, real-time dashboards, or chat/messaging backends.
245
+
246
+ ## Redis Caching for Python APIs
247
+ Speed up your API with automatic or custom caching of responses, including cache invalidation. [Learn more about Redis](https://redis.io/)
248
+ ```python
249
+ from lightapi.cache import RedisCache
250
+ class Product(RestEndpoint):
251
+ class Configuration:
252
+ caching_class = RedisCache
253
+ caching_method_names = ['GET']
254
+ ```
255
+ *How to use:* Set `caching_class = RedisCache` and specify which HTTP methods to cache. LightAPI will cache responses transparently.
256
+ *Use cases:* Reduce database load for expensive queries, speed up product catalogs, or cache public data.
257
+
258
+ ## Filtering, Pagination, and Sorting
259
+ Query your data efficiently with flexible filters, paginated results, and sort options.
260
+ ```python
261
+ from lightapi.filters import ParameterFilter
262
+ from lightapi.pagination import Paginator
263
+ class ProductFilter(ParameterFilter): ...
264
+ class ProductPaginator(Paginator): ...
265
+ class Product(RestEndpoint):
266
+ class Configuration:
267
+ filter_class = ProductFilter
268
+ pagination_class = ProductPaginator
269
+ ```
270
+ *How to use:* Implement custom filter and paginator classes, then assign them in your endpoint's Configuration.
271
+ *Use cases:* Build APIs for large datasets, searchable product listings, or analytics dashboards.
272
+
273
+ ## Request Validation
274
+ Validate incoming data with custom or automatic validators, returning clear error messages.
275
+ ```python
276
+ from lightapi.rest import Validator
277
+ class UserValidator(Validator):
278
+ def validate_name(self, value):
279
+ if not value:
280
+ raise ValueError('Name required')
281
+ return value
282
+ class User(RestEndpoint):
283
+ class Configuration:
284
+ validator_class = UserValidator
285
+ ```
286
+ *How to use:* Create a Validator class and assign it in your endpoint's Configuration. Validation errors are returned as 400 responses.
287
+ *Use cases:* Enforce business rules, prevent bad data, and provide user-friendly error messages in your API.
288
+
289
+ ## Type Hints & Modern Python
290
+ All code is type-annotated and follows modern Python best practices for maintainability and IDE support.
291
+
292
+ ## Comprehensive Error Handling
293
+ Detailed error messages and robust error handling are built in, making debugging and production support easier.
294
+
295
+ ---
296
+
297
+ # Quick Start: Build a Python REST API in Minutes
298
+
299
+ ## 1. Install LightAPI
300
+
301
+ ```bash
302
+ pip install lightapi
303
+ ```
304
+
305
+ ## 2. Define your model (SQLAlchemy)
306
+
307
+ ```python
308
+ from lightapi import LightApi
309
+ from lightapi.database import Base
310
+ from sqlalchemy import Column, Integer, String
311
+
312
+ class User(Base):
313
+ __tablename__ = "users"
314
+ id = Column(Integer, primary_key=True)
315
+ name = Column(String(50))
316
+ email = Column(String(100))
317
+
318
+ app = LightApi()
319
+ app.register(User)
320
+
321
+ if __name__ == "__main__":
322
+ app.run()
323
+ ```
324
+
325
+ ## 3. Or use YAML for instant API from your database
326
+
327
+ ```yaml
328
+ # config.yaml
329
+ database_url: sqlite:///mydata.db
330
+ tables:
331
+ - name: users
332
+ crud: [get, post, put, patch, delete]
333
+ - name: orders
334
+ crud: [get, post]
335
+ ```
336
+
337
+ ```python
338
+ from lightapi import LightApi
339
+ api = LightApi.from_config('config.yaml')
340
+ api.run(host="0.0.0.0", port=8081)
341
+ ```
342
+
343
+ ---
344
+
345
+ # Example Endpoints
346
+
347
+ - `GET /users/` - List users
348
+ - `POST /users/` - Create user
349
+ - `GET /users/{id}` - Get user by ID
350
+ - `PUT /users/{id}` - Replace user
351
+ - `PATCH /users/{id}` - Update user
352
+ - `DELETE /users/{id}` - Delete user
353
+ - `GET /orders/` - List orders
354
+ - `POST /orders/` - Create order
355
+ - `GET /orders/{id}` - Get order by ID
356
+
357
+ ---
358
+
359
+ # Documentation
360
+
361
+ - [Full Documentation](https://iklobato.github.io/lightapi/)
362
+ - [Getting Started](https://iklobato.github.io/lightapi/getting-started/installation/)
363
+ - [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
364
+ - [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
365
+ - [SQLAlchemy](https://www.sqlalchemy.org/)
366
+ - [aiohttp](https://docs.aiohttp.org/)
367
+ - [OpenAPI](https://swagger.io/specification/)
368
+ - [JWT](https://jwt.io/)
369
+ - [Redis](https://redis.io/)
370
+
371
+ ---
372
+
373
+ # FAQ
374
+
375
+ **Q: Can I use LightAPI with my existing database?**
376
+ A: Yes! Use the YAML config to reflect your schema and instantly expose REST endpoints.
377
+
378
+ **Q: What databases are supported?**
379
+ A: Any database supported by SQLAlchemy (PostgreSQL, MySQL, SQLite, etc.).
380
+
381
+ **Q: How do I secure my API?**
382
+ A: Enable JWT authentication and CORS with a single line.
383
+
384
+ **Q: Can I customize endpoints or add business logic?**
385
+ A: Yes, you can extend or override any handler, add middleware, and use validators.
386
+
387
+ **Q: Is this production-ready?**
388
+ A: Yes. LightAPI is designed for both rapid prototyping and production deployment.
389
+
390
+ ---
391
+
392
+ # Comparison
393
+
394
+ | Feature | LightAPI | FastAPI | Flask | Django REST |
395
+ |------------------------------------------|----------|---------|-------|-------------|
396
+ | Zero-boilerplate CRUD generation | ✅ | ❌ | ❌ | ❌ |
397
+ | YAML-driven API/config | ✅ | ❌ | ❌ | ❌ |
398
+ | Async/await support | ✅ | ✅ | ❌ | ❌ |
399
+ | Automatic OpenAPI/Swagger docs | ✅ | ✅ | ❌ | ✅ |
400
+ | JWT authentication (built-in) | ✅ | ❌ | ❌ | ✅ |
401
+ | CORS support (built-in) | ✅ | ✅ | ❌ | ✅ |
402
+ | Redis caching (built-in) | ✅ | ❌ | ❌ | ✅ |
403
+ | Request validation (customizable) | ✅ | ✅ | ❌ | ✅ |
404
+ | Filtering, pagination, sorting | ✅ | ✅ | ❌ | ✅ |
405
+ | Database reflection | ✅ | ❌ | ❌ | ❌ |
406
+ | Type hints & modern Python | ✅ | ✅ | ❌ | ✅ |
407
+ | Custom middleware | ✅ | ✅ | ✅ | ✅ |
408
+ | Environment-based configuration | ✅ | ✅ | ❌ | ✅ |
409
+ | Production-ready out of the box | ✅ | ✅ | ❌ | ✅ |
410
+
411
+ ---
412
+
413
+ # License
414
+
415
+ MIT License. See [LICENSE](LICENSE).
416
+
417
+ ---
418
+
419
+ > **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.
420
+ > To start your API, always use `api.run(host, port)`. Do not use external libraries or `app = api.app` to start the server directly.
421
+
422
+ ---
423
+
424
+ **LightAPI** - The fastest way to build Python REST APIs from your database.
425
+
426
+ ---
427
+
428
+ # Troubleshooting
429
+
430
+ ### ModuleNotFoundError: No module named 'lightapi'
431
+
432
+ If you see this error when running example scripts:
433
+
434
+ ```
435
+ Traceback (most recent call last):
436
+ File "examples/mega_example.py", line 22, in <module>
437
+ from lightapi.auth import JWTAuthentication
438
+ ModuleNotFoundError: No module named 'lightapi'
439
+ ```
440
+
441
+ **Solution:**
442
+ - Make sure you run the script from the project root directory, not from inside the `examples/` folder.
443
+ - Or, set the `PYTHONPATH` to include the project root:
444
+
445
+ ```bash
446
+ PYTHONPATH=. python3 examples/mega_example.py
447
+ ```
448
+
449
+ This ensures Python can find the `lightapi` package in your local project.