Registry / auth-security / stytch

stytch

JSON →
library15.2.0pypypi✓ verified 87d ago

The Stytch Python library provides an interface to the Stytch user infrastructure API, simplifying the integration of authentication and authorization flows into Python applications. It supports various authentication methods like Email Magic Links, OAuth, SMS/WhatsApp passcodes, and more for both B2C and B2B use cases. The library is actively maintained with frequent releases, often multiple times a month for minor versions, indicating an agile development cycle.

pip install stytch
INSTALL
IMPORT
SIG · STYTCH
S
stytch
auth-securitypythonv15.2.0
Install
7.2s avg
Import
2441ms
Disk
60MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v15.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 2.573s · 59.4MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 7.2s · import 2.309s · 61MB
60MB installed
● package 60MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
✓ from stytch import Client
✗ import stytch
B2BClient
✓ from stytch import B2BClient
SamlShieldClient
✓ from stytch import SamlShieldClient

This quickstart demonstrates how to initialize the Stytch client using environment variables and send a magic link for user login or signup. It includes basic error handling for `StytchError` exceptions.

import os import stytch # Initialize the Stytch client using environment variables # Replace with your actual project_id and secret, or set as environment variables # For B2C authentication: client = stytch.Client( project_id=os.environ.get("STYTCH_PROJECT_ID", "project-test-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), secret=os.environ.get("STYTCH_SECRET", "secret-test-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), # Optionally specify a custom base URL for all API calls # custom_base_url="https://api.custom-domain.com/", ) # For B2B authentication, use stytch.B2BClient instead: # b2b_client = stytch.B2BClient( # project_id=os.environ.get("STYTCH_PROJECT_ID", "project-test-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), # secret=os.environ.get("STYTCH_SECRET", "secret-test-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), # ) try: # Example: Send a magic link for login or signup email_to_authenticate = "test@example.com" response = client.magic_links.email.login_or_create( email=email_to_authenticate, login_magic_link_url="http://localhost:3000/authenticate", signup_magic_link_url="http://localhost:3000/authenticate", ) print(f"Magic link sent to {email_to_authenticate}. Status code: {response.status_code}") print(f"Request ID: {response.request_id}") except stytch.StytchError as e: print(f"Stytch API error occurred: {e.details}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingStarting with Python SDK v6, asynchronous support was added. All API methods now have synchronous and asynchronous equivalents (e.g., `client.magic_links.authenticate` vs. `client.magic_links.authenticate_async`). Ensure you use the correct method based on your application's concurrency model.
fix
For async applications, append `_async` to method calls (e.g., `await client.users.get_async(...)`). For sync applications, use the methods without `_async`.
affects: >=6.0.0
gotchaAll structured errors returned from the Stytch API are encapsulated in `stytch.StytchError` exceptions. Generic exception catching might mask specific API error details.
fix
Always catch `stytch.StytchError` to properly handle and inspect API-specific error details via the `.details` property.
affects: All
gotchaStytch differentiates between Consumer (B2C) and B2B authentication. You must use the appropriate client (`stytch.Client` for B2C or `stytch.B2BClient` for B2B) as their API interfaces and expected payloads differ significantly.
fix
Instantiate `stytch.Client` for Consumer projects and `stytch.B2BClient` for B2B projects. Do not mix their usage, as B2B specific endpoints will not be available on `stytch.Client` and vice-versa.
affects: All
gotchaFor Machine-to-Machine (M2M) authentication endpoints, such as `POST /oauth2/token`, authentication is performed using `client_id` and `client_secret` rather than the standard `project_id` and `secret` used for other API calls.
fix
When interacting with M2M token endpoints, ensure you provide the M2M `client_id` and `client_secret` for authentication, either in the request body or via HTTP Basic Auth.
affects: All
gotchaWhen migrating sessions from an existing authentication system using `sessions.migrate_async`, the API is designed to return a full-fledged Stytch session. If your existing system handles Multi-Factor Authentication (MFA) prior to migration, that MFA logic typically needs to remain outside the Stytch ecosystem for the `migrate` call.
fix
If MFA is handled by your legacy system before session migration, complete the MFA flow in your existing system, then call Stytch's `sessions.migrate` (or `migrate_async`) to establish the final Stytch session.
affects: All
Upgrade
Version history
15.2.0latest on PyPI · released May 4, 2026
Audit
Dependencies
pythonrequiredRequired runtime environment.
Agent activity
37 hits · last 30 days
node
32
Amazon
1
OpenAI (training)
1
Resources
stytch — pip install stytch · libregistry