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 stytchVerified import paths — ran on the pinned version, not inferred.
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.
For async applications, append `_async` to method calls (e.g., `await client.users.get_async(...)`). For sync applications, use the methods without `_async`.
Always catch `stytch.StytchError` to properly handle and inspect API-specific error details via the `.details` property.
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.
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.
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.