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 miniapi
For WebSocket support:
pip install miniapi[websockets]
Quick Start
from miniapi 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 miniapi.validation import RequestValidator, ValidationError
from miniapi 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 miniapi import MiniAPI, CORSMiddleware
app = MiniAPI()
app.add_middleware(CORSMiddleware, allow_origins=["*"])
HTML Response
from miniapi 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.0.tar.gz
(9.7 kB
view details)
Built Distribution
File details
Details for the file miniapi3-0.1.0.tar.gz
.
File metadata
- Download URL: miniapi3-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.19.3 CPython/3.12.7 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a3f29adce8a65f5004f4bf8d4e3ee787fea8cdad2d28033a02a8bae7281f823 |
|
MD5 | 604a8bee99be01cacd38458332d06a2e |
|
BLAKE2b-256 | 4dd53a42521fec060e0b0830f62887fc6d160443675a1cbb3f2313d44fda383c |
File details
Details for the file miniapi3-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: miniapi3-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b376043b1471f7bc53777c1c32d93eeb12a1740a53fec8da9866b114f2fb24ee |
|
MD5 | eb49cd4b10ea8ed22d56b2ed686b01ac |
|
BLAKE2b-256 | aa900154d6f9c77fe1270814964380c76ecf4ffc75f90b9782c0ac4250181629 |