Skip to main content

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

Project description

LightAPI

PyPI version Python 3.8+ License: MIT

A lightweight, fast, and easy-to-use web API framework for Python with automatic REST endpoint generation, built-in authentication, caching, and more.

Features

  • 🚀 Zero-boilerplate REST APIs - Automatically generate CRUD operations from SQLAlchemy models
  • 🔐 Built-in Authentication - JWT authentication with automatic CORS handling
  • High Performance - Built on Starlette for async support and speed
  • 💾 Smart Caching - Redis-based caching with automatic invalidation
  • 📊 Request Validation - Automatic request validation and error handling
  • 🔍 Advanced Filtering - Query filtering, pagination, and sorting out of the box
  • 📖 Auto Documentation - Automatic OpenAPI/Swagger documentation generation
  • 🔧 Flexible Middleware - Easy middleware system for custom logic
  • 🗄️ Database Integration - Seamless SQLAlchemy integration with automatic table creation
  • ⚙️ Environment Configuration - Easy configuration management

Quick Start

Installation

pip install lightapi

Basic Usage

from lightapi import LightApi
from lightapi.database import Base
from sqlalchemy import Column, Integer, String

# Define your model
class User(Base):
    __tablename__ = "users"
    
    id = Column(Integer, primary_key=True)
    name = Column(String(50))
    email = Column(String(100))

# Create API instance
app = LightApi()

# Register your model - automatically creates CRUD endpoints
app.register(User)

# Run the server
if __name__ == "__main__":
    app.run()

That's it! You now have a fully functional REST API with:

  • GET /users - List all users with filtering and pagination
  • GET /users/{id} - Get user by ID
  • POST /users - Create new user
  • PUT /users/{id} - Update user
  • DELETE /users/{id} - Delete user
  • OPTIONS /users - CORS preflight support

Documentation

Visit our comprehensive documentation at: https://iklobato.github.io/lightapi/

Advanced Features

Authentication

from lightapi.auth import JWTAuthentication

# Add JWT authentication
auth = JWTAuthentication(secret_key="your-secret-key")
app.add_middleware(auth)

# Protected endpoints automatically require valid JWT tokens

Caching

from lightapi.cache import RedisCache

# Add Redis caching
cache = RedisCache(host="localhost", port=6379)
app.register(User, cache=cache, cache_ttl=300)  # 5 minutes TTL

Validation

from lightapi.rest import Validator

class UserValidator(Validator):
    def validate_post(self, data):
        if not data.get("email"):
            raise ValueError("Email is required")
        return data

app.register(User, validator=UserValidator())

Middleware

from lightapi.core import Middleware

class LoggingMiddleware(Middleware):
    async def process(self, request, call_next):
        print(f"Request: {request.method} {request.url}")
        response = await call_next(request)
        print(f"Response: {response.status_code}")
        return response

app.add_middleware(LoggingMiddleware())

Why LightAPI?

  • Rapid Development: Get REST APIs running in minutes, not hours
  • Production Ready: Built-in security, caching, and error handling
  • Flexible: Customize every aspect while keeping defaults simple
  • Modern: Async support, type hints, and contemporary Python practices
  • Well Documented: Comprehensive docs with real-world examples

Examples

Check out the examples directory for complete applications:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


LightAPI - Making web APIs light and fast

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.3.tar.gz (173.5 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.3-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lightapi-0.1.3.tar.gz
  • Upload date:
  • Size: 173.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for lightapi-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ad0f50906ee162d8148a9b94021617fa7829adfd1c9cc1c79d6144984cd61d34
MD5 e728d174b58d3ee67746bf89e27e863d
BLAKE2b-256 bd3080aff7dfd3b80ec7764f46b8fac773e7d59b5dc72ced1996a46ac1649896

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lightapi-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for lightapi-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ed584c388eac5dd7265ee0a9a8c6c45a5b853dbaa4cc85296f1664bce3fad292
MD5 ec62d67cece47ed8a709855427bb50b2
BLAKE2b-256 b2025da589e7eff98f1571ba54e49b5892cd2696b62401d2910b47e2cd8e399d

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