Skip to main content

Python SDK for Fastn connector authentication

Project description

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",
        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,
    base_url: str | None = None,
)
Parameter Type Required Description
space_id str Yes The space/workspace ID
api_key str Yes API key for authentication
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
tenant_id str No Tenant ID
connection_id str No Connection instance ID (defaults to "default")

AuthSession

Represents an active authentication session.

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 and wait for completion.

@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.

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}")

Status Lifecycle

Status Description
INACTIVE OAuth initiated, awaiting user authorization
ACTIVE Connector successfully activated
FAILED Activation failed

Requirements

  • Python 3.9 or higher
  • aiohttp >= 3.8.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastn_auth-1.0.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

fastn_auth-1.0.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file fastn_auth-1.0.1.tar.gz.

File metadata

  • Download URL: fastn_auth-1.0.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for fastn_auth-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a9d111ebd4e38fb4e08e14086bdbd183daa242961605e6f0d21c5914610c6ce3
MD5 7a3e8ebde6d14be7522aa81837757ca9
BLAKE2b-256 a88544f36079fa1bb17b30ada2d2e44ee7e5f493f1f1b481fc73d7290a27f010

See more details on using hashes here.

File details

Details for the file fastn_auth-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fastn_auth-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for fastn_auth-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 830eb5c8860d8bfbf9560a86f13277cfcbb2c9eab817433dfe537272ad9b836e
MD5 70171c4a0b9e9960cbd79bf177c8b313
BLAKE2b-256 f2299f11bb89f53f354116639a0acf68e24eca8771d58bfce64d9da40dabab4e

See more details on using hashes here.

Supported by

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