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 Scalar API Reference, 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:
- Scalar API Reference: http://127.0.0.1:8888/docs
- Swagger UI: http://127.0.0.1:8888/swagger
- ReDoc: http://127.0.0.1:8888/redoc
- OpenAPI JSON: http://127.0.0.1:8888/openapi.json
You can customize or disable documentation routes when creating the app:
app = PureAPI(
docs_url="/docs",
scalar_url="/scalar",
swagger_url="/swagger",
redoc_url="/redoc",
)
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.
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 pureapi-0.2.0.tar.gz.
File metadata
- Download URL: pureapi-0.2.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bba89b9e092207a9afe5aa75fc936f7898670a25c885b9d81477f899babce09
|
|
| MD5 |
71b9627354eb7b5cd57600bd56b35922
|
|
| BLAKE2b-256 |
479fba66be2bc348d6a499552b380aa06eeeef46060533b296b1f390457f0ab1
|
Provenance
The following attestation bundles were made for pureapi-0.2.0.tar.gz:
Publisher:
publish.yml on MarkHoo/pureapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pureapi-0.2.0.tar.gz -
Subject digest:
5bba89b9e092207a9afe5aa75fc936f7898670a25c885b9d81477f899babce09 - Sigstore transparency entry: 2339534812
- Sigstore integration time:
-
Permalink:
MarkHoo/pureapi@291e2e00688feeec1985f682a8f0122af8c02e67 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MarkHoo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@291e2e00688feeec1985f682a8f0122af8c02e67 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pureapi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pureapi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff23294866c1a88fc785c735d87b63ee233353f8c6da0ebbc269819060095baa
|
|
| MD5 |
66cf946de7f0842cfc80a2b4ad034700
|
|
| BLAKE2b-256 |
b6bfc8d995012369c36bc739bbb9eba82ac968bea4d80a52c2b77baea8628155
|
Provenance
The following attestation bundles were made for pureapi-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on MarkHoo/pureapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pureapi-0.2.0-py3-none-any.whl -
Subject digest:
ff23294866c1a88fc785c735d87b63ee233353f8c6da0ebbc269819060095baa - Sigstore transparency entry: 2339534816
- Sigstore integration time:
-
Permalink:
MarkHoo/pureapi@291e2e00688feeec1985f682a8f0122af8c02e67 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MarkHoo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@291e2e00688feeec1985f682a8f0122af8c02e67 -
Trigger Event:
push
-
Statement type: