A lightweight and elegant Python web framework
Project description
PureAPI
A lightweight and elegant Python web framework for building modern APIs.
Features
- 🚀 Modern Routing - Type-annotated path parameters with automatic conversion
- 📖 OpenAPI Support - Built-in Swagger UI and ReDoc documentation
- 🎯 Simple Design - Intuitive API that's easy to learn and use
- 🔧 WSGI Compatible - Works with any WSGI server (Gunicorn, uWSGI, etc.)
- 📦 Zero Dependencies - Uses only Python standard library
Installation
pip install pureapi
Quick Start
from pureapi import PureAPI
app = PureAPI(title="My API", version="1.0.0")
@app.get("/")
def root():
"""Welcome endpoint."""
return {"message": "Hello, World!"}
@app.get("/users/{user_id:int}")
def get_user(user_id: int):
"""Get user by ID."""
return {"user_id": user_id}
@app.post("/users")
def create_user(request):
"""Create a new user."""
data = request.json
return {"created": True, "data": data}
if __name__ == "__main__":
app.run() # Runs on http://127.0.0.1:8888
API Documentation
Once your app is running, visit:
- Swagger UI: http://127.0.0.1:8888/docs
- ReDoc: http://127.0.0.1:8888/redoc
- OpenAPI JSON: http://127.0.0.1:8888/openapi.json
Path Parameters
# String parameter (default)
@app.get("/items/{item_id}")
def get_item(item_id: str):
return {"item_id": item_id}
# Integer parameter
@app.get("/users/{user_id:int}")
def get_user(user_id: int):
return {"user_id": user_id}
# Float parameter
@app.get("/prices/{price:float}")
def get_price(price: float):
return {"price": price}
Request Handling
from pureapi import PureAPI, Request
app = PureAPI()
@app.post("/data")
def handle_data(request: Request):
# JSON body
data = request.json
# Query parameters
params = request.query_params
# Headers
headers = request.headers
return {"received": data}
Error Handling
from pureapi import HTTPException
@app.get("/items/{item_id:int}")
def get_item(item_id: int):
if item_id < 0:
raise HTTPException(status_code=400, detail="Invalid item ID")
return {"item_id": item_id}
# Custom exception handler
@app.exception_handler(404)
def not_found(request, exc):
return {"error": "Not found", "path": request.path}
Sub-Routers
from pureapi import PureAPI, Router
app = PureAPI()
api_router = Router()
@api_router.get("/users")
def list_users():
return []
app.include_router(api_router, prefix="/api/v1")
# Route: /api/v1/users
Running in Production
# With Gunicorn
gunicorn myapp:app -w 4 -b 0.0.0.0:8888
# With uWSGI
uwsgi --http :8888 --wsgi-file myapp.py --callable app
Documentation
See the docs folder for detailed documentation.
License
MIT License - see LICENSE for details.
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
pureapi-0.1.1.tar.gz
(14.5 kB
view details)
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
pureapi-0.1.1-py3-none-any.whl
(12.7 kB
view details)
File details
Details for the file pureapi-0.1.1.tar.gz.
File metadata
- Download URL: pureapi-0.1.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f5ed13693ee36fd589b2af51ee05aae8620eecf1adfefeb1703aa996186b5ac
|
|
| MD5 |
e39a815d74fe72506a4bab5967bed4d8
|
|
| BLAKE2b-256 |
05104337ddf420e19e828fdd224bf4b1a958e51b2acf57b8032f7aff69e7983c
|
File details
Details for the file pureapi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pureapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d32b23f1eec9958429baa20edd6382d5b24afd44b368e5dd5a716592f73cdeb8
|
|
| MD5 |
816cfe6c3cff135c13a1bc312317d9eb
|
|
| BLAKE2b-256 |
8c90fd12fe16e062d0722d6ab83ec2708b3946304f75ce21542e3b35b87dcf45
|