fastn-auth (Python)
Python SDK for Fastn connector authentication. Provides a simple async interface for initiating OAuth and credential-based connector authentication flows.
Installation
pip install fastn-auth
Quick Start
import asyncio
from fastn_auth import FastnAuth
async def main():
# Create a client
client = FastnAuth(
space_id="your-space-id",
api_key="your-api-key", # or use auth_token instead
base_url="https://live.fastn.ai/api", # optional
)
# Initialize an authentication session
session = await client.initialize(
connector_id="google-sheets",
org_id="org-id", # optional
tenant_id="tenant-id" # optional
)
# Redirect the user to complete OAuth
print(f"Redirect user to: {session.redirect_url}")
# Wait for the user to complete authentication
result = await session.wait_for_completion()
print("Authentication complete!", result.credentials)
asyncio.run(main())
API Reference
FastnAuth
The main client class for initializing authentication flows.
Constructor
FastnAuth(
space_id: str,
api_key: str | None = None,
auth_token: str | None = None,
base_url: str | None = None,
)
| Parameter | Type | Required | Description |
|---|---|---|---|
space_id |
str |
Yes | The space/workspace ID |
api_key |
str |
One of api_key or auth_token |
API key — sent as x-fastn-api-key header |
auth_token |
str |
One of api_key or auth_token |
Bearer token — sent as Authorization: Bearer {token} header |
base_url |
str |
No | Base URL for the Fastn API (defaults to https://live.fastn.ai/api) |
Methods
async initialize(...) -> AuthSession
Initialize a connector authentication flow.
async def initialize(
self,
connector_id: str,
org_id: str | None = None,
tenant_id: str | None = None,
connection_id: str | None = None,
) -> AuthSession
| Parameter | Type | Required | Description |
|---|---|---|---|
connector_id |
str |
Yes | The connector ID (e.g., "google-sheets", "salesforce") |
org_id |
str |
No | Organization ID (defaults to "community") |
tenant_id |
str |
No | Tenant ID |
connection_id |
str |
No | Connection instance ID |
async get_credentials(options: GetCredentialsOptions) -> Credentials
Fetch credentials for an already-authenticated connector without starting a new OAuth flow.
from fastn_auth import FastnAuth, GetCredentialsOptions
credentials = await client.get_credentials(
GetCredentialsOptions(
connector_id="google-sheets",
org_id="org-id", # optional
tenant_id="tenant-id", # optional
connection_id="conn-id" # optional
)
)
| Parameter | Type | Required | Description |
|---|---|---|---|
connector_id |
str |
Yes | The connector ID |
org_id |
str |
No | Organization ID (defaults to "community") |
tenant_id |
str |
No | Tenant ID |
connection_id |
str |
No | Connection instance ID |
AuthSession
Represents an active authentication session returned by client.initialize().
Properties
| Property | Type | Description |
|---|---|---|
id |
str |
Unique identifier for this session |
state_key |
str |
State key for the OAuth flow |
redirect_url |
str |
URL to redirect the user to for OAuth authorization |
Methods
async wait_for_completion(options: PollOptions | None = None) -> AuthResult
Poll for the authentication status until it reaches ACTIVE or FAILED, or until the timeout is exceeded.
@dataclass
class PollOptions:
interval: float = 2.0 # Polling interval in seconds
timeout: float = 300.0 # Maximum wait time in seconds (5 minutes)
Returns an AuthResult object:
@dataclass
class AuthResult:
status: AuthStatus
credentials: Credentials | None = None
error_message: str | None = None
async get_status() -> StatusResponse
Get the current status of the authentication session.
@dataclass
class StatusResponse:
status: AuthStatus
error_message: str | None = None
async get_credentials() -> Credentials
Fetch the credentials for the authenticated connector after the OAuth flow completes.
@dataclass
class Credentials:
access_token: str | None = None
expires_in: int | None = None
[key: str]: Any # connector-specific fields
Error Handling
The SDK provides custom exception classes for different failure scenarios:
from fastn_auth import (
FastnAuthError,
TimeoutError,
AuthenticationError,
NetworkError,
InvalidResponseError,
)
try:
result = await session.wait_for_completion()
except TimeoutError:
print("Authentication timed out")
except AuthenticationError as e:
print(f"Authentication failed: {e.message}")
except NetworkError as e:
print(f"Network error: {e.message}, status: {e.status_code}")
except InvalidResponseError as e:
print(f"Unexpected API response: {e.message}")
| Error Class | Code | Description |
|---|---|---|
FastnAuthError |
— | Base class for all SDK errors |
TimeoutError |
TIMEOUT |
wait_for_completion() exceeded the timeout |
AuthenticationError |
AUTH_FAILED |
The authentication flow returned FAILED |
NetworkError |
NETWORK_ERROR |
HTTP request failed; includes status_code |
InvalidResponseError |
INVALID_RESPONSE |
API response is missing required fields |
Status Lifecycle
| Status | Description |
|---|---|
INACTIVE |
OAuth initiated, awaiting user authorization |
ACTIVE |
Connector successfully authenticated |
FAILED |
Authentication failed |
Requirements
- Python 3.9 or higher
- aiohttp >= 3.8.0
License
MIT
Metadata
Release files for fastn-auth 1.0.5
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 |
|---|---|---|---|---|
| fastn_auth-1.0.5.tar.gz | 8.5 kB | Without provenance | Details for fastn_auth-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastn_auth-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for fastn_auth-1.0.5-py3-none-any.whl |
Total release size: 17.6 kB
Release files / fastn_auth-1.0.5.tar.gz
| Download URL | fastn_auth-1.0.5.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1163b48203bd3f50b27c429a029302d9782b4b532bd10123d2ec7aa4ab241b6f
|
|
BLAKE2b-256 checksum How to use checksums |
322beb20a59d40d850d0dc297b88d5d86bd1da88e971264ff2b028bebe320ce2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / fastn_auth-1.0.5-py3-none-any.whl
| Download URL | fastn_auth-1.0.5-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
094c5e5141a56134826b5ece6f6c4958eaad1141893dca56c3e0f5e97c916a8d
|
|
BLAKE2b-256 checksum How to use checksums |
80082b69b23429818931446fdee48d9caf3df73b0b3a58538675c28248888d11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for fastn-auth 1.0.5
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.