Skip to main content

PureAPI

A lightweight and elegant Python web framework for building modern APIs.

Python License

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:

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

pureapi-0.2.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pureapi-0.2.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

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

Hashes for pureapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5bba89b9e092207a9afe5aa75fc936f7898670a25c885b9d81477f899babce09
MD5 71b9627354eb7b5cd57600bd56b35922
BLAKE2b-256 479fba66be2bc348d6a499552b380aa06eeeef46060533b296b1f390457f0ab1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pureapi-0.2.0.tar.gz:

Publisher: publish.yml on MarkHoo/pureapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pureapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff23294866c1a88fc785c735d87b63ee233353f8c6da0ebbc269819060095baa
MD5 66cf946de7f0842cfc80a2b4ad034700
BLAKE2b-256 b6bfc8d995012369c36bc739bbb9eba82ac968bea4d80a52c2b77baea8628155

See more details on using hashes here.

Provenance

The following attestation bundles were made for pureapi-0.2.0-py3-none-any.whl:

Publisher: publish.yml on MarkHoo/pureapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page