Skip to main content

Stytch Management Python Library

The Stytch Management Python library makes it easy to use Stytch's Programmatic Workspace Actions API in Python applications.

This library requires Python 3.8 or later.

Installation

pip install stytch-management

Pre-requisites

You need your Stytch Management API credentials from the workspace management section of your Stytch Dashboard.

Note: These credentials allow you to perform read and write actions on your workspace, potentially modifying or deleting important Stytch resources like projects, environments, or secrets.

Examples

Create a new API client:

from stytch_management import Client

# Set your Stytch Management API credentials
client = Client(
    workspace_key_id="workspace-test-...",
    workspace_key_secret="secret-test-..."
)

Create a new B2B project:

response = client.projects.create(
    name="My new project",
    vertical="B2B"
)

new_project = response.project
print(f"Created project: {new_project.project_slug}")

Get the live environment in the new project:

response = client.environments.get_all(
    project_slug=new_project.project_slug
)

live_env = next((env for env in response.environments if env.type == "LIVE"), None)
print(f"Live environment: {live_env.environment_slug}")

Alternatively, create a new custom environment:

response = client.environments.create(
    project_slug=new_project.project_slug,
    name="My custom environment",
    type="TEST"
)

custom_env = response.environment
print(f"Created environment: {custom_env.environment_slug}")

Create a new secret in the live environment:

response = client.secrets.create(
    project_slug=new_project.project_slug,
    environment_slug=live_env.environment_slug
)

secret = response.secret
print(f"Created secret: {secret.secret_id}")

Get SDK configuration:

response = client.sdk.get_consumer_config(
    project_slug=new_project.project_slug,
    environment_slug=live_env.environment_slug
)

print("Consumer SDK config:", response.config)

Type Safety

All request and response types are fully typed using Pydantic models. Import them from the models subpackages:

from stytch_management.models import projects, environments, secrets

# Responses are typed
response: projects.CreateResponse = client.projects.create(
    name="My project",
    vertical="B2B"
)

Error Handling

from stytch_management import Client, StytchError, ClientError

client = Client(
    workspace_key_id="workspace-test-...",
    workspace_key_secret="secret-test-..."
)

try:
    client.projects.get(project_slug="invalid-slug")
except StytchError as e:
    print(f"Stytch error: {e.error_type}")
    print(f"Message: {e.error_message}")
    print(f"Request ID: {e.request_id}")
except ClientError as e:
    print(f"Client error: {e.message}")

Running Tests

This library includes comprehensive integration tests that verify functionality against the Stytch API. These tests create and clean up disposable projects and resources.

Prerequisites

To run the tests, you need valid Stytch Management API credentials:

export STYTCH_WORKSPACE_KEY_ID="your-workspace-key-id"
export STYTCH_WORKSPACE_KEY_SECRET="your-workspace-key-secret"

Important: Tests will be skipped if these environment variables are not set. The tests create real resources in your workspace but clean them up automatically.

Running All Tests

# Install dependencies (if not already installed)
pip install -r requirements_dev.txt

# Run all tests
python -m unittest discover test/

# Run a specific test file
python test/test_secrets.py

Test Coverage

The test suite includes integration tests for:

  • Email Templates - Create, get, update, delete, and default management
  • Environments - Environment lifecycle with user locking and IDP configurations
  • Secrets - Secret creation, retrieval, and deletion
  • Public Tokens - Public token management
  • JWT Templates - Session and M2M JWT template configuration
  • Redirect URLs - URL validation and type management
  • Password Strength Config - LUDS and ZXCVBN policy configuration
  • Country Code Allowlist - SMS and WhatsApp country code management

Each test suite:

  • ✓ Creates disposable projects/environments
  • ✓ Tests all CRUD operations
  • ✓ Validates error handling
  • ✓ Cleans up all resources automatically
  • ✓ Runs independently without side effects

Continuous Integration

Tests are designed to run in CI environments. Set the environment variables in your CI configuration:

# Example GitHub Actions
env:
  STYTCH_WORKSPACE_KEY_ID: ${{ secrets.STYTCH_WORKSPACE_KEY_ID }}
  STYTCH_WORKSPACE_KEY_SECRET: ${{ secrets.STYTCH_WORKSPACE_KEY_SECRET }}

Development

See DEVELOPMENT.md for information on building and testing the SDK.

Documentation

See the full Stytch Management API documentation for more details on available endpoints and functionality.

Support

If you've found a bug, open an issue!

If you have questions or want help troubleshooting, join us in Slack or email support@stytch.com.

If you've found a security vulnerability, please follow our responsible disclosure instructions.

License

MIT

Release files for stytch-management 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stytch-management 1.2.0
File Size Uploaded
stytch_management-1.2.0.tar.gz 35.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stytch-management 1.2.0
File Interpreter ABI Platform
stytch_management-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 81.6 kB

Release files / stytch_management-1.2.0.tar.gz

Download URL stytch_management-1.2.0.tar.gz
Size 35.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ee73b941c754f56f00b1b1e041dff8d09acaa620b34ae90235bf4ec1523b2a0f
BLAKE2b-256 checksum
How to use checksums
e159f4551c1ee694b9125fefadca7cc8b87ce6b170ce205f88af3a1d6b9ad868
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / stytch_management-1.2.0-py3-none-any.whl

Download URL stytch_management-1.2.0-py3-none-any.whl
Size 45.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b50554f78eee1b4873f4c964f334e7ef98c3fd03454f9f0a491e267524efff09
BLAKE2b-256 checksum
How to use checksums
e6a9113f9b82192728086b5e33fe80b03421c4a242942fb915761349cc5f749f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page