PureAPI
PureAPI is a lightweight, intuitive, zero-runtime-dependency Python web API framework.
Features
- Typed routing with automatic conversion, such as
/users/{user_id:int}. - Standard WSGI application interface.
- Automatic JSON responses for
dictandlistreturn values. - Request object with query parameters, headers, body, JSON, form data, and URL helpers.
- Built-in OpenAPI generation at
/openapi.json. - Built-in API documentation with Scalar API Reference by default, plus Swagger UI and ReDoc.
- Zero runtime dependencies in the core framework.
Requirements
PureAPI supports Python 3.11 and newer.
Installation
Install from PyPI:
pip install pureapi
Install for local development:
git clone https://github.com/MarkHoo/pureapi.git
cd pureapi
python -m pip install -e ".[dev]"
Run the test suite:
python -m pytest
Quick Start
Create app.py:
from pureapi import PureAPI, Request, HTTPException
app = PureAPI(
title="Task API",
version="1.0.0",
description="A small task management API built with PureAPI.",
)
tasks = {
1: {"id": 1, "title": "Write documentation", "done": False},
}
@app.get("/", summary="API home", tags=["system"])
def home():
"""Return basic service information."""
return {
"name": "Task API",
"docs": "/docs",
"openapi": "/openapi.json",
}
@app.get("/tasks", summary="List tasks", tags=["tasks"])
def list_tasks():
"""Return all tasks."""
return {"items": list(tasks.values()), "count": len(tasks)}
@app.get("/tasks/{task_id:int}", summary="Get task", tags=["tasks"])
def get_task(task_id: int):
"""Return one task by ID."""
task = tasks.get(task_id)
if task is None:
raise HTTPException(status_code=404, detail="Task not found")
return task
@app.post("/tasks", summary="Create task", tags=["tasks"])
def create_task(request: Request):
"""Create a task from a JSON request body."""
data = request.json or {}
title = str(data.get("title", "")).strip()
if not title:
raise HTTPException(status_code=400, detail="title is required")
task_id = max(tasks.keys(), default=0) + 1
task = {"id": task_id, "title": title, "done": False}
tasks[task_id] = task
return task
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8000, debug=True)
Start the application:
python app.py
Open:
- API home: http://127.0.0.1:8000/
- Scalar docs: http://127.0.0.1:8000/docs
- Swagger UI: http://127.0.0.1:8000/swagger
- ReDoc: http://127.0.0.1:8000/redoc
- OpenAPI JSON: http://127.0.0.1:8000/openapi.json
Documentation Routes
PureAPI registers documentation routes automatically:
| Path | Description |
|---|---|
/docs |
Scalar API Reference, the default documentation UI |
/swagger |
Swagger UI |
/redoc |
ReDoc |
/openapi.json |
OpenAPI 3.0 JSON |
Customize them when creating the app:
app = PureAPI(
title="My API",
version="1.0.0",
docs_url="/docs",
scalar_url="/reference",
swagger_url="/swagger",
redoc_url="/redoc",
openapi_url="/openapi.json",
)
Production
Run with Gunicorn:
gunicorn myapp:app -w 4 -b 0.0.0.0:8000
Run with uWSGI:
uwsgi --http :8000 --wsgi-file myapp.py --callable app
License
PureAPI is released under the MIT License. See LICENSE.
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.1.tar.gz.
File metadata
- Download URL: pureapi-0.2.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7139dae5fb58f8a4a3c50736ca4a0f09551853a3176076ae96f9122b00302084
|
|
| MD5 |
cb11c1068443b8847571f8a8d336d07b
|
|
| BLAKE2b-256 |
df1887dbf3f4e94b06ff529aab87d04e610823d6420b6686766a605ef414c3ea
|
Provenance
The following attestation bundles were made for pureapi-0.2.1.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.1.tar.gz -
Subject digest:
7139dae5fb58f8a4a3c50736ca4a0f09551853a3176076ae96f9122b00302084 - Sigstore transparency entry: 2339932171
- Sigstore integration time:
-
Permalink:
MarkHoo/pureapi@c8130914e7593ddabf517bc3cc9333eb34a3ba78 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/MarkHoo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c8130914e7593ddabf517bc3cc9333eb34a3ba78 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pureapi-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pureapi-0.2.1-py3-none-any.whl
- Upload date:
- Size: 13.5 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 |
e5a2a7001fb55cad969b490bc73f35258bf5ab746b00cd2b0703590e43dcfc05
|
|
| MD5 |
50f01f035055e5e82a4311a4c465a112
|
|
| BLAKE2b-256 |
d121542c437d3f3e57ed2545be829e710d2ba4eef8cdb88c0e8bf8468c094163
|
Provenance
The following attestation bundles were made for pureapi-0.2.1-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.1-py3-none-any.whl -
Subject digest:
e5a2a7001fb55cad969b490bc73f35258bf5ab746b00cd2b0703590e43dcfc05 - Sigstore transparency entry: 2339932184
- Sigstore integration time:
-
Permalink:
MarkHoo/pureapi@c8130914e7593ddabf517bc3cc9333eb34a3ba78 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/MarkHoo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c8130914e7593ddabf517bc3cc9333eb34a3ba78 -
Trigger Event:
push
-
Statement type: