API¶
This part of the documentation lists the full API reference of all classes and functions.
CLI¶
Command-line interface.
The fastapi_mvc.cli submodule defines Click command-line interface root and
its commands.
- Resources:
- class fastapi_mvc.cli.ClickAliasedCommand(alias='', *args, **kwargs)¶
Bases:
CommandDefines base class for all concrete fastapi-mvc CLI commands.
- Parameters:
- Resources:
- class fastapi_mvc.cli.ClickAliasedGroup(*args, **kwargs)¶
Bases:
GroupCustom click.Group class implementation.
- Parameters:
- Resources:
- add_command(cmd, name=None)¶
Register another Command class object instance with this group.
If the name is not provided, the name of the command is used.
- Parameters:
cmd (click.Command) – Command class object instance to register.
- Return type:
None
- format_commands(ctx, formatter)¶
Write all the commands into the formatter if they exist.
- Parameters:
ctx (click.Context) – Click Context class object instance.
formatter (click.HelpFormatter) – Click HelpFormatter class object instance.
- Return type:
None
- get_command(ctx, cmd_name)¶
Return Command class object instance.
Given a context and a command name or alias, this returns a
Commandclass object instance if it exists.- Parameters:
ctx (click.Context) – Click Context class object instance.
cmd_name (str) – Chosen command name.
- Returns:
- Command class object instance for given
command name.
- Return type:
- class fastapi_mvc.cli.GeneratorCommand(category='Other', *args, **kwargs)¶
Bases:
ClickAliasedCommandDefines base class for all concrete fastapi-mvc generators.
- Parameters:
- category¶
Name under which generator should be printed in
fastapi-mvc generateCLI command help page.- Type:
- format_epilog(ctx, formatter)¶
Write the epilog into the formatter if it exists.
- Parameters:
ctx (click.Context) – Click Context class object instance.
formatter (click.HelpFormatter) – Click HelpFormatter class object instance.
- Return type:
None
- class fastapi_mvc.cli.GeneratorsMultiCommand(generators, alias='', *args, **kwargs)¶
Bases:
_MultiCommandCustom click.MultiCommand class implementation.
- Parameters:
- Resources:
- format_commands(ctx, formatter)¶
Write all the generators into the formatter if they exist.
Extra format methods for multi methods that adds all the generators after the options.
- Parameters:
ctx (click.Context) – Click Context class object instance.
formatter (click.HelpFormatter) – Click HelpFormatter class object instance.
- Return type:
None
- get_command(ctx, name)¶
Return GeneratorCommand class object instance.
Given a context and a command name or alias, this returns a
GeneratorCommandclass object instance if it exists or aborts the execution of the program.- Parameters:
ctx (click.Context) – Click Context class object instance.
name (str) – Chosen generator name.
- Returns:
Command class object instance for given command name.
- Return type:
- list_commands(ctx)¶
Return a list of subcommand names in the order they should appear.
- Parameters:
ctx (click.Context) – Click Context class object instance.
- Returns:
List of subcommand names.
- Return type:
- fastapi_mvc.cli.cli.cli(*args, **kwargs)¶
Define command-line interface root.
- fastapi_mvc.cli.run.run(*args, **kwargs)¶
Define command-line interface run command.
- Parameters:
ctx (click.Context) – Click Context class object instance.
options (Dict[str, Any]) – Map of command option names to their parsed values.
args (t.Any) –
kwargs (t.Any) –
- Return type:
t.Any
- fastapi_mvc.cli.new.new(*args, **kwargs)¶
Define command-line interface new command.
- fastapi_mvc.cli.generate.get_generate_cmd()¶
Return command-line interface generate command.
- Returns:
Class object instance.
- Return type:
- fastapi_mvc.cli.update.update(*args, **kwargs)¶
Define command-line interface update command.
- Parameters:
ctx (click.Context) – Click Context class object instance.
options (Dict[str, Any]) – Map of command option names to their parsed values.
args (t.Any) –
kwargs (t.Any) –
- Return type:
t.Any
Generators¶
Fastapi-mvc generators.
Fastapi-mvc comes with a number of scripts called generators that are designed to make your development life easier by creating everything that’s necessary to start working on a particular task.
- Each generator is build of the following:
A copier template.
Click options and arguments for creating generator CLI subcommand.
Method for creating thing it generates.
- Resources:
- fastapi_mvc.generators.ControllerGenerator(*args, **kwargs)¶
Define controller generator command-line interface.
- fastapi_mvc.generators.GeneratorGenerator(*args, **kwargs)¶
Define generator generator command-line interface.
- fastapi_mvc.generators.ScriptGenerator(*args, **kwargs)¶
Define script generator command-line interface.
- fastapi_mvc.generators.load_generators()¶
Load user fastapi-mvc generators.
Programmatically import all available user generators from known paths to search in.
- Returns:
Builtin and imported fastapi-mvc generators.
- Return type:
- Resources:
Utils¶
Fastapi-mvc utilities.
The fastapi-mvc.utils submodule implements generic utilities for the need of
the package.
- fastapi_mvc.utils.get_poetry_path()¶
Get Poetry executable abspath.
- Returns:
Poetry executable abspath.
- Return type:
- fastapi_mvc.utils.run_shell(cmd, cwd=None, check=False, stdout=None, stderr=None, input=None, capture_output=False)¶
Run shell command without activated virtualenv.
If virtual env is activated, remove it from PATH in order to ensure command proper execution. For more information, see issue: https://github.com/fastapi-mvc/fastapi-mvc/issues/37
- Parameters:
cmd (list) – Shell command to run.
cwd (str) – Path under which process should execute command. Defaults to current working directory.
check (bool) – If True raise a subprocess.CalledProcessError error when a process returns non-zero exit status.
stdout (Optional[Union[int, IO[AnyStr]]]) – Specify the executed program’s standard output file handles.
stderr (Optional[Union[int, IO[AnyStr]])) – Specify the executed program’s standard error file handles.
input (Optional[Union[bytes, str]])) – If given the input argument is passed to the subprocess’s stdin.
capture_output (bool) – If True, stdout and stderr will be captured.
- Returns:
Class object instance.
- Return type:
CompletedProcess
- Raises:
subprocess.CalledProcessError – If spawned proces finishes with an error and check is True.
- fastapi_mvc.utils.get_git_user_info()¶
Get git user information.
Reads username and email information from git. If not exists, provide defaults values.
- fastapi_mvc.utils.load_answers_file(project_root=None, answers_file='.fastapi-mvc.yml')¶
Define wrapper for Copier load_answersfile_data method.
Load answers data from a $project_root/$answers_file file if it exists.
- fastapi_mvc.utils.ensure_permissions(path, r=True, w=False, x=False)¶
Ensure correct permissions to given path.
- Parameters:
- Raises:
SystemExit – If path has insufficient permissions.
- Return type:
None
- fastapi_mvc.utils.require_fastapi_mvc_project()¶
Ensure valid fastapi-mvc project, and return loaded project data.
- Returns:
Loaded fastapi-mvc project answers data.
- Return type:
- Raises:
SystemExit – If project data is empty or is missing required values.
- fastapi_mvc.utils.excepthook.global_except_hook(exctype, value, traceback)¶
Global except hook method.
- Parameters:
exctype (Type[BaseException]) – Exception object instance.
value (BaseException) – Exception value.
traceback (Optional[types.TracebackType]) – Traceback object instance.
- Return type:
None