superfunctions-flask
Flask adapter for superfunctions.http
Location: packages/python-flask/
Package: superfunctions-flask
Import: from superfunctions_flask import create_blueprint
Installation
pip install superfunctions-flask
Usage
Option 1: Create Blueprint from Routes
from flask import Flask
from superfunctions.http import Route, HttpMethod, Response, NotFoundError
from superfunctions_flask import create_blueprint
app = Flask(__name__)
# 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 blueprint from routes
routes = [
Route(method=HttpMethod.GET, path="/users/<id>", handler=get_user),
Route(method=HttpMethod.POST, path="/users", handler=create_user),
]
blueprint = create_blueprint(routes, name="api", url_prefix="/api/v1")
app.register_blueprint(blueprint)
Option 2: Convert Individual Handlers
from flask import Flask
from superfunctions_flask import to_flask_handler
from superfunctions.http import Response
app = Flask(__name__)
async def get_user(request, context):
return Response(status=200, body={"id": context.params["id"]})
@app.route("/users/<id>")
def route(id):
handler = to_flask_handler(get_user)
return handler(id=id)
Features
- ✅ Automatic request/response conversion
- ✅ HTTP error handling
- ✅ Path parameters
- ✅ Query parameters
- ✅ Headers
- ✅ JSON body parsing
- ✅ Blueprint support
Benefits
Write framework-agnostic handlers that work across:
- Flask
- FastAPI (with
superfunctions-fastapi) - Django (with
superfunctions-django)
Example with authfn
from flask import Flask
from superfunctions_flask import create_blueprint
from superfunctions.http import Route, HttpMethod, Response, UnauthorizedError
from authfn import create_authfn, AuthFnConfig
app = Flask(__name__)
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),
]
blueprint = create_blueprint(routes)
app.register_blueprint(blueprint)
License
MIT
Metadata
Release files for superfunctions-flask 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| superfunctions_flask-0.1.0.tar.gz | 4.3 kB | Without provenance | Details for superfunctions_flask-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| superfunctions_flask-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for superfunctions_flask-0.1.0-py3-none-any.whl |
Total release size: 9.2 kB
Release files / superfunctions_flask-0.1.0.tar.gz
| Download URL | superfunctions_flask-0.1.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6265a61c95087ab107d28d3b3490dfa7ababb16c2e00696dbad1ae1a3e5f7253
|
|
BLAKE2b-256 checksum How to use checksums |
62f9a57fbee5a69b448b31c5782c203f5e5a1241506741fa2c7666611e314e83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / superfunctions_flask-0.1.0-py3-none-any.whl
| Download URL | superfunctions_flask-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45a7bd587b5a75af69d5b9e74a365bdc4a709ae97dbcd9d7851acff3ec11f470
|
|
BLAKE2b-256 checksum How to use checksums |
c5fdc6bcf1aadba2bfad0b9465bf4f7ebd1fb8a856b8d067c16870397d0d0e49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for superfunctions-flask 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.