{"id":9000,"library":"frontegg","title":"Frontegg Python SDK","description":"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.","status":"active","version":"3.0.4","language":"en","source_language":"en","source_url":"https://github.com/Frontegg/frontegg-python","tags":["authentication","saas","identity management","authorization","jwt","openid connect"],"install":[{"cmd":"pip install frontegg","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for making HTTP requests to Frontegg APIs.","package":"requests"}],"imports":[{"note":"The v3.x API consolidated core functionality into FronteggContext and deprecated framework-specific Frontegg classes like `frontegg.fastapi.Frontegg`.","wrong":"from frontegg.fastapi import Frontegg","symbol":"FronteggContext","correct":"from frontegg.frontegg import FronteggContext"},{"note":"FronteggConfig is located in the `frontegg.common.frontegg_config` submodule.","wrong":"from frontegg import FronteggConfig","symbol":"FronteggConfig","correct":"from frontegg.common.frontegg_config import FronteggConfig"},{"note":"Use framework-specific decorators for authentication middleware (e.g., from `frontegg.flask` or `frontegg.fastapi`).","symbol":"with_authentication","correct":"from frontegg.fastapi import with_authentication"}],"quickstart":{"code":"import os\nfrom frontegg.frontegg import FronteggContext\nfrom frontegg.common.frontegg_config import FronteggConfig\n\n# 1. Configure Frontegg global settings\n# Get your Client ID and API Key from the Frontegg Portal.\n# Using environment variables is recommended for production.\nFronteggConfig.client_id = os.environ.get('FRONTEGG_CLIENT_ID', 'FRONTEGG_CLIENT_ID_NOT_SET')\nFronteggConfig.api_key = os.environ.get('FRONTEGG_API_KEY', 'FRONTEGG_API_KEY_NOT_SET')\nFronteggConfig.base_url = os.environ.get('FRONTEGG_BASE_URL', 'https://api.frontegg.com')\nFronteggConfig.middleware_access_strategy = 'token' # or 'cookie' depending on your setup\n\n# 2. Initialize the FronteggContext (it uses the globally configured settings)\nfrontegg_context = FronteggContext()\n\n# 3. Verify configuration (for demonstration purposes)\nprint(\"Frontegg SDK initialized.\")\nprint(f\"Configured Client ID: {FronteggConfig.client_id}\")\nprint(f\"Configured Base URL: {FronteggConfig.base_url}\")\n\n# In a real application, you would typically use `frontegg_context.token_service.validate_jwt()`\n# or decorators like `@with_authentication` in web frameworks to protect routes.\n# Example (requires a valid JWT token, which is not provided in this quickstart):\n# try:\n#     # For actual token validation, you'd need a real token, e.g., from an Authorization header\n#     # user_info = frontegg_context.token_service.validate_jwt(\"YOUR_JWT_TOKEN\")\n#     # print(f\"Token validated for user: {user_info.get('sub')}\")\n# except Exception as e:\n#     # print(f\"Token validation failed: {e}\")\n#     pass # Suppress error for runnable quickstart without a token\n","lang":"python","description":"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."},"warnings":[{"fix":"Review the official migration guide for v3.0.0. Update imports to use `from frontegg.frontegg import FronteggContext` and configure settings via `FronteggConfig` class attributes. Replace `sanity_middleware` usage with `FronteggConfig.middleware_access_strategy`.","message":"Major breaking changes were introduced in version 3.0.0. The configuration flow was completely revamped, core services were consolidated into `FronteggContext`, and framework-specific `Frontegg` classes (e.g., `frontegg.fastapi.Frontegg`) were removed. Additionally, the `frontegg.sanity_middleware` module was removed.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Be aware of the global nature of `FronteggConfig`. For multi-tenant scenarios requiring isolated configurations, consider running separate processes or carefully managing configuration changes, though dynamically changing global settings per request is generally not recommended.","message":"FronteggConfig uses class attributes for its settings, making it a global configuration. This means you cannot easily manage multiple, distinct Frontegg configurations simultaneously within a single Python process (e.g., for different tenants requiring distinct API keys or base URLs).","severity":"gotcha","affected_versions":"All versions"},{"fix":"When using Frontegg SDK outside of framework decorators (`@with_authentication`), ensure that any potentially blocking network calls are either `await`ed in an `async` function or handled in a separate thread if your application is synchronous.","message":"Direct usage of Frontegg SDK methods (e.g., for token validation) without proper integration into an asynchronous web framework (like FastAPI) might lead to blocking I/O if not correctly awaited in an `async` context. The SDK is largely designed with async operations in mind.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you set `FronteggConfig.client_id`, `FronteggConfig.api_key`, and `FronteggConfig.base_url` as class attributes before initializing `FronteggContext` or performing any operations.","cause":"You are attempting to access a FronteggConfig attribute (like `client_id`) before it has been set, or you are trying to instantiate `FronteggConfig` directly instead of setting its class attributes.","error":"AttributeError: type object 'FronteggConfig' has no attribute 'client_id'"},{"fix":"Double-check that `FronteggConfig.client_id`, `FronteggConfig.api_key`, and `FronteggConfig.base_url` are correctly set with valid values obtained from your Frontegg Portal.","cause":"One or more essential Frontegg configuration parameters (client_id, api_key, base_url) are missing, empty, or malformed, preventing the SDK from initializing correctly.","error":"frontegg.common.exceptions.FronteggException: Invalid Frontegg configuration"},{"fix":"Remove imports and usage of `frontegg.sanity_middleware`. Instead, control the middleware behavior using `FronteggConfig.middleware_access_strategy` (set to 'token' or 'cookie').","cause":"The `sanity_middleware` module was removed in Frontegg Python SDK v3.0.0 and its functionality consolidated.","error":"ModuleNotFoundError: No module named 'frontegg.sanity_middleware'"},{"fix":"Verify that the JWT token is valid and not expired. Ensure `FronteggConfig.base_url` correctly points to the Frontegg environment that issued the token, and that your `client_id` and `api_key` are accurate for that environment.","cause":"The provided JWT token is either invalid, expired, malformed, or signed by an issuer not recognized by your Frontegg configuration (e.g., wrong `base_url`).","error":"frontegg.common.exceptions.FronteggException: Token validation failed: Unauthorized"}]}