authfn Python SDK
The Python authfn package mirrors the TypeScript authfn contract for backend runtimes that want the same routes, schema output, plugin surface, and canonical error envelopes.
What It Covers
- Browser session routes and cookie handling
- Password sign-up/sign-in and password reset
- Email OTP send/verify
- Google, Apple, and GitHub social OAuth sign-in
- User-owned API keys
- TOTP-based 2FA
- Multi-region lookup and runtime resolution
- Shared OpenAPI generation through the Python
superfunctions.http.openapilayer
Quick Start
from authfn import (
AuthFnConfig,
authfn_email_otp_plugin,
authfn_multi_region_plugin,
authfn_password_plugin,
authfn_social_oauth_plugin,
authfn_two_factor_plugin,
create_authfn,
)
from authfn.plugins.social_oauth import SocialOAuthPluginConfig, SocialProviderConfig
auth = create_authfn(
AuthFnConfig(
database=my_database_adapter,
namespace="authfn",
plugins=[
authfn_password_plugin(),
authfn_email_otp_plugin(
{
"delivery": my_delivery_provider,
}
),
authfn_social_oauth_plugin(
SocialOAuthPluginConfig(
providers={
"google": SocialProviderConfig(
client_id="google-client-id",
client_secret="google-client-secret",
allowlisted_return_to=["https://app.example.com/post-auth"],
)
},
# Secret key (at least 32 bytes) that encrypts stored
# provider tokens; required.
encryption_key_resolver=lambda key_ref: load_secret(key_ref),
)
),
authfn_two_factor_plugin(),
authfn_multi_region_plugin(),
],
)
)
After upgrading from a release that stored social OAuth tokens without a configured key, re-encrypt them once with await SocialOAuthService(config, plugin_config).token_vault.migrate_legacy_tokens() (when your resolver only knows a new key reference, set the plugin's encryption_key_ref to it and pass the same value as destination_key_ref=).
Mount the emitted routes through the shared adapters:
superfunctions-fastapisuperfunctions-flask
Route Surface
GET /auth/sessionGET /auth/sessionsPOST /auth/sign-outPOST /auth/sessions/:sessionId/revokePOST /auth/sign-up/passwordPOST /auth/sign-in/passwordPOST /auth/password/reset/startPOST /auth/password/reset/completePOST /auth/otp/sendPOST /auth/otp/verifyPOST /auth/social/startGET /auth/social/callback/:providerPOST /auth/social/disconnect/:providerPOST /auth/api-keysGET /auth/api-keysDELETE /auth/api-keys/:keyIdPOST /auth/2fa/enrollPOST /auth/2fa/confirmPOST /auth/2fa/challengePOST /auth/2fa/disablePOST /auth/regions/lookupGET /auth/environmentGET /auth/runtime(compatibility alias for/auth/environment)
OpenAPI
Python authfn uses the shared OpenAPI generator rather than maintaining a custom authfn-specific implementation:
document = auth.open_api()
The output is deterministic and matches the TypeScript path surface.
Notes
- Python authfn follows the same canonical envelopes and error codes as TypeScript.
- FastAPI and Flask cookie propagation is covered by the shared package layer and authfn parity tests.
- Sensitive values such as passwords, OTP codes, API key secrets, and OAuth tokens are omitted or redacted from observability events.
- CI discovers this package from the monorepo root (
.github/workflows/ci.yml) and runs pytest, ruff, andpython -m build.
Awaiting placement verification telemetry
Use await verifier.verify_signed_async(assertion) (also available on the issuer) in request-scoped or serverless runtimes. It waits for configured verification event delivery on both success and rejection. The synchronous verification API remains available, but cannot guarantee asynchronous telemetry completes before the request lifetime ends.
Metadata
Release files for authfn 0.3.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 |
|---|---|---|---|---|
| authfn-0.3.0.tar.gz | 109.3 kB | With provenance | Details for authfn-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| authfn-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for authfn-0.3.0-py3-none-any.whl |
Total release size: 188.9 kB
Release files / authfn-0.3.0.tar.gz
| Download URL | authfn-0.3.0.tar.gz |
|---|---|
| Size | 109.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3641c488e39cbed9fe16a301cc0adebaa3118fcaf209a5a3497d0452f0c43eeb
|
|
BLAKE2b-256 checksum How to use checksums |
ef831fa69d66a189197f5184fff82849247fa887ae369cf6153d61fc001aaee5
|
| 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 logRelease files / authfn-0.3.0-py3-none-any.whl
| Download URL | authfn-0.3.0-py3-none-any.whl |
|---|---|
| Size | 79.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23e758c252b412998bf187e84900ba451fe2b0b671ebcb0242c65a2ec3ab03a8
|
|
BLAKE2b-256 checksum How to use checksums |
4c080501f4b7bada67f1e576c376ce0dac676d5f587765a6dd227bcaffc13729
|
| 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 logSecurity for authfn 0.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for authfn-0.3.0.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 logA 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.