Skip to main content

superfunctions-fastapi

FastAPI adapter for superfunctions.http

Location: packages/python-fastapi/
Package: superfunctions-fastapi
Import: from superfunctions_fastapi import create_router

Installation

pip install superfunctions-fastapi

Usage

Option 1: Create Router from Routes

from fastapi import FastAPI
from superfunctions.http import Route, HttpMethod, Response, NotFoundError
from superfunctions_fastapi import create_router

app = FastAPI()

# Define handlers using superfunctions abstractions
async def get_user(request, context):
    user_id = context.params["id"]
    
    # Your logic here
    user = await db.find_one(...)
    if not user:
        raise NotFoundError(f"User {user_id} not found")
    
    return Response(status=200, body=user)

async def create_user(request, context):
    data = await request.json()
    user = await db.create(...)
    return Response(status=201, body=user)

# Create router from routes
routes = [
    Route(method=HttpMethod.GET, path="/users/{id}", handler=get_user),
    Route(method=HttpMethod.POST, path="/users", handler=create_user),
]

router = create_router(routes, prefix="/api/v1", tags=["users"])
app.include_router(router)

Option 2: Convert Individual Handlers

from fastapi import FastAPI, Request
from superfunctions_fastapi import to_fastapi_handler
from superfunctions.http import Response

app = FastAPI()

async def get_user(request, context):
    return Response(status=200, body={"id": context.params["id"]})

@app.get("/users/{id}")
async def route(request: Request, id: str):
    handler = to_fastapi_handler(get_user)
    return await handler(request, id=id)

Features

  • ✅ Automatic request/response conversion
  • ✅ HTTP error handling
  • ✅ Path parameters
  • ✅ Query parameters
  • ✅ Headers
  • ✅ JSON body parsing
  • ✅ OpenAPI documentation support

Benefits

Write framework-agnostic handlers that work across:

  • FastAPI
  • Flask (with superfunctions-flask)

Example with authfn

from fastapi import FastAPI, Depends
from superfunctions_fastapi import create_router
from superfunctions.http import Route, HttpMethod, Response, UnauthorizedError
from authfn import create_authfn, AuthFnConfig

app = FastAPI()
auth = create_authfn(AuthFnConfig(database=adapter))

async def get_protected_resource(request, context):
    # Authenticate using authfn
    auth_header = context.headers.get("authorization")
    if not auth_header:
        raise UnauthorizedError("Missing authorization header")
    
    session = await auth.provider.authenticate(request)
    if not session:
        raise UnauthorizedError("Invalid credentials")
    
    return Response(status=200, body={"message": "Protected resource", "user": session.keyId})

routes = [
    Route(method=HttpMethod.GET, path="/protected", handler=get_protected_resource),
]

router = create_router(routes)
app.include_router(router)

License

MIT

Metadata

Release files for superfunctions-fastapi 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for superfunctions-fastapi 0.1.1
File Size Uploaded Provenance Actions
superfunctions_fastapi-0.1.1.tar.gz 7.3 kB With provenance Details for superfunctions_fastapi-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for superfunctions-fastapi 0.1.1
File Interpreter ABI Platform Actions
superfunctions_fastapi-0.1.1-py3-none-any.whl Python 3 none any Details for superfunctions_fastapi-0.1.1-py3-none-any.whl

Total release size: 12.7 kB

Release files / superfunctions_fastapi-0.1.1.tar.gz

Download URL superfunctions_fastapi-0.1.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8cf9bfbf53dc35a08e3e4e0905c24802a9c81c80a9a90705edc0d8b8b883ece6
BLAKE2b-256 checksum
How to use checksums
31e8567ec54689b760733409f4f79b91c6baa1e1350f223992d8d6a8c3cad277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / superfunctions_fastapi-0.1.1-py3-none-any.whl

Download URL superfunctions_fastapi-0.1.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca09ce4919e4474c839fb2d00a077a34339998447990f1750fd4f15087a9ca06
BLAKE2b-256 checksum
How to use checksums
4538a6458e4bd72f54c43e5f08285c38d20fd44b117ad9fa461ed63d72bf12b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for superfunctions-fastapi 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for superfunctions_fastapi-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page