Module supertokens_python.types.config

Expand source code
from abc import abstractmethod
from typing import Callable, Generic, Optional, TypeVar

from supertokens_python.types.recipe import BaseAPIInterface, BaseRecipeInterface
from supertokens_python.types.response import CamelCaseBaseModel
from supertokens_python.types.utils import UseDefaultIfNone

T = TypeVar("T")

"""Generic Type for use in `InterfaceOverride`"""
FunctionInterfaceType = TypeVar("FunctionInterfaceType", bound=BaseRecipeInterface)
"""Generic Type for use in `FunctionOverrideConfig`"""
APIInterfaceType = TypeVar("APIInterfaceType", bound=BaseAPIInterface)
"""Generic Type for use in `APIOverrideConfig`"""


InterfaceOverride = Callable[[T], T]


class BaseOverrideConfigWithoutAPI(CamelCaseBaseModel, Generic[FunctionInterfaceType]):
    """Base class for input override config without API overrides."""

    functions: UseDefaultIfNone[Optional[InterfaceOverride[FunctionInterfaceType]]] = (
        lambda original_implementation: original_implementation
    )


class BaseNormalisedOverrideConfigWithoutAPI(
    CamelCaseBaseModel, Generic[FunctionInterfaceType]
):
    """Base class for normalized override config without API overrides."""

    functions: InterfaceOverride[FunctionInterfaceType] = (
        lambda original_implementation: original_implementation
    )

    @classmethod
    def from_input_config(
        cls,
        override_config: Optional[BaseOverrideConfigWithoutAPI[FunctionInterfaceType]],
    ) -> "BaseNormalisedOverrideConfigWithoutAPI[FunctionInterfaceType]":
        """Create a normalized config from the input config."""
        normalised_config = cls()

        if override_config is None:
            return normalised_config

        if override_config.functions is not None:
            normalised_config.functions = override_config.functions

        return normalised_config


class BaseOverrideConfig(
    BaseOverrideConfigWithoutAPI[FunctionInterfaceType],
    Generic[FunctionInterfaceType, APIInterfaceType],
):
    """Base class for input override config with API overrides."""

    apis: UseDefaultIfNone[Optional[InterfaceOverride[APIInterfaceType]]] = (
        lambda original_implementation: original_implementation
    )


class BaseNormalisedOverrideConfig(
    BaseNormalisedOverrideConfigWithoutAPI[FunctionInterfaceType],
    Generic[FunctionInterfaceType, APIInterfaceType],
):
    """Base class for normalized override config with API overrides."""

    apis: InterfaceOverride[APIInterfaceType] = lambda original_implementation: (
        original_implementation
    )

    @classmethod
    def from_input_config(  # type: ignore - invalid override due to subclassing
        cls,
        override_config: Optional[
            BaseOverrideConfig[FunctionInterfaceType, APIInterfaceType]
        ],
    ) -> "BaseNormalisedOverrideConfig[FunctionInterfaceType, APIInterfaceType]":  # type: ignore
        """Create a normalized config from the input config."""
        normalised_config = cls()

        if override_config is None:
            return normalised_config

        if override_config.functions is not None:
            normalised_config.functions = override_config.functions

        if override_config.apis is not None:
            normalised_config.apis = override_config.apis

        return normalised_config


class BaseOverrideableConfig(CamelCaseBaseModel):
    """Base class for input config of a Recipe without any overrides, used for plugin config overrides."""

    ...


OverrideableConfigType = TypeVar("OverrideableConfigType", bound=BaseOverrideableConfig)


class BaseConfigWithoutAPIOverride(
    CamelCaseBaseModel, Generic[FunctionInterfaceType, OverrideableConfigType]
):
    """Base class for input config of a Recipe without API overrides."""

    override: Optional[BaseOverrideConfigWithoutAPI[FunctionInterfaceType]] = None

    @abstractmethod
    def to_overrideable_config(self) -> OverrideableConfigType:
        """
        Create an overrideable config from the input config.
        """
        raise NotImplementedError("Subclasses must implement this method.")

    @abstractmethod
    def from_overrideable_config(
        self,
        overrideable_config: OverrideableConfigType,
    ) -> "BaseConfigWithoutAPIOverride[FunctionInterfaceType, OverrideableConfigType]":
        """
        Create an input config from the overrideable config.
        Not a classmethod since it needs to be used in a dynamic context within plugins.
        """
        raise NotImplementedError("Subclasses must implement this method.")


class BaseNormalisedConfigWithoutAPIOverride(
    CamelCaseBaseModel, Generic[FunctionInterfaceType]
):
    """Base class for normalized config of a Recipe without API overrides."""

    override: BaseNormalisedOverrideConfigWithoutAPI[FunctionInterfaceType]


class BaseConfig(
    CamelCaseBaseModel,
    Generic[FunctionInterfaceType, APIInterfaceType, OverrideableConfigType],
):
    """Base class for input config of a Recipe with API overrides."""

    override: Optional[BaseOverrideConfig[FunctionInterfaceType, APIInterfaceType]] = (
        None
    )

    @abstractmethod
    def to_overrideable_config(self) -> OverrideableConfigType:
        """
        Create an overrideable config from the input config.
        """
        raise NotImplementedError("Subclasses must implement this method.")

    @abstractmethod
    def from_overrideable_config(
        self,
        overrideable_config: OverrideableConfigType,
    ) -> "BaseConfig[FunctionInterfaceType, APIInterfaceType, OverrideableConfigType]":
        """
        Create an input config from the overrideable config.
        Not a classmethod since it needs to be used in a dynamic context within plugins.
        """
        raise NotImplementedError("Subclasses must implement this method.")


class BaseNormalisedConfig(
    CamelCaseBaseModel, Generic[FunctionInterfaceType, APIInterfaceType]
):
    """Base class for normalized config of a Recipe with API overrides."""

    override: BaseNormalisedOverrideConfig[FunctionInterfaceType, APIInterfaceType]

Global variables

var APIInterfaceType

Generic Type for use in APIOverrideConfig

var FunctionInterfaceType

Generic Type for use in FunctionOverrideConfig

var T

Generic Type for use in InterfaceOverride

Classes

class BaseConfig (**data: Any)

Base class for input config of a Recipe with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseConfig(
    CamelCaseBaseModel,
    Generic[FunctionInterfaceType, APIInterfaceType, OverrideableConfigType],
):
    """Base class for input config of a Recipe with API overrides."""

    override: Optional[BaseOverrideConfig[FunctionInterfaceType, APIInterfaceType]] = (
        None
    )

    @abstractmethod
    def to_overrideable_config(self) -> OverrideableConfigType:
        """
        Create an overrideable config from the input config.
        """
        raise NotImplementedError("Subclasses must implement this method.")

    @abstractmethod
    def from_overrideable_config(
        self,
        overrideable_config: OverrideableConfigType,
    ) -> "BaseConfig[FunctionInterfaceType, APIInterfaceType, OverrideableConfigType]":
        """
        Create an input config from the overrideable config.
        Not a classmethod since it needs to be used in a dynamic context within plugins.
        """
        raise NotImplementedError("Subclasses must implement this method.")

Ancestors

Subclasses

  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, DashboardOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, EmailPasswordOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, EmailVerificationOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, JWTOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, MultiFactorAuthOverrideableConfig]
  • BaseConfig[RecipeInterface, APIInterface, MultitenancyOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, OAuth2ProviderOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, OpenIdOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, PasswordlessOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, SAMLOverrideableConfig]
  • BaseConfig[RecipeInterface, APIInterface, SessionOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, TOTPOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, ThirdPartyOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, UserMetadataOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, UserRolesOverrideableConfig]
  • supertokens_python.types.config.BaseConfig[RecipeInterface, APIInterface, WebauthnOverrideableConfig]

Class variables

var override : Optional[BaseOverrideConfig]

The type of the None singleton.

Methods

def from_overrideable_config(self, overrideable_config: ~OverrideableConfigType) ‑> BaseConfig

Create an input config from the overrideable config. Not a classmethod since it needs to be used in a dynamic context within plugins.

def to_overrideable_config(self) ‑> ~OverrideableConfigType

Create an overrideable config from the input config.

Inherited members

class BaseConfigWithoutAPIOverride (**data: Any)

Base class for input config of a Recipe without API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseConfigWithoutAPIOverride(
    CamelCaseBaseModel, Generic[FunctionInterfaceType, OverrideableConfigType]
):
    """Base class for input config of a Recipe without API overrides."""

    override: Optional[BaseOverrideConfigWithoutAPI[FunctionInterfaceType]] = None

    @abstractmethod
    def to_overrideable_config(self) -> OverrideableConfigType:
        """
        Create an overrideable config from the input config.
        """
        raise NotImplementedError("Subclasses must implement this method.")

    @abstractmethod
    def from_overrideable_config(
        self,
        overrideable_config: OverrideableConfigType,
    ) -> "BaseConfigWithoutAPIOverride[FunctionInterfaceType, OverrideableConfigType]":
        """
        Create an input config from the overrideable config.
        Not a classmethod since it needs to be used in a dynamic context within plugins.
        """
        raise NotImplementedError("Subclasses must implement this method.")

Ancestors

Subclasses

  • supertokens_python.types.config.BaseConfigWithoutAPIOverride[RecipeInterface, AccountLinkingOverrideableConfig]

Class variables

var override : Optional[BaseOverrideConfigWithoutAPI]

The type of the None singleton.

Methods

def from_overrideable_config(self, overrideable_config: ~OverrideableConfigType) ‑> BaseConfigWithoutAPIOverride

Create an input config from the overrideable config. Not a classmethod since it needs to be used in a dynamic context within plugins.

def to_overrideable_config(self) ‑> ~OverrideableConfigType

Create an overrideable config from the input config.

Inherited members

class BaseConfig[RecipeInterface, APIInterface, MultitenancyOverrideableConfig] (**data: Any)

Base class for input config of a Recipe with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Subclasses

Inherited members

class BaseConfig[RecipeInterface, APIInterface, SessionOverrideableConfig] (**data: Any)

Base class for input config of a Recipe with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Subclasses

Inherited members

class BaseNormalisedConfig (**data: Any)

Base class for normalized config of a Recipe with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseNormalisedConfig(
    CamelCaseBaseModel, Generic[FunctionInterfaceType, APIInterfaceType]
):
    """Base class for normalized config of a Recipe with API overrides."""

    override: BaseNormalisedOverrideConfig[FunctionInterfaceType, APIInterfaceType]

Ancestors

Subclasses

Class variables

var overrideBaseNormalisedOverrideConfig

The type of the None singleton.

Inherited members

class BaseNormalisedConfigWithoutAPIOverride (**data: Any)

Base class for normalized config of a Recipe without API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseNormalisedConfigWithoutAPIOverride(
    CamelCaseBaseModel, Generic[FunctionInterfaceType]
):
    """Base class for normalized config of a Recipe without API overrides."""

    override: BaseNormalisedOverrideConfigWithoutAPI[FunctionInterfaceType]

Ancestors

Subclasses

  • supertokens_python.types.config.BaseNormalisedConfigWithoutAPIOverride[RecipeInterface]

Class variables

var overrideBaseNormalisedOverrideConfigWithoutAPI

The type of the None singleton.

Inherited members

class BaseNormalisedConfig[RecipeInterface, APIInterface] (**data: Any)

Base class for normalized config of a Recipe with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Subclasses

Class variables

var model_config

The type of the None singleton.

class BaseNormalisedConfig[RecipeInterface, APIInterface]_ (**data: Any)

Base class for normalized config of a Recipe with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Subclasses

Inherited members

class BaseNormalisedOverrideConfig (**data: Any)

Base class for normalized override config with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseNormalisedOverrideConfig(
    BaseNormalisedOverrideConfigWithoutAPI[FunctionInterfaceType],
    Generic[FunctionInterfaceType, APIInterfaceType],
):
    """Base class for normalized override config with API overrides."""

    apis: InterfaceOverride[APIInterfaceType] = lambda original_implementation: (
        original_implementation
    )

    @classmethod
    def from_input_config(  # type: ignore - invalid override due to subclassing
        cls,
        override_config: Optional[
            BaseOverrideConfig[FunctionInterfaceType, APIInterfaceType]
        ],
    ) -> "BaseNormalisedOverrideConfig[FunctionInterfaceType, APIInterfaceType]":  # type: ignore
        """Create a normalized config from the input config."""
        normalised_config = cls()

        if override_config is None:
            return normalised_config

        if override_config.functions is not None:
            normalised_config.functions = override_config.functions

        if override_config.apis is not None:
            normalised_config.apis = override_config.apis

        return normalised_config

Ancestors

Subclasses

Class variables

var apis : Callable[[~APIInterfaceType], ~APIInterfaceType]

The type of the None singleton.

Inherited members

class BaseNormalisedOverrideConfigWithoutAPI (**data: Any)

Base class for normalized override config without API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseNormalisedOverrideConfigWithoutAPI(
    CamelCaseBaseModel, Generic[FunctionInterfaceType]
):
    """Base class for normalized override config without API overrides."""

    functions: InterfaceOverride[FunctionInterfaceType] = (
        lambda original_implementation: original_implementation
    )

    @classmethod
    def from_input_config(
        cls,
        override_config: Optional[BaseOverrideConfigWithoutAPI[FunctionInterfaceType]],
    ) -> "BaseNormalisedOverrideConfigWithoutAPI[FunctionInterfaceType]":
        """Create a normalized config from the input config."""
        normalised_config = cls()

        if override_config is None:
            return normalised_config

        if override_config.functions is not None:
            normalised_config.functions = override_config.functions

        return normalised_config

Ancestors

Subclasses

Class variables

var functions : Callable[[~FunctionInterfaceType], ~FunctionInterfaceType]

The type of the None singleton.

Static methods

def from_input_config(override_config: Optional[BaseOverrideConfigWithoutAPI]) ‑> BaseNormalisedOverrideConfigWithoutAPI

Create a normalized config from the input config.

Inherited members

class BaseNormalisedOverrideConfig[RecipeInterface, APIInterface] (**data: Any)

Base class for normalized override config with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Class variables

var model_config

The type of the None singleton.

class BaseNormalisedOverrideConfig[RecipeInterface, APIInterface]_ (**data: Any)

Base class for normalized override config with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Inherited members

class BaseOverrideConfig (**data: Any)

Base class for input override config with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseOverrideConfig(
    BaseOverrideConfigWithoutAPI[FunctionInterfaceType],
    Generic[FunctionInterfaceType, APIInterfaceType],
):
    """Base class for input override config with API overrides."""

    apis: UseDefaultIfNone[Optional[InterfaceOverride[APIInterfaceType]]] = (
        lambda original_implementation: original_implementation
    )

Ancestors

Subclasses

Class variables

var apis : Optional[Callable[[~APIInterfaceType], ~APIInterfaceType]]

The type of the None singleton.

Inherited members

class BaseOverrideConfigWithoutAPI (**data: Any)

Base class for input override config without API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseOverrideConfigWithoutAPI(CamelCaseBaseModel, Generic[FunctionInterfaceType]):
    """Base class for input override config without API overrides."""

    functions: UseDefaultIfNone[Optional[InterfaceOverride[FunctionInterfaceType]]] = (
        lambda original_implementation: original_implementation
    )

Ancestors

Subclasses

  • BaseOverrideConfig
  • supertokens_python.types.config.BaseOverrideConfigWithoutAPI[RecipeInterface]

Class variables

var functions : Optional[Callable[[~FunctionInterfaceType], ~FunctionInterfaceType]]

The type of the None singleton.

Inherited members

class BaseOverrideConfig[RecipeInterface, APIInterface] (**data: Any)

Base class for input override config with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Class variables

var model_config

The type of the None singleton.

class BaseOverrideConfig[RecipeInterface, APIInterface]_ (**data: Any)

Base class for input override config with API overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Ancestors

Inherited members

class BaseOverrideableConfig (**data: Any)

Base class for input config of a Recipe without any overrides, used for plugin config overrides.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class BaseOverrideableConfig(CamelCaseBaseModel):
    """Base class for input config of a Recipe without any overrides, used for plugin config overrides."""

    ...

Ancestors

Subclasses

Inherited members