lightapi 0.1.3__tar.gz → 0.1.4__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 (124) hide show
  1. {lightapi-0.1.3 → lightapi-0.1.4}/PKG-INFO +71 -1
  2. {lightapi-0.1.3 → lightapi-0.1.4}/README.md +69 -0
  3. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/auth.md +4 -2
  4. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/cache.md +3 -1
  5. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/core.md +3 -1
  6. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/models.md +3 -1
  7. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/rest.md +7 -3
  8. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/auth.md +3 -1
  9. {lightapi-0.1.3 → lightapi-0.1.4}/docs/getting-started/configuration.md +26 -0
  10. lightapi-0.1.4/docs/getting-started/quickstart.md +93 -0
  11. {lightapi-0.1.3 → lightapi-0.1.4}/docs/index.md +9 -3
  12. {lightapi-0.1.3 → lightapi-0.1.4}/examples/README.md +4 -1
  13. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/__init__.py +1 -1
  14. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/handlers.py +133 -83
  15. lightapi-0.1.4/lightapi/lightapi.py +340 -0
  16. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/models.py +26 -0
  17. {lightapi-0.1.3 → lightapi-0.1.4}/pyproject.toml +2 -1
  18. {lightapi-0.1.3 → lightapi-0.1.4}/requirements.txt +2 -1
  19. lightapi-0.1.4/run_server.py +8 -0
  20. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_basic_rest_api.py +0 -25
  21. lightapi-0.1.4/tests/test_from_config.py +932 -0
  22. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_middleware_example.py +0 -19
  23. lightapi-0.1.3/.idx/dev.nix +0 -38
  24. lightapi-0.1.3/docs/getting-started/quickstart.md +0 -47
  25. lightapi-0.1.3/lightapi/lightapi.py +0 -110
  26. lightapi-0.1.3/test_simple_response.py +0 -16
  27. {lightapi-0.1.3 → lightapi-0.1.4}/.github/workflows/pages-publish.yml +0 -0
  28. {lightapi-0.1.3 → lightapi-0.1.4}/.github/workflows/python-publish.yml +0 -0
  29. {lightapi-0.1.3 → lightapi-0.1.4}/.github/workflows/test-dev.yml +0 -0
  30. {lightapi-0.1.3 → lightapi-0.1.4}/.gitignore +0 -0
  31. {lightapi-0.1.3 → lightapi-0.1.4}/LICENSE +0 -0
  32. {lightapi-0.1.3 → lightapi-0.1.4}/docs/.pages +0 -0
  33. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/.pages +0 -0
  34. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/authentication.md +0 -0
  35. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/caching.md +0 -0
  36. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/filtering.md +0 -0
  37. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/middleware.md +0 -0
  38. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/pagination.md +0 -0
  39. {lightapi-0.1.3 → lightapi-0.1.4}/docs/advanced/validation.md +0 -0
  40. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/.pages +0 -0
  41. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/database.md +0 -0
  42. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/exceptions.md +0 -0
  43. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/filters.md +0 -0
  44. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/index.md +0 -0
  45. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/pagination.md +0 -0
  46. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/swagger.md +0 -0
  47. {lightapi-0.1.3 → lightapi-0.1.4}/docs/api-reference/validation.md +0 -0
  48. {lightapi-0.1.3 → lightapi-0.1.4}/docs/deployment/.pages +0 -0
  49. {lightapi-0.1.3 → lightapi-0.1.4}/docs/deployment/docker.md +0 -0
  50. {lightapi-0.1.3 → lightapi-0.1.4}/docs/deployment/production.md +0 -0
  51. {lightapi-0.1.3 → lightapi-0.1.4}/docs/deployment/security.md +0 -0
  52. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/.pages +0 -0
  53. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/basic-crud.md +0 -0
  54. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/basic-rest.md +0 -0
  55. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/caching.md +0 -0
  56. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/custom-application.md +0 -0
  57. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/filtering-pagination.md +0 -0
  58. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/middleware.md +0 -0
  59. {lightapi-0.1.3 → lightapi-0.1.4}/docs/examples/validation.md +0 -0
  60. {lightapi-0.1.3 → lightapi-0.1.4}/docs/getting-started/.pages +0 -0
  61. {lightapi-0.1.3 → lightapi-0.1.4}/docs/getting-started/first-steps.md +0 -0
  62. {lightapi-0.1.3 → lightapi-0.1.4}/docs/getting-started/installation.md +0 -0
  63. {lightapi-0.1.3 → lightapi-0.1.4}/docs/getting-started/introduction.md +0 -0
  64. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/.pages +0 -0
  65. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/cache.md +0 -0
  66. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/core-api.md +0 -0
  67. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/endpoints.md +0 -0
  68. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/handlers.md +0 -0
  69. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/middleware.md +0 -0
  70. {lightapi-0.1.3 → lightapi-0.1.4}/docs/technical-reference/models.md +0 -0
  71. {lightapi-0.1.3 → lightapi-0.1.4}/docs/troubleshooting.md +0 -0
  72. {lightapi-0.1.3 → lightapi-0.1.4}/docs/tutorial/.pages +0 -0
  73. {lightapi-0.1.3 → lightapi-0.1.4}/docs/tutorial/basic-api.md +0 -0
  74. {lightapi-0.1.3 → lightapi-0.1.4}/docs/tutorial/database.md +0 -0
  75. {lightapi-0.1.3 → lightapi-0.1.4}/docs/tutorial/endpoints.md +0 -0
  76. {lightapi-0.1.3 → lightapi-0.1.4}/docs/tutorial/requests.md +0 -0
  77. {lightapi-0.1.3 → lightapi-0.1.4}/docs/tutorial/responses.md +0 -0
  78. {lightapi-0.1.3 → lightapi-0.1.4}/examples/__init__.py +0 -0
  79. {lightapi-0.1.3 → lightapi-0.1.4}/examples/auth_example.py +0 -0
  80. {lightapi-0.1.3 → lightapi-0.1.4}/examples/basic_rest_api.py +0 -0
  81. {lightapi-0.1.3 → lightapi-0.1.4}/examples/caching_example.py +0 -0
  82. {lightapi-0.1.3 → lightapi-0.1.4}/examples/custom_snippet.py +0 -0
  83. {lightapi-0.1.3 → lightapi-0.1.4}/examples/example.py +0 -0
  84. {lightapi-0.1.3 → lightapi-0.1.4}/examples/filtering_pagination_example.py +0 -0
  85. {lightapi-0.1.3 → lightapi-0.1.4}/examples/middleware_example.py +0 -0
  86. {lightapi-0.1.3 → lightapi-0.1.4}/examples/relationships_example.py +0 -0
  87. {lightapi-0.1.3 → lightapi-0.1.4}/examples/swagger_example.py +0 -0
  88. {lightapi-0.1.3 → lightapi-0.1.4}/examples/user_goal_example.py +0 -0
  89. {lightapi-0.1.3 → lightapi-0.1.4}/examples/validation_example.py +0 -0
  90. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/auth.py +0 -0
  91. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/base_endpoint.py +0 -0
  92. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/cache.py +0 -0
  93. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/config.py +0 -0
  94. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/core.py +0 -0
  95. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/database.py +0 -0
  96. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/exceptions.py +0 -0
  97. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/filters.py +0 -0
  98. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/pagination.py +0 -0
  99. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/rest.py +0 -0
  100. {lightapi-0.1.3 → lightapi-0.1.4}/lightapi/swagger.py +0 -0
  101. {lightapi-0.1.3 → lightapi-0.1.4}/mkdocs.yml +0 -0
  102. {lightapi-0.1.3 → lightapi-0.1.4}/pytest.ini +0 -0
  103. {lightapi-0.1.3 → lightapi-0.1.4}/tests/__init__.py +0 -0
  104. {lightapi-0.1.3 → lightapi-0.1.4}/tests/conftest.py +0 -0
  105. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_additional_features.py +0 -0
  106. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_auth.py +0 -0
  107. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_auth_example.py +0 -0
  108. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_cache.py +0 -0
  109. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_caching_example.py +0 -0
  110. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_clients.py +0 -0
  111. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_core.py +0 -0
  112. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_custom_snippet.py +0 -0
  113. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_example.py +0 -0
  114. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_filtering_pagination_example.py +0 -0
  115. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_filters.py +0 -0
  116. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_helpers.py +0 -0
  117. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_integration.py +0 -0
  118. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_middleware.py +0 -0
  119. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_pagination.py +0 -0
  120. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_rest.py +0 -0
  121. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_swagger.py +0 -0
  122. {lightapi-0.1.3 → lightapi-0.1.4}/tests/test_validation_example.py +0 -0
  123. {lightapi-0.1.3 → lightapi-0.1.4}/update_version.py +0 -0
  124. {lightapi-0.1.3 → lightapi-0.1.4}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lightapi
3
- Version: 0.1.3
3
+ Version: 0.1.4
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
@@ -22,6 +22,7 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
22
22
  Requires-Python: >=3.8.1
23
23
  Requires-Dist: aiohttp<4.0.0,>=3.9.5
24
24
  Requires-Dist: pyjwt<3.0.0,>=2.8.0
25
+ Requires-Dist: pyyaml>=5.1
25
26
  Requires-Dist: redis<6.0.0,>=5.0.0
26
27
  Requires-Dist: sqlalchemy<3.0.0,>=2.0.30
27
28
  Requires-Dist: starlette<1.0.0,>=0.37.0
@@ -112,6 +113,70 @@ That's it! You now have a fully functional REST API with:
112
113
  - `DELETE /users/{id}` - Delete user
113
114
  - `OPTIONS /users` - CORS preflight support
114
115
 
116
+ ## Dynamic API from YAML Config (SQLAlchemy Reflection)
117
+
118
+ LightAPI can instantly generate a REST API from a YAML configuration file, reflecting your database schema at runtime using SQLAlchemy. This is ideal for exposing existing databases with zero model code.
119
+
120
+ ### How It Works
121
+ - **Reflects** the schema of specified tables from your database (PostgreSQL, MySQL, SQLite, etc.)
122
+ - **Dynamically generates** SQLAlchemy models and CRUD endpoints for each table
123
+ - **Configurable**: You control which tables and which CRUD operations (GET, POST, PUT, PATCH, DELETE) are exposed
124
+ - **Composite primary keys, unique constraints, foreign keys, BLOBs, JSON, and more** are supported
125
+ - **Advanced edge cases** (triggers, generated columns, partial unique constraints, etc.) are handled
126
+
127
+ ### End-to-End Example
128
+
129
+ #### 1. Create a YAML Config
130
+ ```yaml
131
+ database_url: sqlite:///mydata.db
132
+
133
+ tables:
134
+ - name: users
135
+ crud: [get, post, put, patch, delete]
136
+ - name: orders
137
+ crud: [get, post]
138
+ ```
139
+
140
+ #### 2. Create Your Database (SQLite example)
141
+ ```bash
142
+ sqlite3 mydata.db "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE); CREATE TABLE orders (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, amount REAL NOT NULL, FOREIGN KEY(user_id) REFERENCES users(id));"
143
+ ```
144
+
145
+ #### 3. Start the API
146
+ ```python
147
+ from lightapi import LightApi
148
+ import aiohttp.web
149
+
150
+ api = LightApi.from_config('my_api_config.yaml')
151
+ app = api.app
152
+
153
+ aiohttp.web.run_app(app, port=8080)
154
+ ```
155
+
156
+ #### 4. Use the API (with curl)
157
+ ```bash
158
+ # Create a user
159
+ curl -X POST http://localhost:8080/users/ -H 'Content-Type: application/json' -d '{"name": "Alice", "email": "alice@example.com"}'
160
+
161
+ # List users
162
+ curl http://localhost:8080/users/
163
+
164
+ # Create an order for Alice (id=1)
165
+ curl -X POST http://localhost:8080/orders/ -H 'Content-Type: application/json' -d '{"user_id": 1, "amount": 42.5}'
166
+
167
+ # List orders
168
+ curl http://localhost:8080/orders/
169
+ ```
170
+
171
+ ### FAQ & Tips
172
+ - **Server-side defaults**: Only `server_default` (e.g., `server_default=text('...')`) are available after reflection. Python-side defaults are not reflected.
173
+ - **Composite PKs**: Supported transparently in routes and handlers.
174
+ - **Error handling**: Unique, check, not null, and foreign key constraints are enforced. Violations return 409 Conflict with details.
175
+ - **Partial CRUD**: You can expose only the operations you want per table.
176
+ - **Supported DBs**: Any DB supported by SQLAlchemy reflection (PostgreSQL, MySQL, SQLite, etc.)
177
+
178
+ See the [docs](./docs/getting-started/quickstart.md#dynamic-api-from-yaml-config-sqlalchemy-reflection) for more advanced examples and details.
179
+
115
180
  ## Documentation
116
181
 
117
182
  Visit our comprehensive documentation at: https://iklobato.github.io/lightapi/
@@ -158,6 +223,9 @@ class UserValidator(Validator):
158
223
  app.register(User, validator=UserValidator())
159
224
  ```
160
225
 
226
+ - All required fields must be defined as NOT NULL in your database schema for correct enforcement.
227
+ - 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.
228
+
161
229
  ### Middleware
162
230
 
163
231
  ```python
@@ -205,3 +273,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
205
273
  **LightAPI** - *Making web APIs light and fast* ⚡
206
274
 
207
275
  <!-- Testing development pipeline -->
276
+
277
+ > **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.
@@ -61,6 +61,70 @@ That's it! You now have a fully functional REST API with:
61
61
  - `DELETE /users/{id}` - Delete user
62
62
  - `OPTIONS /users` - CORS preflight support
63
63
 
64
+ ## Dynamic API from YAML Config (SQLAlchemy Reflection)
65
+
66
+ LightAPI can instantly generate a REST API from a YAML configuration file, reflecting your database schema at runtime using SQLAlchemy. This is ideal for exposing existing databases with zero model code.
67
+
68
+ ### How It Works
69
+ - **Reflects** the schema of specified tables from your database (PostgreSQL, MySQL, SQLite, etc.)
70
+ - **Dynamically generates** SQLAlchemy models and CRUD endpoints for each table
71
+ - **Configurable**: You control which tables and which CRUD operations (GET, POST, PUT, PATCH, DELETE) are exposed
72
+ - **Composite primary keys, unique constraints, foreign keys, BLOBs, JSON, and more** are supported
73
+ - **Advanced edge cases** (triggers, generated columns, partial unique constraints, etc.) are handled
74
+
75
+ ### End-to-End Example
76
+
77
+ #### 1. Create a YAML Config
78
+ ```yaml
79
+ database_url: sqlite:///mydata.db
80
+
81
+ tables:
82
+ - name: users
83
+ crud: [get, post, put, patch, delete]
84
+ - name: orders
85
+ crud: [get, post]
86
+ ```
87
+
88
+ #### 2. Create Your Database (SQLite example)
89
+ ```bash
90
+ sqlite3 mydata.db "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE); CREATE TABLE orders (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, amount REAL NOT NULL, FOREIGN KEY(user_id) REFERENCES users(id));"
91
+ ```
92
+
93
+ #### 3. Start the API
94
+ ```python
95
+ from lightapi import LightApi
96
+ import aiohttp.web
97
+
98
+ api = LightApi.from_config('my_api_config.yaml')
99
+ app = api.app
100
+
101
+ aiohttp.web.run_app(app, port=8080)
102
+ ```
103
+
104
+ #### 4. Use the API (with curl)
105
+ ```bash
106
+ # Create a user
107
+ curl -X POST http://localhost:8080/users/ -H 'Content-Type: application/json' -d '{"name": "Alice", "email": "alice@example.com"}'
108
+
109
+ # List users
110
+ curl http://localhost:8080/users/
111
+
112
+ # Create an order for Alice (id=1)
113
+ curl -X POST http://localhost:8080/orders/ -H 'Content-Type: application/json' -d '{"user_id": 1, "amount": 42.5}'
114
+
115
+ # List orders
116
+ curl http://localhost:8080/orders/
117
+ ```
118
+
119
+ ### FAQ & Tips
120
+ - **Server-side defaults**: Only `server_default` (e.g., `server_default=text('...')`) are available after reflection. Python-side defaults are not reflected.
121
+ - **Composite PKs**: Supported transparently in routes and handlers.
122
+ - **Error handling**: Unique, check, not null, and foreign key constraints are enforced. Violations return 409 Conflict with details.
123
+ - **Partial CRUD**: You can expose only the operations you want per table.
124
+ - **Supported DBs**: Any DB supported by SQLAlchemy reflection (PostgreSQL, MySQL, SQLite, etc.)
125
+
126
+ See the [docs](./docs/getting-started/quickstart.md#dynamic-api-from-yaml-config-sqlalchemy-reflection) for more advanced examples and details.
127
+
64
128
  ## Documentation
65
129
 
66
130
  Visit our comprehensive documentation at: https://iklobato.github.io/lightapi/
@@ -107,6 +171,9 @@ class UserValidator(Validator):
107
171
  app.register(User, validator=UserValidator())
108
172
  ```
109
173
 
174
+ - All required fields must be defined as NOT NULL in your database schema for correct enforcement.
175
+ - 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.
176
+
110
177
  ### Middleware
111
178
 
112
179
  ```python
@@ -154,3 +221,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
154
221
  **LightAPI** - *Making web APIs light and fast* ⚡
155
222
 
156
223
  <!-- Testing development pipeline -->
224
+
225
+ > **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.
@@ -555,7 +555,7 @@ class DebugAuth(JWTAuthentication):
555
555
 
556
556
  result = super().authenticate(request)
557
557
  print(f"Auth result: {result}")
558
-
558
+
559
559
  if hasattr(request.state, 'user'):
560
560
  print(f"User: {request.state.user}")
561
561
 
@@ -566,4 +566,6 @@ class DebugAuth(JWTAuthentication):
566
566
 
567
567
  - **[Core API](core.md)** - Application and middleware setup
568
568
  - **[REST Endpoints](rest.md)** - Endpoint authentication configuration
569
- - **[Authentication Example](../examples/auth.md)** - Complete implementation example
569
+ - **[Authentication Example](../examples/auth.md)** - Complete implementation example
570
+
571
+ > **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.
@@ -164,4 +164,6 @@ def update_user(id):
164
164
 
165
165
  - [Core API](core.md) - Core framework functionality
166
166
  - [REST API](rest.md) - REST endpoint implementation
167
- - [Database](database.md) - Database integration
167
+ - [Database](database.md) - Database integration
168
+
169
+ > **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.
@@ -456,4 +456,6 @@ class CustomEndpoint(RestEndpoint):
456
456
  {"error": "Something went wrong"},
457
457
  status_code=500
458
458
  )
459
- ```
459
+ ```
460
+
461
+ **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.
@@ -193,4 +193,6 @@ except ValueError as e:
193
193
 
194
194
  - [Database](database.md) - Database integration
195
195
  - [REST API](rest.md) - REST endpoint implementation
196
- - [Validation](validation.md) - Request validation
196
+ - [Validation](validation.md) - Request validation
197
+
198
+ > **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.
@@ -490,7 +490,7 @@ class StatisticsEndpoint(RestEndpoint):
490
490
  class Configuration:
491
491
  authentication_class = JWTAuthentication
492
492
  http_method_names = ['GET']
493
-
493
+
494
494
  def get(self, request):
495
495
  # Complex analytics logic
496
496
  return {
@@ -640,7 +640,7 @@ class RobustEndpoint(RestEndpoint):
640
640
 
641
641
  id = Column(Integer, primary_key=True)
642
642
  name = Column(String(100))
643
-
643
+
644
644
  def get(self, request):
645
645
  try:
646
646
  return super().get(request)
@@ -747,4 +747,8 @@ 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
+
752
+ - Only GET, POST, PUT, PATCH, DELETE HTTP verbs are supported. OPTIONS and HEAD are not available.
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.
@@ -483,4 +483,6 @@ class DebugJWTAuth(JWTAuthentication):
483
483
  - **[Middleware Example](middleware.md)** - Custom middleware patterns
484
484
  - **[Validation Example](validation.md)** - Request validation
485
485
  - **[Caching Example](caching.md)** - Performance optimization
486
- - **[API Reference](../api-reference/auth.md)** - Authentication API details
486
+ - **[API Reference](../api-reference/auth.md)** - Authentication API details
487
+
488
+ > **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.
@@ -41,3 +41,29 @@ LIGHTAPI_JWT_SECRET=supersecretkey
41
41
  ```
42
42
 
43
43
  Use `python-dotenv` or your own environment loader to populate these variables before starting your app.
44
+
45
+ ## YAML Config for Dynamic API Generation
46
+
47
+ You can define your API using a YAML config file for dynamic, reflection-based API generation. This is useful for exposing existing databases without writing models.
48
+
49
+ **Example:**
50
+ ```yaml
51
+ database_url: sqlite:///mydata.db
52
+ tables:
53
+ - name: users
54
+ crud: [get, post, put, patch, delete]
55
+ - name: logs
56
+ crud: [get]
57
+ ```
58
+
59
+ - `database_url`: Connection string (can use environment variables or a file path)
60
+ - `tables`: List of tables to expose, with allowed CRUD operations per table
61
+ - `name`: Table name in your database
62
+ - `crud`: List of allowed HTTP verbs (get, post, put, patch, delete)
63
+
64
+ **Notes:**
65
+ - Only server-side defaults (e.g., `server_default`) are available after reflection.
66
+ - All SQLAlchemy-reflectable constraints (unique, foreign key, etc.) are enforced.
67
+ - Errors (e.g., constraint violations) return 409 Conflict with details.
68
+
69
+ See the [Quickstart](quickstart.md#dynamic-api-from-yaml-config-sqlalchemy-reflection) or [README](../../README.md) for more details and advanced usage.
@@ -0,0 +1,93 @@
1
+ ---
2
+ title: Quickstart
3
+ ---
4
+
5
+ This quickstart guide shows you how to create your first LightAPI application in just a few simple steps.
6
+
7
+ ## 1. Create a Virtual Environment
8
+
9
+ ```bash
10
+ python3 -m venv .venv
11
+ source .venv/bin/activate
12
+ ```
13
+
14
+ ## 2. Install LightAPI
15
+
16
+ ```bash
17
+ pip install lightapi
18
+ ```
19
+
20
+ ## 3. Define a SQLAlchemy Model
21
+
22
+ ```python
23
+ # models.py
24
+ from sqlalchemy import Column, Integer, String
25
+ from lightapi.database import Base
26
+
27
+ class Item(Base):
28
+ id = Column(Integer, primary_key=True, index=True)
29
+ name = Column(String, unique=True, index=True)
30
+ description = Column(String, nullable=True)
31
+ ```
32
+
33
+ ## 4. Create and Run Your App
34
+
35
+ ```python
36
+ # main.py
37
+ from lightapi import LightApi
38
+ from models import Item
39
+
40
+ app = LightApi()
41
+ app.register({'/items': Item})
42
+
43
+ if __name__ == '__main__':
44
+ app.run(host='0.0.0.0', port=8000, debug=True)
45
+ ```
46
+
47
+ Now navigate to `http://localhost:8000/items` in your browser or use CURL to interact with the automatically generated CRUD endpoints.
48
+
49
+ ## Dynamic API from YAML Config (SQLAlchemy Reflection)
50
+
51
+ LightAPI can generate a REST API from a YAML configuration file, reflecting your database schema at runtime. This is ideal for exposing existing databases without writing models.
52
+
53
+ ### End-to-End Example
54
+
55
+ **1. Create a YAML config:**
56
+ ```yaml
57
+ database_url: sqlite:///mydata.db
58
+ tables:
59
+ - name: users
60
+ crud: [get, post, put, patch, delete]
61
+ - name: orders
62
+ crud: [get, post]
63
+ ```
64
+
65
+ **2. Create your database (SQLite example):**
66
+ ```bash
67
+ sqlite3 mydata.db "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT UNIQUE); CREATE TABLE orders (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, amount REAL, FOREIGN KEY(user_id) REFERENCES users(id));"
68
+ ```
69
+
70
+ **3. Start the API:**
71
+ ```python
72
+ from lightapi import LightApi
73
+ import aiohttp.web
74
+ api = LightApi.from_config('my_api_config.yaml')
75
+ app = api.app
76
+ aiohttp.web.run_app(app, port=8080)
77
+ ```
78
+
79
+ **4. Use the API (with curl):**
80
+ ```bash
81
+ curl -X POST http://localhost:8080/users/ -H 'Content-Type: application/json' -d '{"name": "Alice", "email": "alice@example.com"}'
82
+ curl http://localhost:8080/users/
83
+ curl -X POST http://localhost:8080/orders/ -H 'Content-Type: application/json' -d '{"user_id": 1, "amount": 42.5}'
84
+ curl http://localhost:8080/orders/
85
+ ```
86
+
87
+ ### FAQ
88
+ - Only server-side defaults (e.g., `server_default`) are available after reflection.
89
+ - Composite PKs, foreign keys, and constraints are supported.
90
+ - Violations (e.g., unique, FK) return 409 Conflict with details.
91
+ - You can expose only the operations you want per table.
92
+
93
+ See the [README](../../README.md) for more details and advanced usage.
@@ -14,6 +14,7 @@ description: Enterprise-grade REST API framework for Python
14
14
  - **Automatic OpenAPI/Swagger documentation** - Interactive API docs generated automatically
15
15
  - **Built-in validation** - Request/response validation with customizable validators
16
16
  - **Database integration** - Seamless SQLAlchemy integration with automatic table creation
17
+ - **Dynamic API from YAML** - Instantly generate REST APIs from a YAML config file using SQLAlchemy reflection
17
18
 
18
19
  ### 🔒 **Security & Authentication**
19
20
  - **JWT Authentication** - Built-in JSON Web Token support
@@ -134,9 +135,12 @@ Environment-based configuration with sensible defaults:
134
135
  Ready to build your first API? Check out our guides:
135
136
 
136
137
  1. **[Getting Started](getting-started/)** - Basic setup and your first API
137
- 2. **[Tutorial](tutorial/)** - Step-by-step walkthrough
138
- 3. **[Examples](examples/)** - Real-world examples and patterns
139
- 4. **[API Reference](api-reference/)** - Complete API documentation
138
+ 2. **[Dynamic API from YAML Config](getting-started/quickstart.md#dynamic-api-from-yaml-config-sqlalchemy-reflection)** - Instantly expose your database as an API from a config file
139
+ 3. **[Tutorial](tutorial/)** - Step-by-step walkthrough
140
+ 4. **[Examples](examples/)** - Real-world examples and patterns
141
+ 5. **[API Reference](api-reference/)** - Complete API documentation
142
+
143
+ See the [README](../README.md) for a full feature overview and advanced usage.
140
144
 
141
145
  ## Community & Support
142
146
 
@@ -152,3 +156,5 @@ LightAPI is released under the [MIT License](https://github.com/henriqueblobato/
152
156
 
153
157
  *Built with ❤️ for Python developers who value simplicity and productivity.*
154
158
 
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
+
@@ -203,4 +203,7 @@ def get(self, request):
203
203
  return {'data': 'ok'}
204
204
  ```
205
205
 
206
- ## Notes
206
+ ## Notes
207
+ - All required fields must be defined as NOT NULL in your database schema for correct enforcement.
208
+ - 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.
209
+ - Only GET, POST, PUT, PATCH, DELETE HTTP verbs are supported. OPTIONS and HEAD are not available.
@@ -1,9 +1,9 @@
1
1
  from .auth import JWTAuthentication
2
2
  from .cache import RedisCache
3
+ from .lightapi import LightApi
3
4
  from .core import (
4
5
  AuthenticationMiddleware,
5
6
  CORSMiddleware,
6
- LightApi,
7
7
  Middleware,
8
8
  Response,
9
9
  )