Frontegg Python SDK

3.0.4 · active · verified Thu Apr 16

Frontegg is a web platform for SaaS companies to integrate managed SaaS features like authentication, authorization, and user management. The Python SDK, currently at version 3.0.4, provides tools to validate tokens, manage users, and integrate Frontegg services into Python applications. It's actively maintained with updates released based on feature development and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure and initialize the Frontegg Python SDK. It sets global configuration parameters using `FronteggConfig` class attributes and then creates an instance of `FronteggContext`, which uses these settings. While actual token validation or service calls require a valid JWT, this example ensures the basic setup is correct and environment variables are honored.

import os
from frontegg.frontegg import FronteggContext
from frontegg.common.frontegg_config import FronteggConfig

# 1. Configure Frontegg global settings
# Get your Client ID and API Key from the Frontegg Portal.
# Using environment variables is recommended for production.
FronteggConfig.client_id = os.environ.get('FRONTEGG_CLIENT_ID', 'FRONTEGG_CLIENT_ID_NOT_SET')
FronteggConfig.api_key = os.environ.get('FRONTEGG_API_KEY', 'FRONTEGG_API_KEY_NOT_SET')
FronteggConfig.base_url = os.environ.get('FRONTEGG_BASE_URL', 'https://api.frontegg.com')
FronteggConfig.middleware_access_strategy = 'token' # or 'cookie' depending on your setup

# 2. Initialize the FronteggContext (it uses the globally configured settings)
frontegg_context = FronteggContext()

# 3. Verify configuration (for demonstration purposes)
print("Frontegg SDK initialized.")
print(f"Configured Client ID: {FronteggConfig.client_id}")
print(f"Configured Base URL: {FronteggConfig.base_url}")

# In a real application, you would typically use `frontegg_context.token_service.validate_jwt()`
# or decorators like `@with_authentication` in web frameworks to protect routes.
# Example (requires a valid JWT token, which is not provided in this quickstart):
# try:
#     # For actual token validation, you'd need a real token, e.g., from an Authorization header
#     # user_info = frontegg_context.token_service.validate_jwt("YOUR_JWT_TOKEN")
#     # print(f"Token validated for user: {user_info.get('sub')}")
# except Exception as e:
#     # print(f"Token validation failed: {e}")
#     pass # Suppress error for runnable quickstart without a token

view raw JSON →