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.3.tar.gz
(10.4 kB
view details)
Built Distribution
miniapi3-0.1.3-py3-none-any.whl
(12.0 kB
view details)
File details
Details for the file miniapi3-0.1.3.tar.gz
.
File metadata
- Download URL: miniapi3-0.1.3.tar.gz
- Upload date:
- Size: 10.4 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 | 29a7b83e12481ef374d6fa313b6c8a36ac6b81735dfcb49aadbd61aaa43cf4da |
|
MD5 | 19292d28c46de25f10821b18f2aac5a3 |
|
BLAKE2b-256 | 0a2052b8bb3a3b1b110b1c0fede7f27c9b85019d28701b11b1871897a471fe93 |
File details
Details for the file miniapi3-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: miniapi3-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.0 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 | 96dfebb536095100725c7a173ef934cdb114cc05d16b595700fcfcd88cde4bc5 |
|
MD5 | 6d5d80945eefa5a0e597ebf48e5c919a |
|
BLAKE2b-256 | ebe3d89aab5127ea92cddd73a479e7e30bdc4ca02a26b04c49acff74485c5cff |