flask_imp¶
Flask-IMP
- class flask_imp.__init__.Imp(app=None, config=None)¶
Bases:
object- Parameters:
app (Flask)
config (ImpConfig)
- app_resources_imported: bool = False¶
- 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
- import_resources(folder='resources', factories='include', scope_import=None)¶
Will import resources (cli, routes, filters, context_processors…) from the given folder under the defined factory/factories.
The given folder must be relative to the root of the app.
Example factories:
# If `import_resources(..., factories="production")` # `production` will be included, `development` will be skipped. def production(app): @app.route("/") def index(): ... def development(app): @app.route("/") def new(): ... # If `import_resources(..., factories=["production", "development"])` # both `production` and `development` will be included.
scope_importis used to import only specific files from a folder. It expects a dict where the keys are folder names and the values are lists of file names to import.scope_importdefaults to {“*”: [“*”]} - this will import all folders{"*":and all files: ["*"]}in those folders.“*” : All folders / All Files “.” : Root of the Resources Folder
Example scoping:
# will only import files "file_name_1" and "file_name_2" # from folder "folder_name": {"folder_name": ["file_name_1", "file_name_2"]} # will only import files "file_name_1" and "file_name_2" from the root of the # resources folder: {".": ["file_name_1", "file_name_2"]}
- Parameters:
folder (str) – the folder to import from, must be relative
factories (List[str] | str | None) – a list of function names to call with the app instance, defaults to [“include”]
scope_import (Dict[str, List[str] | str] | None) – a dict of files to import e.g. {“folder_name”: “*”}
- Returns:
None
- Return type:
None
- 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
- 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]
- register_imp_blueprint(imp_blueprint)¶
Manually register a ImpBlueprint.
- Parameters:
imp_blueprint (ImpBlueprint) – the manually imported ImpBlueprint
- Return type:
None
- app: Flask¶
- app_name: str¶
- app_path: Path¶
- app_instance_path: Path¶
- app_folder: Path¶
- model_registry: ModelRegistry¶
- 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)
- as_flask_blueprint()¶
Returns the blueprint as a Flask Blueprint.
- Returns:
Blueprint
- Return type:
Blueprint
- 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
- 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_resources(folder='resources', factories='include', scope_import=None)¶
Will import resources (cli, routes, filters, context_processors…) from the given folder under the defined factory/factories.
The given folder must be relative to the root of the blueprint.
Example factories:
# If `import_resources(..., factories="production")` # `production` will be included, `development` will be skipped. def production(app): @app.route("/") def index(): ... def development(app): @app.route("/") def new(): ... # If `import_resources(..., factories=["production", "development"])` # both `production` and `development` will be included.
scope_importis used to import only specific files from a folder. It expects a dict where the keys are folder names and the values are lists of file names to import.scope_importdefaults to {“*”: [“*”]} - this will import all folders{"*":and all files: ["*"]}in those folders.“*” : All folders / All Files “.” : Root of the Resources Folder
Example scoping:
# will only import files "file_name_1" and "file_name_2" # from folder "folder_name": {"folder_name": ["file_name_1", "file_name_2"]} # will only import files "file_name_1" and "file_name_2" from the root of the # resources folder: {".": ["file_name_1", "file_name_2"]}
- Parameters:
folder (str) – the folder to import from - must be relative
factories (List[str] | str | None) – a list of or single function name(s) to pass the blueprint instance to and call. Defaults to “include”
scope_import (Dict[str, List[str] | str] | None) – a dict of files to import e.g. {“folder_name”: “*”}
- Returns:
None
- 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
- config: ImpBlueprintConfig¶
- location: Path¶
- bp_name: str¶
- package: str¶
- models: t.Set[t.Any]¶
- nested_blueprints: t.Set[t.Union['ImpBlueprint', Blueprint]]¶
- database_binds: t.Set[t.Any]¶