A lightweight framework for building API endpoints using Python's native libraries.
Project description
LightAPI: Instant Python REST APIs from SQL Databases
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.
Why use LightAPI?
- Zero-boilerplate Python REST API: Instantly generate CRUD endpoints from your database schema.
- YAML-driven API generator: Reflect your database and expose only the tables and operations you want.
- Async and Fast: Built on aiohttp for high concurrency and low latency.
- Production-ready: JWT authentication, Redis caching, request validation, and robust error handling.
- Automatic OpenAPI docs: Swagger UI and OpenAPI JSON out of the box.
- Flexible: Use with SQLite, PostgreSQL, MySQL, or any SQLAlchemy-supported database.
- Modern Python: Type hints, async/await, and best practices throughout.
Who is this for?
- Backend developers who want to ship APIs fast, with minimal code.
- Data engineers needing to expose existing databases as RESTful services.
- Prototypers and startups who want to iterate quickly and scale later.
- Anyone who wants a clean, maintainable, and extensible Python API stack.
Features
- 🚀 Automatic CRUD endpoints from SQLAlchemy models or YAML config
- 🔄 Database reflection: Expose existing tables instantly
- 🔐 JWT authentication with CORS support
- ⚡ Async performance (aiohttp)
- 💾 Redis caching with auto-invalidation
- 🧪 Request validation and error handling
- 🔍 Filtering, pagination, and sorting
- 📖 OpenAPI/Swagger documentation auto-generated
- 🔧 Custom middleware support
- 🗄️ Works with SQLite, PostgreSQL, MySQL, and more
- 📝 Environment-based configuration
Quick Start
1. Install LightAPI
pip install lightapi
2. Define your model (SQLAlchemy)
from lightapi import LightApi
from lightapi.database import Base
from sqlalchemy import Column, Integer, String
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String(50))
email = Column(String(100))
app = LightApi()
app.register(User)
if __name__ == "__main__":
app.run()
3. Or use YAML for instant API from your database
# config.yaml
database_url: sqlite:///mydata.db
tables:
- name: users
crud: [get, post, put, patch, delete]
- name: orders
crud: [get, post]
from lightapi import LightApi
api = LightApi.from_config('config.yaml')
api.run(host="0.0.0.0", port=8081)
Example Endpoints (from YAML above)
GET /users/- List usersPOST /users/- Create userGET /users/{id}- Get user by IDPUT /users/{id}- Replace userPATCH /users/{id}- Update userDELETE /users/{id}- Delete userGET /orders/- List ordersPOST /orders/- Create orderGET /orders/{id}- Get order by ID
Documentation
FAQ
Q: Can I use LightAPI with my existing database?
A: Yes! Use the YAML config to reflect your schema and instantly expose REST endpoints.
Q: What databases are supported?
A: Any database supported by SQLAlchemy (PostgreSQL, MySQL, SQLite, etc.).
Q: How do I secure my API?
A: Enable JWT authentication and CORS with a single line.
Q: Can I customize endpoints or add business logic?
A: Yes, you can extend or override any handler, add middleware, and use validators.
Q: Is this production-ready?
A: Yes. LightAPI is designed for both rapid prototyping and production deployment.
Comparison
| Feature | LightAPI | FastAPI | Flask | Django REST |
|---|---|---|---|---|
| Zero-boilerplate CRUD | ✅ | ❌ | ❌ | ❌ |
| YAML-driven API | ✅ | ❌ | ❌ | ❌ |
| Async support | ✅ | ✅ | ❌ | ❌ |
| OpenAPI docs | ✅ | ✅ | ❌ | ✅ |
| Built-in Auth/Caching | ✅ | ❌ | ❌ | ✅ |
| DB Reflection | ✅ | ❌ | ❌ | ❌ |
License
MIT License. See LICENSE.
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.
To start your API, always useapi.run(host, port). Do not use external libraries orapp = api.appto start the server directly.
LightAPI - The fastest way to build Python REST APIs from your database.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lightapi-0.1.7.tar.gz.
File metadata
- Download URL: lightapi-0.1.7.tar.gz
- Upload date:
- Size: 326.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e95f80ed4b4381da07fab4ae878727280e31f92290303a9a1ea86ab18a370295
|
|
| MD5 |
fc097169beab8aec0029cdf5a3e68883
|
|
| BLAKE2b-256 |
59abff33b0480335be6a851e5d9a3c8150cb616aa77124f8bccf89ef22c2383c
|
File details
Details for the file lightapi-0.1.7-py3-none-any.whl.
File metadata
- Download URL: lightapi-0.1.7-py3-none-any.whl
- Upload date:
- Size: 36.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5611e3fc22118025eee2b5972efcf0d926ffb1886c2633f32f3b92bfff5cadfd
|
|
| MD5 |
bbbd27b30186b7f0f4d465706f6b8297
|
|
| BLAKE2b-256 |
77f3f2a97bad02f75e54ed0bad529c1e9e24a3bb0db981b9225e2e7b52baf004
|