Skip to main content

A lightweight framework for building API endpoints using Python's native libraries.

Project description

LightAPI: Instant Python REST APIs from SQL Databases

PyPI version Python 3.8+ License: MIT

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 users
  • POST /users/ - Create user
  • GET /users/{id} - Get user by ID
  • PUT /users/{id} - Replace user
  • PATCH /users/{id} - Update user
  • DELETE /users/{id} - Delete user
  • GET /orders/ - List orders
  • POST /orders/ - Create order
  • GET /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 use api.run(host, port). Do not use external libraries or app = api.app to start the server directly.


LightAPI - The fastest way to build Python REST APIs from your database.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lightapi-0.1.8.tar.gz (326.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lightapi-0.1.8-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file lightapi-0.1.8.tar.gz.

File metadata

  • Download URL: lightapi-0.1.8.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

Hashes for lightapi-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b30681c84aa6f8a1f830a38625d3ecd7aaeefcb7b2c9e4bb617e510aaaf7f0d3
MD5 c7644b0beae3f18c2fc8492ba43d820b
BLAKE2b-256 e663def755b6e8527bb9ff59ca29f65a97be9f5f8dc1d7bf1a748e96218e7097

See more details on using hashes here.

File details

Details for the file lightapi-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: lightapi-0.1.8-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

Hashes for lightapi-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1c3216deff235a7e1a615b617449fc786e5571f651faf80aca25c4c9acbc41be
MD5 c130424ca70d142d79f152fce7b84df6
BLAKE2b-256 cb67cc69c7dde6275f2157c8a1e2db9fa8cb163e7f76bfc5bc808ae7d73edaf8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page