A lightweight FastAPI-inspired framework
Project description
README.md
MenzoAPI v1.0.0
A lightweight FastAPI-inspired framework for Python 3.10+ with zero external dependencies.
Features
- Routing: GET, POST, PUT, DELETE, PATCH
- Route Parameters:
/users/{id} - Query Parameters:
/search?q=test&page=1 - Request Object: headers, body, json, params, query, method, path
- Response Object: status, body, headers
- JSON Responses: Automatic serialization
- Middleware System: Multiple middleware support
- Exception Handlers: Custom exception handling
- Built-in Docs:
/docsendpoint with auto-listed routes - Async Support: Full async endpoint support
- Thread-Safe Routing: Safe for concurrent requests
- Automatic JSON Parsing: Request body parsing
- Automatic Status Codes: Smart response status detection
- Static File Serving: Serve static files
- CORS Support: Cross-Origin Resource Sharing
- Logging: Built-in logging
- Type Hints: Complete type annotations everywhere
- Zero Dependencies: Pure Python standard library
Installation
pip install menzoapi
Quick Start
from menzoapi import MenzoAPI, Server
app = MenzoAPI()
@app.get("/")
def home(request):
return {"message": "Hello, MenzoAPI!"}
@app.get("/users/{id}")
def get_user(request):
user_id = request.params["id"]
return {"id": user_id, "name": "User " + user_id}
@app.post("/users")
async def create_user(request):
data = await request.json
return {"created": True, "data": data}
Server(app).run()
Advanced Usage Middleware
from menzoapi import MenzoAPI
from menzoapi.middleware import LoggerMiddleware, CORSMiddleware
app = MenzoAPI()
app.use(LoggerMiddleware())
app.use(CORSMiddleware(origins=["*"]))
Exception Handling
from menzoapi.exceptions import NotFoundException
@app.exception_handler(NotFoundException)
def handle_not_found(exc):
return {"error": str(exc)}, 404
Static Files
app.static("/static", "./public")
CORS
app.enable_cors(
origins=["https://example.com"],
methods=["GET", "POST"],
headers=["Content-Type"]
)
API Reference MenzoAPI
@app.get(path) - GET route
@app.post(path) - POST route
@app.put(path) - PUT route
@app.delete(path) - DELETE route
@app.patch(path) - PATCH route
app.use(middleware) - Add middleware
app.exception_handler(type) - Add exception handler
app.enable_cors() - Enable CORS
app.static(path, directory) - Serve static files
Request
request.method - HTTP method
request.path - Request path
request.headers - Headers dict
request.query - Query parameters
request.params - Route parameters
await request.body - Raw body
await request.json - JSON body
Response
Response(status, body, headers) - Create response
response.json(data, status) - JSON response
Server
from menzoapi import Server
Server(app, host="0.0.0.0", port=8000, workers=4).run()
host - Bind address (default: 127.0.0.1)
ENDING PART
port - Bind port (default: 8000)
workers - Number of worker processes (default: 1) Documentation Visit /docs endpoint in your browser to see auto-generated API documentation.
License MIT
By Sarthak Kamat
---Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file menzoapi-1.0.0.tar.gz.
File metadata
- Download URL: menzoapi-1.0.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0965b6300e86e1da62b794dd2285b85584407f343f579de3324de3613f3e5a69
|
|
| MD5 |
514dab32ec077277f52fd9f087325d03
|
|
| BLAKE2b-256 |
ceed0c331849c0880f481b7940485dce240c54dfb6ea718799349b74d00df39f
|
File details
Details for the file menzoapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: menzoapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d947d30acad3338c8beeb7bdf39713fbf7f11bbb69a2b973f1dcfe154215ee4e
|
|
| MD5 |
c84774e6628070543d6d22ece57e97f1
|
|
| BLAKE2b-256 |
b3a00ebf41221c8869f30b09778cf96a3cbfde0c158f024361d73546c6beb575
|