lightapi 0.1.7__tar.gz → 0.1.9__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 (119) hide show
  1. {lightapi-0.1.7 → lightapi-0.1.9}/PKG-INFO +129 -12
  2. lightapi-0.1.9/README.md +279 -0
  3. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/.pages +2 -3
  4. {lightapi-0.1.7 → lightapi-0.1.9}/pyproject.toml +1 -1
  5. lightapi-0.1.7/README.md +0 -162
  6. {lightapi-0.1.7 → lightapi-0.1.9}/.github/workflows/pages-publish.yml +0 -0
  7. {lightapi-0.1.7 → lightapi-0.1.9}/.github/workflows/python-publish.yml +0 -0
  8. {lightapi-0.1.7 → lightapi-0.1.9}/.github/workflows/test-dev.yml +0 -0
  9. {lightapi-0.1.7 → lightapi-0.1.9}/.gitignore +0 -0
  10. {lightapi-0.1.7 → lightapi-0.1.9}/LICENSE +0 -0
  11. {lightapi-0.1.7 → lightapi-0.1.9}/docs/.pages +0 -0
  12. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/.pages +0 -0
  13. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/authentication.md +0 -0
  14. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/caching.md +0 -0
  15. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/filtering.md +0 -0
  16. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/middleware.md +0 -0
  17. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/pagination.md +0 -0
  18. {lightapi-0.1.7 → lightapi-0.1.9}/docs/advanced/validation.md +0 -0
  19. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/.pages +0 -0
  20. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/auth.md +0 -0
  21. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/cache.md +0 -0
  22. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/core.md +0 -0
  23. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/database.md +0 -0
  24. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/exceptions.md +0 -0
  25. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/filters.md +0 -0
  26. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/index.md +0 -0
  27. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/models.md +0 -0
  28. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/pagination.md +0 -0
  29. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/rest.md +0 -0
  30. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/swagger.md +0 -0
  31. {lightapi-0.1.7 → lightapi-0.1.9}/docs/api-reference/validation.md +0 -0
  32. {lightapi-0.1.7 → lightapi-0.1.9}/docs/deployment/.pages +0 -0
  33. {lightapi-0.1.7 → lightapi-0.1.9}/docs/deployment/docker.md +0 -0
  34. {lightapi-0.1.7 → lightapi-0.1.9}/docs/deployment/production.md +0 -0
  35. {lightapi-0.1.7 → lightapi-0.1.9}/docs/deployment/security.md +0 -0
  36. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/auth.md +0 -0
  37. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/basic-crud.md +0 -0
  38. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/basic-rest.md +0 -0
  39. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/caching.md +0 -0
  40. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/custom-application.md +0 -0
  41. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/filtering-pagination.md +0 -0
  42. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/middleware.md +0 -0
  43. {lightapi-0.1.7 → lightapi-0.1.9}/docs/examples/validation.md +0 -0
  44. {lightapi-0.1.7 → lightapi-0.1.9}/docs/getting-started/.pages +0 -0
  45. {lightapi-0.1.7 → lightapi-0.1.9}/docs/getting-started/configuration.md +0 -0
  46. {lightapi-0.1.7 → lightapi-0.1.9}/docs/getting-started/first-steps.md +0 -0
  47. {lightapi-0.1.7 → lightapi-0.1.9}/docs/getting-started/installation.md +0 -0
  48. {lightapi-0.1.7 → lightapi-0.1.9}/docs/getting-started/introduction.md +0 -0
  49. {lightapi-0.1.7 → lightapi-0.1.9}/docs/getting-started/quickstart.md +0 -0
  50. {lightapi-0.1.7 → lightapi-0.1.9}/docs/index.md +0 -0
  51. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/.pages +0 -0
  52. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/cache.md +0 -0
  53. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/core-api.md +0 -0
  54. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/endpoints.md +0 -0
  55. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/handlers.md +0 -0
  56. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/middleware.md +0 -0
  57. {lightapi-0.1.7 → lightapi-0.1.9}/docs/technical-reference/models.md +0 -0
  58. {lightapi-0.1.7 → lightapi-0.1.9}/docs/troubleshooting.md +0 -0
  59. {lightapi-0.1.7 → lightapi-0.1.9}/docs/tutorial/.pages +0 -0
  60. {lightapi-0.1.7 → lightapi-0.1.9}/docs/tutorial/basic-api.md +0 -0
  61. {lightapi-0.1.7 → lightapi-0.1.9}/docs/tutorial/database.md +0 -0
  62. {lightapi-0.1.7 → lightapi-0.1.9}/docs/tutorial/endpoints.md +0 -0
  63. {lightapi-0.1.7 → lightapi-0.1.9}/docs/tutorial/requests.md +0 -0
  64. {lightapi-0.1.7 → lightapi-0.1.9}/docs/tutorial/responses.md +0 -0
  65. {lightapi-0.1.7 → lightapi-0.1.9}/examples/README.md +0 -0
  66. {lightapi-0.1.7 → lightapi-0.1.9}/examples/__init__.py +0 -0
  67. {lightapi-0.1.7 → lightapi-0.1.9}/examples/authentication_jwt.py +0 -0
  68. {lightapi-0.1.7 → lightapi-0.1.9}/examples/blog_post.py +0 -0
  69. {lightapi-0.1.7 → lightapi-0.1.9}/examples/caching_redis_custom.py +0 -0
  70. {lightapi-0.1.7 → lightapi-0.1.9}/examples/comprehensive_ideal_usage.py +0 -0
  71. {lightapi-0.1.7 → lightapi-0.1.9}/examples/example.py +0 -0
  72. {lightapi-0.1.7 → lightapi-0.1.9}/examples/filtering_pagination.py +0 -0
  73. {lightapi-0.1.7 → lightapi-0.1.9}/examples/general_usage.py +0 -0
  74. {lightapi-0.1.7 → lightapi-0.1.9}/examples/mega_example.py +0 -0
  75. {lightapi-0.1.7 → lightapi-0.1.9}/examples/middleware_cors_auth.py +0 -0
  76. {lightapi-0.1.7 → lightapi-0.1.9}/examples/middleware_custom.py +0 -0
  77. {lightapi-0.1.7 → lightapi-0.1.9}/examples/relationships_sqlalchemy.py +0 -0
  78. {lightapi-0.1.7 → lightapi-0.1.9}/examples/rest_crud_basic.py +0 -0
  79. {lightapi-0.1.7 → lightapi-0.1.9}/examples/swagger_openapi_docs.py +0 -0
  80. {lightapi-0.1.7 → lightapi-0.1.9}/examples/user_goal_example.py +0 -0
  81. {lightapi-0.1.7 → lightapi-0.1.9}/examples/validation_custom_fields.py +0 -0
  82. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/__init__.py +0 -0
  83. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/auth.py +0 -0
  84. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/base_endpoint.py +0 -0
  85. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/cache.py +0 -0
  86. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/config.py +0 -0
  87. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/core.py +0 -0
  88. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/database.py +0 -0
  89. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/exceptions.py +0 -0
  90. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/filters.py +0 -0
  91. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/handlers.py +0 -0
  92. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/lightapi.py +0 -0
  93. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/models.py +0 -0
  94. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/pagination.py +0 -0
  95. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/rest.py +0 -0
  96. {lightapi-0.1.7 → lightapi-0.1.9}/lightapi/swagger.py +0 -0
  97. {lightapi-0.1.7 → lightapi-0.1.9}/mkdocs.yml +0 -0
  98. {lightapi-0.1.7 → lightapi-0.1.9}/pytest.ini +0 -0
  99. {lightapi-0.1.7 → lightapi-0.1.9}/requirements.txt +0 -0
  100. {lightapi-0.1.7 → lightapi-0.1.9}/run_server.py +0 -0
  101. {lightapi-0.1.7 → lightapi-0.1.9}/tests/conftest.py +0 -0
  102. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_additional_features.py +0 -0
  103. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_auth.py +0 -0
  104. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_cache.py +0 -0
  105. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_caching_example.py +0 -0
  106. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_core.py +0 -0
  107. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_custom_snippet.py +0 -0
  108. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_filtering_pagination_example.py +0 -0
  109. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_filters.py +0 -0
  110. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_from_config.py +0 -0
  111. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_helpers.py +0 -0
  112. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_integration.py +0 -0
  113. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_middleware.py +0 -0
  114. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_pagination.py +0 -0
  115. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_rest.py +0 -0
  116. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_swagger.py +0 -0
  117. {lightapi-0.1.7 → lightapi-0.1.9}/tests/test_validators.py +0 -0
  118. {lightapi-0.1.7 → lightapi-0.1.9}/update_version.py +0 -0
  119. {lightapi-0.1.7 → lightapi-0.1.9}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lightapi
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: A lightweight framework for building API endpoints using Python's native libraries.
5
5
  Project-URL: Repository, https://github.com/henriqueblobato/LightApi
6
6
  Project-URL: Issues, https://github.com/henriqueblobato/LightApi/issues
@@ -83,17 +83,134 @@ Description-Content-Type: text/markdown
83
83
 
84
84
  ## Features
85
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**
86
+ Each feature explained:
87
+ - **Automatic CRUD endpoints**: Instantly generate RESTful endpoints for your models or tables, so you can create, read, update, and delete records with no manual wiring.
88
+ ```python
89
+ from lightapi import LightApi
90
+ from sqlalchemy import Column, Integer, String
91
+ class User(Base):
92
+ __tablename__ = 'users'
93
+ id = Column(Integer, primary_key=True)
94
+ name = Column(String(50))
95
+ app = LightApi()
96
+ app.register(User)
97
+ ```
98
+ *How to use:* Define your SQLAlchemy model, register it with `app.register()`, and LightAPI will expose full CRUD endpoints automatically.
99
+ *Use cases:* Quickly build admin panels, internal tools, or MVPs where you need instant API access to your data.
100
+ - **Database reflection**: Point LightAPI at your existing database and expose tables as REST endpoints without writing model code.
101
+ ```python
102
+ # config.yaml
103
+ database_url: sqlite:///mydata.db
104
+ tables:
105
+ - name: users
106
+ crud: [get, post, put, patch, delete]
107
+ # Python
108
+ from lightapi import LightApi
109
+ api = LightApi.from_config('config.yaml')
110
+ api.run()
111
+ ```
112
+ *How to use:* Create a YAML config describing your database and tables, then use `LightApi.from_config()` to generate endpoints instantly.
113
+ *Use cases:* Expose legacy or third-party databases as REST APIs for integration, analytics, or migration.
114
+ - **JWT authentication**: Secure your API with industry-standard JSON Web Tokens, including login endpoints and protected resources.
115
+ ```python
116
+ from lightapi.auth import JWTAuthentication
117
+ class UserEndpoint(RestEndpoint):
118
+ class Configuration:
119
+ authentication_class = JWTAuthentication
120
+ # Set secret
121
+ export LIGHTAPI_JWT_SECRET="supersecret"
122
+ ```
123
+ *How to use:* Add `authentication_class = JWTAuthentication` to your endpoint's Configuration. Set the secret key as an environment variable.
124
+ *Use cases:* Protect sensitive endpoints, implement login/logout, and control access for different user roles.
125
+ - **CORS support**: Easily enable Cross-Origin Resource Sharing for frontend/backend integration.
126
+ ```python
127
+ from lightapi.core import CORSMiddleware
128
+ app.add_middleware([CORSMiddleware])
129
+ ```
130
+ *How to use:* Add `CORSMiddleware` to your app's middleware list to allow cross-origin requests from browsers.
131
+ *Use cases:* Enable frontend apps (React, Vue, etc.) to call your API from a different domain during development or production.
132
+ - **Async performance**: Built on aiohttp for high concurrency and fast response times.
133
+ ```python
134
+ # All endpoints are async-ready; just use async def in your handlers.
135
+ class MyEndpoint(RestEndpoint):
136
+ async def get(self, request):
137
+ return {"message": "Async ready!"}
138
+ ```
139
+ *How to use:* Write your endpoint methods as `async def` to take full advantage of Python's async capabilities.
140
+ *Use cases:* Handle thousands of concurrent API requests, real-time dashboards, or chat/messaging backends.
141
+ - **Redis caching**: Speed up your API with automatic or custom caching of responses, including cache invalidation.
142
+ ```python
143
+ from lightapi.cache import RedisCache
144
+ class Product(RestEndpoint):
145
+ class Configuration:
146
+ caching_class = RedisCache
147
+ caching_method_names = ['GET']
148
+ ```
149
+ *How to use:* Set `caching_class = RedisCache` and specify which HTTP methods to cache. LightAPI will cache responses transparently.
150
+ *Use cases:* Reduce database load for expensive queries, speed up product catalogs, or cache public data.
151
+ - **Request validation**: Validate incoming data with custom or automatic validators, returning clear error messages.
152
+ ```python
153
+ from lightapi.rest import Validator
154
+ class UserValidator(Validator):
155
+ def validate_name(self, value):
156
+ if not value:
157
+ raise ValueError('Name required')
158
+ return value
159
+ class User(RestEndpoint):
160
+ class Configuration:
161
+ validator_class = UserValidator
162
+ ```
163
+ *How to use:* Create a Validator class and assign it in your endpoint's Configuration. Validation errors are returned as 400 responses.
164
+ *Use cases:* Enforce business rules, prevent bad data, and provide user-friendly error messages in your API.
165
+ - **Filtering, pagination, and sorting**: Query your data efficiently with flexible filters, paginated results, and sort options.
166
+ ```python
167
+ from lightapi.filters import ParameterFilter
168
+ from lightapi.pagination import Paginator
169
+ class ProductFilter(ParameterFilter): ...
170
+ class ProductPaginator(Paginator): ...
171
+ class Product(RestEndpoint):
172
+ class Configuration:
173
+ filter_class = ProductFilter
174
+ pagination_class = ProductPaginator
175
+ ```
176
+ *How to use:* Implement custom filter and paginator classes, then assign them in your endpoint's Configuration.
177
+ *Use cases:* Build APIs for large datasets, searchable product listings, or analytics dashboards.
178
+ - **OpenAPI/Swagger documentation**: Get interactive API docs and OpenAPI JSON automatically, always in sync with your endpoints.
179
+ ```python
180
+ app = LightApi(swagger_title="My API", swagger_version="1.0.0")
181
+ # Visit http://localhost:8000/docs
182
+ ```
183
+ *How to use:* Set Swagger options when creating your app. Docs are auto-generated and always up to date.
184
+ *Use cases:* Share your API with frontend teams, generate client SDKs, or provide public API documentation.
185
+ - **Custom middleware**: Add logging, rate limiting, authentication, or any cross-cutting logic with a simple middleware interface.
186
+ ```python
187
+ from lightapi.core import Middleware
188
+ class LoggingMiddleware(Middleware):
189
+ def process(self, request, response=None):
190
+ print(f"{request.method} {request.url}")
191
+ return response
192
+ app.add_middleware([LoggingMiddleware])
193
+ ```
194
+ *How to use:* Subclass `Middleware` and implement the `process` method. Add your middleware to the app.
195
+ *Use cases:* Add request logging, enforce rate limits, or inject custom headers for all responses.
196
+ - **Works with all major databases**: Use SQLite, PostgreSQL, MySQL, or any SQLAlchemy-supported backend.
197
+ ```python
198
+ app = LightApi(database_url="postgresql://user:pass@localhost/db")
199
+ # or
200
+ app = LightApi(database_url="mysql://user:pass@localhost/db")
201
+ ```
202
+ *How to use:* Set the `database_url` parameter to match your database backend.
203
+ *Use cases:* Migrate between databases, support multiple environments, or connect to cloud-hosted DBs.
204
+ - **Environment-based configuration**: Configure your app for development, testing, or production using environment variables or YAML.
205
+ ```python
206
+ # config.yaml
207
+ database_url: sqlite:///dev.db
208
+ debug: true
209
+ # Python
210
+ api = LightApi.from_config('config.yaml')
211
+ ```
212
+ *How to use:* Store your settings in a YAML file or environment variables, then load them with `from_config()` or `os.environ`.
213
+ *Use cases:* Seamlessly switch between dev, staging, and production setups, or deploy with Docker and CI/CD.
97
214
 
98
215
  ---
99
216
 
@@ -0,0 +1,279 @@
1
+ # LightAPI: Instant Python REST APIs from SQL Databases
2
+
3
+ [![PyPI version](https://badge.fury.io/py/lightapi.svg)](https://pypi.org/project/lightapi/)
4
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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
+ Each feature explained:
35
+ - **Automatic CRUD endpoints**: Instantly generate RESTful endpoints for your models or tables, so you can create, read, update, and delete records with no manual wiring.
36
+ ```python
37
+ from lightapi import LightApi
38
+ from sqlalchemy import Column, Integer, String
39
+ class User(Base):
40
+ __tablename__ = 'users'
41
+ id = Column(Integer, primary_key=True)
42
+ name = Column(String(50))
43
+ app = LightApi()
44
+ app.register(User)
45
+ ```
46
+ *How to use:* Define your SQLAlchemy model, register it with `app.register()`, and LightAPI will expose full CRUD endpoints automatically.
47
+ *Use cases:* Quickly build admin panels, internal tools, or MVPs where you need instant API access to your data.
48
+ - **Database reflection**: Point LightAPI at your existing database and expose tables as REST endpoints without writing model code.
49
+ ```python
50
+ # config.yaml
51
+ database_url: sqlite:///mydata.db
52
+ tables:
53
+ - name: users
54
+ crud: [get, post, put, patch, delete]
55
+ # Python
56
+ from lightapi import LightApi
57
+ api = LightApi.from_config('config.yaml')
58
+ api.run()
59
+ ```
60
+ *How to use:* Create a YAML config describing your database and tables, then use `LightApi.from_config()` to generate endpoints instantly.
61
+ *Use cases:* Expose legacy or third-party databases as REST APIs for integration, analytics, or migration.
62
+ - **JWT authentication**: Secure your API with industry-standard JSON Web Tokens, including login endpoints and protected resources.
63
+ ```python
64
+ from lightapi.auth import JWTAuthentication
65
+ class UserEndpoint(RestEndpoint):
66
+ class Configuration:
67
+ authentication_class = JWTAuthentication
68
+ # Set secret
69
+ export LIGHTAPI_JWT_SECRET="supersecret"
70
+ ```
71
+ *How to use:* Add `authentication_class = JWTAuthentication` to your endpoint's Configuration. Set the secret key as an environment variable.
72
+ *Use cases:* Protect sensitive endpoints, implement login/logout, and control access for different user roles.
73
+ - **CORS support**: Easily enable Cross-Origin Resource Sharing for frontend/backend integration.
74
+ ```python
75
+ from lightapi.core import CORSMiddleware
76
+ app.add_middleware([CORSMiddleware])
77
+ ```
78
+ *How to use:* Add `CORSMiddleware` to your app's middleware list to allow cross-origin requests from browsers.
79
+ *Use cases:* Enable frontend apps (React, Vue, etc.) to call your API from a different domain during development or production.
80
+ - **Async performance**: Built on aiohttp for high concurrency and fast response times.
81
+ ```python
82
+ # All endpoints are async-ready; just use async def in your handlers.
83
+ class MyEndpoint(RestEndpoint):
84
+ async def get(self, request):
85
+ return {"message": "Async ready!"}
86
+ ```
87
+ *How to use:* Write your endpoint methods as `async def` to take full advantage of Python's async capabilities.
88
+ *Use cases:* Handle thousands of concurrent API requests, real-time dashboards, or chat/messaging backends.
89
+ - **Redis caching**: Speed up your API with automatic or custom caching of responses, including cache invalidation.
90
+ ```python
91
+ from lightapi.cache import RedisCache
92
+ class Product(RestEndpoint):
93
+ class Configuration:
94
+ caching_class = RedisCache
95
+ caching_method_names = ['GET']
96
+ ```
97
+ *How to use:* Set `caching_class = RedisCache` and specify which HTTP methods to cache. LightAPI will cache responses transparently.
98
+ *Use cases:* Reduce database load for expensive queries, speed up product catalogs, or cache public data.
99
+ - **Request validation**: Validate incoming data with custom or automatic validators, returning clear error messages.
100
+ ```python
101
+ from lightapi.rest import Validator
102
+ class UserValidator(Validator):
103
+ def validate_name(self, value):
104
+ if not value:
105
+ raise ValueError('Name required')
106
+ return value
107
+ class User(RestEndpoint):
108
+ class Configuration:
109
+ validator_class = UserValidator
110
+ ```
111
+ *How to use:* Create a Validator class and assign it in your endpoint's Configuration. Validation errors are returned as 400 responses.
112
+ *Use cases:* Enforce business rules, prevent bad data, and provide user-friendly error messages in your API.
113
+ - **Filtering, pagination, and sorting**: Query your data efficiently with flexible filters, paginated results, and sort options.
114
+ ```python
115
+ from lightapi.filters import ParameterFilter
116
+ from lightapi.pagination import Paginator
117
+ class ProductFilter(ParameterFilter): ...
118
+ class ProductPaginator(Paginator): ...
119
+ class Product(RestEndpoint):
120
+ class Configuration:
121
+ filter_class = ProductFilter
122
+ pagination_class = ProductPaginator
123
+ ```
124
+ *How to use:* Implement custom filter and paginator classes, then assign them in your endpoint's Configuration.
125
+ *Use cases:* Build APIs for large datasets, searchable product listings, or analytics dashboards.
126
+ - **OpenAPI/Swagger documentation**: Get interactive API docs and OpenAPI JSON automatically, always in sync with your endpoints.
127
+ ```python
128
+ app = LightApi(swagger_title="My API", swagger_version="1.0.0")
129
+ # Visit http://localhost:8000/docs
130
+ ```
131
+ *How to use:* Set Swagger options when creating your app. Docs are auto-generated and always up to date.
132
+ *Use cases:* Share your API with frontend teams, generate client SDKs, or provide public API documentation.
133
+ - **Custom middleware**: Add logging, rate limiting, authentication, or any cross-cutting logic with a simple middleware interface.
134
+ ```python
135
+ from lightapi.core import Middleware
136
+ class LoggingMiddleware(Middleware):
137
+ def process(self, request, response=None):
138
+ print(f"{request.method} {request.url}")
139
+ return response
140
+ app.add_middleware([LoggingMiddleware])
141
+ ```
142
+ *How to use:* Subclass `Middleware` and implement the `process` method. Add your middleware to the app.
143
+ *Use cases:* Add request logging, enforce rate limits, or inject custom headers for all responses.
144
+ - **Works with all major databases**: Use SQLite, PostgreSQL, MySQL, or any SQLAlchemy-supported backend.
145
+ ```python
146
+ app = LightApi(database_url="postgresql://user:pass@localhost/db")
147
+ # or
148
+ app = LightApi(database_url="mysql://user:pass@localhost/db")
149
+ ```
150
+ *How to use:* Set the `database_url` parameter to match your database backend.
151
+ *Use cases:* Migrate between databases, support multiple environments, or connect to cloud-hosted DBs.
152
+ - **Environment-based configuration**: Configure your app for development, testing, or production using environment variables or YAML.
153
+ ```python
154
+ # config.yaml
155
+ database_url: sqlite:///dev.db
156
+ debug: true
157
+ # Python
158
+ api = LightApi.from_config('config.yaml')
159
+ ```
160
+ *How to use:* Store your settings in a YAML file or environment variables, then load them with `from_config()` or `os.environ`.
161
+ *Use cases:* Seamlessly switch between dev, staging, and production setups, or deploy with Docker and CI/CD.
162
+
163
+ ---
164
+
165
+ ## Quick Start
166
+
167
+ ### 1. Install LightAPI
168
+
169
+ ```bash
170
+ pip install lightapi
171
+ ```
172
+
173
+ ### 2. Define your model (SQLAlchemy)
174
+
175
+ ```python
176
+ from lightapi import LightApi
177
+ from lightapi.database import Base
178
+ from sqlalchemy import Column, Integer, String
179
+
180
+ class User(Base):
181
+ __tablename__ = "users"
182
+ id = Column(Integer, primary_key=True)
183
+ name = Column(String(50))
184
+ email = Column(String(100))
185
+
186
+ app = LightApi()
187
+ app.register(User)
188
+
189
+ if __name__ == "__main__":
190
+ app.run()
191
+ ```
192
+
193
+ ### 3. Or use YAML for instant API from your database
194
+
195
+ ```yaml
196
+ # config.yaml
197
+ database_url: sqlite:///mydata.db
198
+ tables:
199
+ - name: users
200
+ crud: [get, post, put, patch, delete]
201
+ - name: orders
202
+ crud: [get, post]
203
+ ```
204
+
205
+ ```python
206
+ from lightapi import LightApi
207
+ api = LightApi.from_config('config.yaml')
208
+ api.run(host="0.0.0.0", port=8081)
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Example Endpoints (from YAML above)
214
+
215
+ - `GET /users/` - List users
216
+ - `POST /users/` - Create user
217
+ - `GET /users/{id}` - Get user by ID
218
+ - `PUT /users/{id}` - Replace user
219
+ - `PATCH /users/{id}` - Update user
220
+ - `DELETE /users/{id}` - Delete user
221
+ - `GET /orders/` - List orders
222
+ - `POST /orders/` - Create order
223
+ - `GET /orders/{id}` - Get order by ID
224
+
225
+ ---
226
+
227
+ ## Documentation
228
+
229
+ - [Full Documentation](https://iklobato.github.io/lightapi/)
230
+ - [Getting Started](https://iklobato.github.io/lightapi/getting-started/installation/)
231
+ - [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
232
+ - [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
233
+
234
+ ---
235
+
236
+ ## FAQ
237
+
238
+ **Q: Can I use LightAPI with my existing database?**
239
+ A: Yes! Use the YAML config to reflect your schema and instantly expose REST endpoints.
240
+
241
+ **Q: What databases are supported?**
242
+ A: Any database supported by SQLAlchemy (PostgreSQL, MySQL, SQLite, etc.).
243
+
244
+ **Q: How do I secure my API?**
245
+ A: Enable JWT authentication and CORS with a single line.
246
+
247
+ **Q: Can I customize endpoints or add business logic?**
248
+ A: Yes, you can extend or override any handler, add middleware, and use validators.
249
+
250
+ **Q: Is this production-ready?**
251
+ A: Yes. LightAPI is designed for both rapid prototyping and production deployment.
252
+
253
+ ---
254
+
255
+ ## Comparison
256
+
257
+ | Feature | LightAPI | FastAPI | Flask | Django REST |
258
+ |------------------------|----------|--------|-------|-------------|
259
+ | Zero-boilerplate CRUD | ✅ | ❌ | ❌ | ❌ |
260
+ | YAML-driven API | ✅ | ❌ | ❌ | ❌ |
261
+ | Async support | ✅ | ✅ | ❌ | ❌ |
262
+ | OpenAPI docs | ✅ | ✅ | ❌ | ✅ |
263
+ | Built-in Auth/Caching | ✅ | ❌ | ❌ | ✅ |
264
+ | DB Reflection | ✅ | ❌ | ❌ | ❌ |
265
+
266
+ ---
267
+
268
+ ## License
269
+
270
+ MIT License. See [LICENSE](LICENSE).
271
+
272
+ ---
273
+
274
+ > **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.
275
+ > To start your API, always use `api.run(host, port)`. Do not use external libraries or `app = api.app` to start the server directly.
276
+
277
+ ---
278
+
279
+ **LightAPI** - *The fastest way to build Python REST APIs from your database.*
@@ -6,7 +6,6 @@ nav:
6
6
  - Caching: caching.md
7
7
  - Filtering and Pagination: filtering-pagination.md
8
8
  - Middleware: middleware.md
9
- - Relationships: relationships.md
10
- - Swagger Documentation: swagger.md
11
9
  - Validation: validation.md
12
- - Custom Snippets: custom-snippets.md
10
+ - Custom Application: custom-application.md
11
+ - Basic CRUD: basic-crud.md
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "lightapi"
9
- version = "0.1.7"
9
+ version = "0.1.9"
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.7/README.md DELETED
@@ -1,162 +0,0 @@
1
- # LightAPI: Instant Python REST APIs from SQL Databases
2
-
3
- [![PyPI version](https://badge.fury.io/py/lightapi.svg)](https://pypi.org/project/lightapi/)
4
- [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.*
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes