flask_imp¶
Flask-IMP
- class flask_imp.__init__.Imp(app=None, config=None)¶
Bases:
object- Parameters:
app (Flask)
config (ImpConfig)
- app: Flask¶
- app_name: str¶
- app_path: Path¶
- app_instance_path: Path¶
- app_folder: Path¶
- app_resources_imported: bool = False¶
- model_registry: ModelRegistry¶
- init_app(app, config=None)¶
Initializes the app with the flask-imp extension.
- Parameters:
app (Flask) – the flask app to initialize
config (ImpConfig | None) – the ImpConfig to use
- Return type:
None
- import_app_resources(folder='resources', factories=None, static_folder='static', templates_folder='templates', scope_import=None)¶
Imports the app resources from the given folder.
- Parameters:
folder (str) – the folder to import from, must be relative
factories (List[str] | None) – a list of function names to call with the app instance
static_folder (str) – the name of the static folder (if not found will be set to None)
templates_folder (str) – the name of the templates folder (if not found will be set to None)
scope_import (Dict[str, List[str] | str] | None) – a dict of files to import e.g. {“folder_name”: “*”}
- Returns:
None
- Return type:
None
- register_imp_blueprint(imp_blueprint)¶
Manually register a ImpBlueprint.
- Parameters:
imp_blueprint (ImpBlueprint) – the manually imported ImpBlueprint
- Return type:
None
- import_blueprint(blueprint, package=None)¶
Import a blueprint from the given package.
- Parameters:
blueprint (str) – the blueprint (folder name) to import.
package (str | None) – the relative package to import from.
- Return type:
None
- import_blueprints(folder, package=None)¶
Import all blueprints from the given folder.
- Parameters:
folder (str) – The folder to import from. Must be relative
package (str | None) – the relative package to import from.
- Return type:
None
- import_models(file_or_folder)¶
Import all models from the given file or folder.
- Parameters:
file_or_folder (str) – The file or folder to import from. Must be relative
- Return type:
None
- model(class_)¶
Returns the model class for the given ORM class name.
- Parameters:
class – The class name of the model to return
class_ (str)
- Returns:
The model class [DefaultMeta]
- Return type:
DefaultMeta | Any
- model_meta(class_)¶
Returns meta information for the given ORM class name.
- Parameters:
class – the class name of the model to return [Class Instance | Name of class as String]
class_ (str | DefaultMeta)
- Returns:
dict of meta-information
- Return type:
Dict[str, Any]
- class flask_imp.__init__.ImpBlueprint(dunder_name, config)¶
Bases:
BlueprintA Class that extends the capabilities of the Flask Blueprint class.
- Parameters:
dunder_name (str)
config (ImpBlueprintConfig)
- models: t.Set[t.Any]¶
- database_binds: t.Set[t.Any]¶
- nested_blueprints: t.Set[t.Union['ImpBlueprint', Blueprint]]¶
- package: str¶
- location: Path¶
- bp_name: str¶
- config: ImpBlueprintConfig¶
- as_flask_blueprint()¶
Returns the blueprint as a Flask Blueprint.
- Returns:
Blueprint
- Return type:
Blueprint
- import_resources(folder='routes')¶
Will import all the resources (cli, routes, filters, context_processors…) from the given folder. Given folder must be relative to the blueprint (in the same folder as the __init__.py file).
- Parameters:
folder (str) – the folder to look for resources in. Defaults to “routes”. Must be relative
- Return type:
None
- import_nested_blueprint(blueprint)¶
Imports the specified Flask-Imp Blueprint or a standard Flask Blueprint as a nested blueprint, under the current blueprint.
- Parameters:
blueprint (str | Path) – the blueprint (folder name) to import. Must be relative
- Return type:
None
- import_nested_blueprints(folder)¶
Imports all blueprints in the given folder.
- Parameters:
folder (str) – the folder to look for nested blueprints in.
- Return type:
None
- import_models(file_or_folder)¶
Same actions as
Imp.import_models(), but scoped to the current blueprint’s package.- Parameters:
file_or_folder (str) – the file or folder to import from. Must be relative
- Return type:
None
- tmpl(template)¶
Pushes the blueprint name to the template name.
This is useful if you ever want to change the name of the blueprint.
- Parameters:
template (str) – the template name to push the blueprint name to
- Returns:
the template name with the blueprint name pushed to it
- Return type:
str