Module supertokens_python.recipe.usermetadata
Expand source code
# Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
#
# This software is licensed under the Apache License, Version 2.0 (the
# "License") as published by the Apache Software Foundation.
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations
from typing import TYPE_CHECKING, Union
from .recipe import UserMetadataRecipe
from .utils import InputOverrideConfig, UserMetadataOverrideConfig
if TYPE_CHECKING:
from supertokens_python.supertokens import RecipeInit
def init(
override: Union[UserMetadataOverrideConfig, None] = None,
) -> RecipeInit:
return UserMetadataRecipe.init(override)
__all__ = [
"InputOverrideConfig", # deprecated, use `UserMetadataOverrideConfig` instead
"UserMetadataOverrideConfig",
"UserMetadataRecipe",
"init",
]
Sub-modules
supertokens_python.recipe.usermetadata.asynciosupertokens_python.recipe.usermetadata.exceptionssupertokens_python.recipe.usermetadata.interfacessupertokens_python.recipe.usermetadata.recipesupertokens_python.recipe.usermetadata.recipe_implementationsupertokens_python.recipe.usermetadata.synciosupertokens_python.recipe.usermetadata.utils
Functions
def init(override: Union[BaseOverrideConfig[RecipeInterface, APIInterface], None] = None)
Classes
class InputOverrideConfig (**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.selfis explicitly positional-only to allowselfas a field name.Ancestors
- BaseOverrideConfig
- BaseOverrideConfigWithoutAPI
- CamelCaseBaseModel
- APIResponse
- abc.ABC
- pydantic.main.BaseModel
- typing.Generic
Class variables
var model_config-
The type of the None singleton.
class UserMetadataOverrideConfig (**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.selfis explicitly positional-only to allowselfas a field name.Ancestors
- BaseOverrideConfig
- BaseOverrideConfigWithoutAPI
- CamelCaseBaseModel
- APIResponse
- abc.ABC
- pydantic.main.BaseModel
- typing.Generic
Inherited members
class UserMetadataRecipe (recipe_id: str, app_info: AppInfo, config: UserMetadataConfig)-
Helper class that provides a standard way to create an ABC using inheritance.
Expand source code
class UserMetadataRecipe(RecipeModule): recipe_id = "usermetadata" __instance = None def __init__( self, recipe_id: str, app_info: AppInfo, config: UserMetadataConfig, ): super().__init__(recipe_id, app_info) self.config = validate_and_normalise_user_input( _recipe=self, _app_info=app_info, input_config=config ) recipe_implementation = RecipeImplementation(Querier.get_instance(recipe_id)) self.recipe_implementation = self.config.override.functions( recipe_implementation ) def is_error_from_this_recipe_based_on_instance(self, err: Exception) -> bool: return isinstance(err, SuperTokensError) and ( isinstance(err, SuperTokensUserMetadataError) ) def get_apis_handled(self) -> List[APIHandled]: return [] async def handle_api_request( self, request_id: str, tenant_id: Optional[str], request: BaseRequest, path: NormalisedURLPath, method: str, response: BaseResponse, user_context: Dict[str, Any], ) -> Union[BaseResponse, None]: raise Exception("Should never come here") async def handle_error( self, request: BaseRequest, err: SuperTokensError, response: BaseResponse, user_context: Dict[str, Any], ) -> BaseResponse: raise err def get_all_cors_headers(self) -> List[str]: return [] @staticmethod def init(override: Union[UserMetadataOverrideConfig, None] = None): from supertokens_python.plugins import OverrideMap, apply_plugins config = UserMetadataConfig(override=override) def func(app_info: AppInfo, plugins: List[OverrideMap]): if UserMetadataRecipe.__instance is None: UserMetadataRecipe.__instance = UserMetadataRecipe( recipe_id=UserMetadataRecipe.recipe_id, app_info=app_info, config=apply_plugins( recipe_id=UserMetadataRecipe.recipe_id, config=config, plugins=plugins, ), ) return UserMetadataRecipe.__instance raise Exception( None, "Usermetadata recipe has already been initialised. Please check your code for bugs.", ) return func @staticmethod def reset(): if ("SUPERTOKENS_ENV" not in environ) or ( environ["SUPERTOKENS_ENV"] != "testing" ): raise_general_exception("calling testing function in non testing env") UserMetadataRecipe.__instance = None @staticmethod def get_instance() -> UserMetadataRecipe: if UserMetadataRecipe.__instance is not None: return UserMetadataRecipe.__instance raise_general_exception( "Initialisation not done. Did you forget to call the SuperTokens.init function?" )Ancestors
- RecipeModule
- abc.ABC
Class variables
var recipe_id-
The type of the None singleton.
Static methods
def get_instance() ‑> UserMetadataRecipedef init(override: Union[BaseOverrideConfig[RecipeInterface, APIInterface], None] = None)def reset()
Methods
def get_all_cors_headers(self) ‑> List[str]def get_apis_handled(self) ‑> List[APIHandled]async def handle_api_request(self, request_id: str, tenant_id: Optional[str], request: BaseRequest, path: NormalisedURLPath, method: str, response: BaseResponse, user_context: Dict[str, Any]) ‑> Optional[BaseResponse]async def handle_error(self, request: BaseRequest, err: SuperTokensError, response: BaseResponse, user_context: Dict[str, Any]) ‑> BaseResponsedef is_error_from_this_recipe_based_on_instance(self, err: Exception) ‑> bool
Inherited members