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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lightapi-0.1.2.tar.gz
  • Upload date:
  • Size: 173.0 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.2.tar.gz
Algorithm Hash digest
SHA256 30253ce568bf26b6e4b0d3f90bbf57f998c7febb229847b129c394d7ef533e4d
MD5 12128e70206df0fbdb37ed90f81cd5af
BLAKE2b-256 761b9807b5c00dcade14f985db4e51406c38bb78518ed31020ecb3c05166ef52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lightapi-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a26d3464ec10bf797b0aba2cc6e976219194b6fc1052c2415617a71a084792b5
MD5 00708de69578feed51acf89e4545e155
BLAKE2b-256 450e88f46f154ed70f23f76f6e74724ce3e18b0fc1a316a99a2eb37d057724ca

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