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:
  1. Click documentation

class fastapi_mvc.cli.ClickAliasedCommand(alias='', *args, **kwargs)

Bases: Command

Defines base class for all concrete fastapi-mvc CLI commands.

Parameters:
  • alias (str) – Given command alias.

  • *args (Any) – Parent class constructor args.

  • **kwargs (Any) – Parent class constructor kwargs.

alias

Command alias.

Type:

str

Resources:
  1. click.Command class documentation

class fastapi_mvc.cli.ClickAliasedGroup(*args, **kwargs)

Bases: Group

Custom click.Group class implementation.

Parameters:
  • *args (Any) – Parent class constructor args.

  • **kwargs (Any) – Parent class constructor kwargs.

aliases

Map of command aliases to their names.

Type:

str

Resources:
  1. click.Group class documentation

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:
Return type:

None

format_commands(ctx, formatter)

Write all the commands into the formatter if they exist.

Parameters:
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 Command class 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:

Optional[click.Command]

class fastapi_mvc.cli.GeneratorCommand(category='Other', *args, **kwargs)

Bases: ClickAliasedCommand

Defines base class for all concrete fastapi-mvc generators.

Parameters:
  • category (str) – Given name under which generator should be printed in fastapi-mvc generate CLI command help page.

  • *args (Any) – Parent class constructor args.

  • **kwargs (Any) – Parent class constructor kwargs.

category

Name under which generator should be printed in fastapi-mvc generate CLI command help page.

Type:

str

format_epilog(ctx, formatter)

Write the epilog into the formatter if it exists.

Parameters:
Return type:

None

class fastapi_mvc.cli.GeneratorsMultiCommand(generators, alias='', *args, **kwargs)

Bases: _MultiCommand

Custom click.MultiCommand class implementation.

Parameters:
  • generators (Dict[str, GeneratorCommand]) – Given dictionary containing all available fastapi-mvc generators.

  • alias (str) – Given command alias.

  • *args (Any) – Parent class constructor args.

  • **kwargs (Any) – Parent class constructor kwargs.

generators

Dictionary containing all available fastapi-mvc generators.

Type:

Dict[str, Generator]

generators_aliases

Map of generator aliases to their names.

Type:

Dict[str, str]

Resources:
  1. click.MultiCommand class documentation

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:
Return type:

None

get_command(ctx, name)

Return GeneratorCommand class object instance.

Given a context and a command name or alias, this returns a GeneratorCommand class 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:

click.Command

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:

List[str]

fastapi_mvc.cli.cli.cli(*args, **kwargs)

Define command-line interface root.

Parameters:
  • 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.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.

Parameters:
  • app_path (str) – Destination path where to render the project.

  • 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.generate.get_generate_cmd()

Return command-line interface generate command.

Returns:

Class object instance.

Return type:

GeneratorsMultiCommand

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:
  1. Click Arguments

  2. Click Options

  3. Copier Docs

fastapi_mvc.generators.ControllerGenerator(*args, **kwargs)

Define controller generator command-line interface.

Parameters:
  • name (str) – Given controller name.

  • endpoints (List[str]) – Given controller endpoints.

  • 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.generators.GeneratorGenerator(*args, **kwargs)

Define generator generator command-line interface.

Parameters:
  • name (str) – Given generator name.

  • 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.generators.ScriptGenerator(*args, **kwargs)

Define script generator command-line interface.

Parameters:
  • name (str) – Given script name.

  • 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.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:

Dict[str, click.Command]

Resources:
  1. Importing programmatically

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:

str

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.

Returns:

Tuple containing git username and email.

Return type:

Tuple[str, str]

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.

Parameters:
  • project_root (Optional[str]) – Given fastapi-mvc project root path.

  • answers_file (str) – Given name of Copier answers_file relative to project root.

Returns:

Loaded answers data.

Return type:

Dict[str, Any]

fastapi_mvc.utils.ensure_permissions(path, r=True, w=False, x=False)

Ensure correct permissions to given path.

Parameters:
  • path (str) – Given path to check.

  • r (bool) – Check read ok.

  • w (bool) – Check write ok.

  • x (bool) – Check executable ok.

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:

Dict[str, Any]

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:
Return type:

None