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.1.tar.gz
(10.6 kB
view details)
Built Distribution
miniapi3-0.1.1-py3-none-any.whl
(10.8 kB
view details)
File details
Details for the file miniapi3-0.1.1.tar.gz
.
File metadata
- Download URL: miniapi3-0.1.1.tar.gz
- Upload date:
- Size: 10.6 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 | b09204debd75478b8f7a5f5c176511794cdb066f035f82529f0dea6f31f5d757 |
|
MD5 | 48a120444ba0c6b75fab649912250a71 |
|
BLAKE2b-256 | d01fdedc58dcf356feea9a6fa08819c1232cac912d31eb8856e162e1c310dc35 |
File details
Details for the file miniapi3-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: miniapi3-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.8 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 | 8599587fa455347ef2058949fd789933b5184534f1e23321602f3b06815bc420 |
|
MD5 | 364b2bc1d6a3314b4d3ea68ccae7f82f |
|
BLAKE2b-256 | 7a500d7ccb0ba02be545caa3868f397d5b4848b0a793044ac5a3324d3e796cfd |