miniapi like fastapi
Project description
MiniAPI3
A lightweight Python web framework inspired by FastAPI, featuring async support, WebSocket capabilities, and middleware.
github repo
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()
uvicorn support
uvicorn main:app
Request Validation
from miniapi3 import MiniAPI, Response
from pydantic import BaseModel
app = MiniAPI()
class UserCreate(BaseModel):
username: str
email: str
age: int
@app.post("/users")
async def create_user(request, user: UserCreate):
return dict(user)
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.4.tar.gz
(10.6 kB
view details)
Built Distribution
miniapi3-0.1.4-py3-none-any.whl
(12.5 kB
view details)
File details
Details for the file miniapi3-0.1.4.tar.gz
.
File metadata
- Download URL: miniapi3-0.1.4.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.20.1 CPython/3.11.10 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cd7a9ee521e80b296ae6d5c7df419d46863d13671dbebc9bbfb93adf0d6b7d1 |
|
MD5 | 07209ea8f52147821fee7b652aa84d2d |
|
BLAKE2b-256 | f5c880f4a59bfffe5f3d54c6a2cf6d8764b7ecf634fdf08891bf98581ad07474 |
File details
Details for the file miniapi3-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: miniapi3-0.1.4-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.20.1 CPython/3.11.10 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a132cd19b1a6ea9e62f8789d7bfea994783f62ff29508dc02776c5f37218917f |
|
MD5 | b93f3177fffaf13dafe3e89987b4fbd6 |
|
BLAKE2b-256 | 0f6ad7707a0e9b1517d8a9f56cc879fd9400315d07252399dfa567815fa9025f |