### Install Development Dependencies Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Installs the necessary development dependencies for the Stytch Python library using pip. This command should be run after cloning the repository and setting up a virtual environment. ```shell pip install -r requirements_dev.txt ``` -------------------------------- ### Install Stytch Python Library Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Install the Stytch Python library using pip. This command fetches and installs the latest version of the library, making it available for use in your Python projects. ```bash pip install stytch ``` -------------------------------- ### Initialize B2C Stytch Client (Python) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Demonstrates how to initialize the Stytch client for B2C (Business-to-Consumer) authentication flows. You need your project ID and secret key from the Stytch Dashboard. An optional custom base URL can be provided. ```python import stytch client = stytch.Client( project_id="project-live-c60c0abe-c25a-4472-a9ed-320c6667d317", secret="secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=", # Optionally specify a custom base URL for all API calls # custom_base_url="https://api.custom-domain.com/", ) ``` -------------------------------- ### Initialize B2B Stytch Client (Python) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Demonstrates how to initialize the Stytch client for B2B (Business-to-Business) authentication flows. Similar to B2C, it requires project ID and secret key, with an option for a custom base URL. ```python import stytch client = stytch.B2BClient( project_id="project-live-c60c0abe-c25a-4472-a9ed-320c6667d317", secret="secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=", # Optionally specify a custom base URL for all API calls # custom_base_url="https://api.custom-domain.com/", ) ``` -------------------------------- ### Login/Signup via Email Magic Link (B2B) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Facilitates the login or signup process for the first user in a B2B organization using email magic links. It requires the organization ID, the user's email address, and redirect URLs for both login and signup scenarios. ```python response = client.magic_links.email.login_or_signup( organization_id="ORGANIZATION_ID_FROM_RESPONSE", email_address="admin@acme.co", login_redirect_url="https://example.com/authenticate", signup_redirect_url="https://example.com/authenticate" ) ``` -------------------------------- ### Run Core Unit Tests Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Discovers and runs unit tests specifically within the 'stytch/' directory. This command is useful for focusing on the core library logic tests. ```python python -m unittest discover -s stytch/ -t . ``` -------------------------------- ### Run Integration Tests Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Discovers and runs integration tests, typically located in the 'test/' directory. These tests interact with the actual Stytch API and require specific environment variables to be set. ```python python -m unittest discover -s test/ -t . ``` -------------------------------- ### Generate HTML Coverage Report Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Enables integration tests by setting an environment variable, runs unit tests, and generates an HTML report for test coverage. This command is a convenience script for detailed coverage analysis. ```shell env STYTCH_PYTHON_RUN_INTEGRATION_TESTS=1 coverage run -m unittest && coverage html --omit="*test/*" ``` -------------------------------- ### Run All Unit Tests Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Executes all unit tests for the Stytch Python library using Python's built-in unittest module. This command should be run from the project's root directory to ensure all test suites are discovered and executed. ```python python -m unittest ``` -------------------------------- ### Generate Test Coverage Report Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Runs all unit tests and then generates a coverage report, omitting test files. This provides insights into which parts of the library are covered by tests. ```shell coverage run -m unittest && coverage report --omit="*test/*" --sort=cover ``` -------------------------------- ### Run Codegen Unit Tests Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Discovers and runs unit tests related to the code generation process, located within the 'codegen/' directory. This helps verify the functionality of the API generation scripts. ```python python -m unittest discover -s codegen/ -t . ``` -------------------------------- ### Run Coverage Script Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md A convenience script that automates the process of running tests and generating coverage reports, including HTML output. This script simplifies the workflow for checking test coverage. ```shell bin/generate-coverage.sh ``` -------------------------------- ### Distribution Dependencies Source: https://github.com/stytchauth/stytch-python/blob/main/requirements_dev.txt Specifies the package required for building and distributing the Python project. This entry includes the package name and its version. ```requirements.txt build==1.2.2.post1 ``` -------------------------------- ### Type Checking and Testing Dependencies Source: https://github.com/stytchauth/stytch-python/blob/main/requirements_dev.txt Lists packages essential for static type checking and running tests within the project. This includes linters, type checkers, and related libraries. ```requirements.txt black==24.3.0 mypy==0.991 types-requests==2.28.11.5 ``` -------------------------------- ### Create Organization (B2B) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Creates a new organization within Stytch for B2B use cases. This involves providing an organization name, a unique slug, and a list of allowed email domains. ```python response = client.organizations.create( organization_name="Acme Co", organization_slug="acme-co", email_allowed_domains=["acme.co"] ) ``` -------------------------------- ### Async Magic Link Authentication (B2C) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Shows how to perform the magic link authentication flow asynchronously. The `_async` suffix is appended to method names for asynchronous operations. The same client object can be used for both sync and async calls. ```python login_or_create_resp = await client.magic_links.email.login_or_create_async( email="sandbox@stytch.com", login_magic_link_url="https://example.com/authenticate", signup_magic_link_url="https://example.com/authenticate", ) print(login_or_create_resp) auth_resp = await client.magic_links.authenticate( token="DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=", ) print(resp) ``` -------------------------------- ### Python StytchError Handling Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Demonstrates how to catch and handle `StytchError` exceptions raised by the Stytch API in Python. It shows how to access error details via the `.details` property and differentiate between API-specific errors and general exceptions. ```python from stytch.core.response_base import StytchError try: auth_resp = await client.magic_links.authenticate_async(token="token") except StytchError as error: # Handle Stytch errors here if error.details.error_type == "invalid_token": print("Whoops! Try again?") except Exception as error: # Handle other errors here pass ``` -------------------------------- ### Send Magic Link by Email (B2C) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Initiates a login or signup flow using email magic links for B2C users. This method sends an email containing a magic link to the specified email address. It requires the user's email and URLs for login and signup redirects. ```python login_or_create_resp = client.magic_links.email.login_or_create( email="sandbox@stytch.com", login_magic_link_url="https://example.com/authenticate", signup_magic_link_url="https://example.com/authenticate", ) # Responses are fully-typed `pydantic` objects print(login_or_create_resp) ``` -------------------------------- ### Generate API Methods Source: https://github.com/stytchauth/stytch-python/blob/main/DEVELOPMENT.md Executes a shell script to regenerate API client code. This is crucial when API methods are added, updated, or deleted to keep the library synchronized with the Stytch API. It applies default formatters and avoids overwriting manual implementations. ```shell bin/generate-api.sh ``` -------------------------------- ### Authenticate Magic Link Token (B2C) Source: https://github.com/stytchauth/stytch-python/blob/main/README.md Authenticates a token received from a magic link. This is typically called after a user clicks the magic link in their email. It validates the token and returns user session information. ```python auth_resp = client.magic_links.authenticate( token="DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=", ) print(auth_resp) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.