Skip to main content

miniapi like fastapi

Project description

MiniAPI

A lightweight Python web framework inspired by FastAPI, featuring async support, WebSocket capabilities, and middleware.

Features

  • Async request handling
  • Route parameters
  • WebSocket support
  • Middleware system
  • Request validation
  • CORS support
  • Form data handling
  • ASGI compatibility

Installation

pip install miniapi3

For WebSocket support:

pip install miniapi3[websockets]

Quick Start

from miniapi3 import MiniAPI, Response

app = MiniAPI()

@app.get("/")
async def hello():
    return {"message": "Hello, World!"}

@app.get("/users/{user_id}")
async def get_user(request):
    user_id = request.path_params["user_id"]
    return {"user_id": user_id}

# WebSocket example
@app.websocket("/ws")
async def websocket_handler(ws):
    while True:
        message = await ws.receive()
        await ws.send(f"Echo: {message}")

if __name__ == "__main__":
    app.run()

Request Validation

from dataclasses import dataclass

from miniapi3.validation import RequestValidator, ValidationError
from miniapi3 import MiniAPI, Response

app = MiniAPI()

@dataclass
class UserCreate(RequestValidator):
    username: str
    email: str
    age: int

@app.post("/users")
@app.validate(UserCreate)
async def create_user(request, data: UserCreate):
    return {"user": data}

CORS Middleware

from miniapi3 import MiniAPI, CORSMiddleware

app = MiniAPI()
app.add_middleware(CORSMiddleware, allow_origins=["*"])

HTML Response

from miniapi3 import MiniAPI, html

app = MiniAPI()

@app.get("/")
async def index():
    return html("<h1>Hello, World!</h1>")

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

miniapi3-0.1.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

miniapi3-0.1.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: miniapi3-0.1.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.19.3 CPython/3.12.7 Darwin/24.0.0

File hashes

Hashes for miniapi3-0.1.2.tar.gz
Algorithm Hash digest
SHA256 04b3ce505ff304533269c2eed419cfb5df4cc124e7f26d828ca6953dd2864841
MD5 1eb62fdd7ccbf3e115429ef31d95c90e
BLAKE2b-256 cd0cb18a90d8922f98af7cdde90527b0927322f96024faaf82b6a8551eaedd47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: miniapi3-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.19.3 CPython/3.12.7 Darwin/24.0.0

File hashes

Hashes for miniapi3-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ae2c0c26974447bfb498f0a3546dd9d673ad23e00211160f0e168a3172cb243a
MD5 6a71f4f8e2ca1a6e224a0cf0f9dbedd4
BLAKE2b-256 6c1f64f45e1c4af8038062823a9e5b9f500d146b6868a5348e4bab32833b76d6

See more details on using hashes here.

Supported by

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