Avnology ID
SDKsPython SDKAuthentication

Login

Authenticate users with email/password and SMS OTP using the Python SDK.

Login

Server-side authentication methods for the Python SDK.

login()

Authenticate with email and password.

def login(self, *, email: str, password: str, organization_id: str | None = None) -> Session

Parameters

NameTypeRequiredDescription
emailstryesUser's email address
passwordstryesUser's password
organization_idstrnoScope to an organization

Returns

Session -- The authenticated session.

Basic usage

from avnology_id import AvnologyId

client = AvnologyId(
    base_url="https://api.id.avnology.com",
    client_id="app_abc123",
    client_secret="sk_live_...",
)

session = client.login(email="[email protected]", password="SecurePassword123!")

print(session.id)              # "ses_abc123"
print(session.identity.email)  # "[email protected]"
print(session.expires_at)      # datetime object
print(session.authenticator_assurance_level)  # "aal1"

Error handling

from avnology_id.errors import (
    InvalidCredentialsError,
    AccountLockedError,
    MfaRequiredError,
    RateLimitError,
)

try:
    session = client.login(email=email, password=password)
except InvalidCredentialsError:
    print("Invalid email or password")
except AccountLockedError as e:
    print(f"Account locked. Retry after {e.retry_after} seconds")
except MfaRequiredError as e:
    print(f"MFA required. Flow: {e.flow_id}")
    print(f"Available methods: {e.available_methods}")
    # Handle MFA challenge
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")

Async usage

from avnology_id import AsyncAvnologyId

async_client = AsyncAvnologyId(
    base_url="https://api.id.avnology.com",
    client_id="app_abc123",
    client_secret="sk_live_...",
)

session = await async_client.login(email="[email protected]", password="SecurePassword123!")

login_with_sms()

# Step 1: Send SMS code
result = client.login_with_sms(phone="+15550100")
print(f"Flow ID: {result.flow_id}")

# Step 2: Verify code
session = client.verify_sms_code(flow_id=result.flow_id, code="482901")
result = client.login_with_magic_link(
    email="[email protected]",
    return_url="https://myapp.com/dashboard",
)
print(f"Magic link sent. Flow ID: {result.flow_id}")

See also

On this page