# aiida.cmdline package¶

The command line interface of AiiDA.

class aiida.cmdline.AbsolutePathParamType(exists=False, file_okay=True, dir_okay=True, writable=False, readable=True, resolve_path=False, allow_dash=False, path_type=None)[source]

The ParamType for identifying absolute Paths (derived from click.Path).

__module__ = 'aiida.cmdline.params.types.path'
__repr__()[source]

Return repr(self).

convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

name = 'AbsolutePath'
class aiida.cmdline.CalculationParamType(sub_classes=None)[source]

The ParamType for identifying Calculation entities or its subclasses

__abstractmethods__ = frozenset({})
__module__ = 'aiida.cmdline.params.types.calculation'
_abc_impl = <_abc_data object>
name = 'Calculation'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.CodeParamType(sub_classes=None, entry_point=None)[source]

The ParamType for identifying Code entities or its subclasses

__abstractmethods__ = frozenset({})
__init__(sub_classes=None, entry_point=None)[source]

Construct the param type

Parameters
• sub_classes – specify a tuple of Code sub classes to narrow the query set

• entry_point – specify an optional calculation entry point that the Code’s input plugin should match

__module__ = 'aiida.cmdline.params.types.code'
_abc_impl = <_abc_data object>
complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value.

Returns

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)[source]

Attempt to convert the given value to an instance of the orm class using the orm class loader.

Returns

Raises
• click.BadParameter – if the value is ambiguous and leads to multiple entities

• click.BadParameter – if the value cannot be mapped onto any existing instance

• RuntimeError – if the defined orm class loader is not a subclass of the OrmEntityLoader class

name = 'Code'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.ComputerParamType(sub_classes=None)[source]

The ParamType for identifying Computer entities or its subclasses

__abstractmethods__ = frozenset({})
__module__ = 'aiida.cmdline.params.types.computer'
_abc_impl = <_abc_data object>
complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value.

Returns

list of tuples of valid entry points (matching incomplete) and a description

name = 'Computer'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.ConfigOptionParamType[source]

Bases: click.types.StringParamType

ParamType for configuration options.

__module__ = 'aiida.cmdline.params.types.config'
complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value

Returns

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

name = 'config option'
class aiida.cmdline.DataParamType(sub_classes=None)[source]

The ParamType for identifying Data entities or its subclasses

__abstractmethods__ = frozenset({})
__module__ = 'aiida.cmdline.params.types.data'
_abc_impl = <_abc_data object>
name = 'Data'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.FileOrUrl(timeout_seconds=10, **kwargs)[source]

Extension of click’s File-type to include URLs.

Returns handle either to local file or to remote file fetched from URL.

Parameters

timeout_seconds (int) – Maximum timeout accepted for URL response. Must be an integer in the range [0;60].

__init__(timeout_seconds=10, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.types.path'
convert(value, param, ctx)[source]

Return file handle.

get_url(url, param, ctx)[source]

Retrieve file from URL.

name = 'FileOrUrl'
class aiida.cmdline.GroupParamType(create_if_not_exist=False, sub_classes='aiida.groups:core')[source]

The ParamType for identifying Group entities or its subclasses.

__abstractmethods__ = frozenset({})
__init__(create_if_not_exist=False, sub_classes='aiida.groups:core')[source]

Construct the parameter type.

The sub_classes argument can be used to narrow the set of subclasses of Group that should be matched. By default all subclasses of Group will be matched, otherwise it is restricted to the subclasses that correspond to the entry point names in the tuple of sub_classes.

To prevent having to load the database environment at import time, the actual loading of the entry points is deferred until the call to convert is made. This is to keep the command line autocompletion light and responsive. The entry point strings will be validated, however, to see if they correspond to known entry points.

Parameters
• create_if_not_exist – boolean, if True, will create the group if it does not yet exist. By default the group created will be of class Group, unless another subclass is specified through sub_classes. Note that in this case, only a single entry point name can be specified

• sub_classes – a tuple of entry point strings from the aiida.groups entry point group.

__module__ = 'aiida.cmdline.params.types.group'
_abc_impl = <_abc_data object>
complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value.

Returns

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)[source]

Attempt to convert the given value to an instance of the orm class using the orm class loader.

Returns

Raises
• click.BadParameter – if the value is ambiguous and leads to multiple entities

• click.BadParameter – if the value cannot be mapped onto any existing instance

• RuntimeError – if the defined orm class loader is not a subclass of the OrmEntityLoader class

name = 'Group'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader.

This class is supposed to be used to load the entity for a given identifier.

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.IdentifierParamType(sub_classes=None)[source]

An extension of click.ParamType for a generic identifier parameter. In AiiDA, orm entities can often be identified by either their ID, UUID or optionally some LABEL identifier. This parameter type implements the convert method, which attempts to convert a value passed to the command for a parameter with this type, to an orm entity. The actual loading of the entity is delegated to the orm class loader. Subclasses of this parameter type should implement the orm_class_loader method to return the appropriate orm class loader, which should be a subclass of aiida.orm.utils.loaders.OrmEntityLoader for the corresponding orm class.

__abstractmethods__ = frozenset({'orm_class_loader'})
__init__(sub_classes=None)[source]

Construct the parameter type, optionally specifying a tuple of entry points that reference classes that should be a sub class of the base orm class of the orm class loader. The classes pointed to by these entry points will be passed to the OrmEntityLoader when converting an identifier and they will restrict the query set by demanding that the class of the corresponding entity matches these sub classes.

To prevent having to load the database environment at import time, the actual loading of the entry points is deferred until the call to convert is made. This is to keep the command line autocompletion light and responsive. The entry point strings will be validated, however, to see if the correspond to known entry points.

Parameters

sub_classes – a tuple of entry point strings that can narrow the set of orm classes that values will be mapped upon. These classes have to be strict sub classes of the base orm class defined by the orm class loader

__module__ = 'aiida.cmdline.params.types.identifier'
_abc_impl = <_abc_data object>
convert(value, param, ctx)[source]

Attempt to convert the given value to an instance of the orm class using the orm class loader.

Returns

Raises
• click.BadParameter – if the value is ambiguous and leads to multiple entities

• click.BadParameter – if the value cannot be mapped onto any existing instance

• RuntimeError – if the defined orm class loader is not a subclass of the OrmEntityLoader class

abstract property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.LazyChoice(get_choices)[source]

This is a delegate of click’s Choice ParamType that evaluates the set of choices lazily. This is useful if the choices set requires an import that is slow. Using the vanilla click.Choice will call this on import which will slow down verdi and its autocomplete. This type will generate the choices set lazily through the choices property

__init__(get_choices)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.types.choice'
__repr__()[source]

Return repr(self).

property _click_choice

Get the internal click Choice object that we delegate functionality to. Will construct it lazily if necessary.

Returns

The click Choice

Return type

click.Choice

property choices
convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

get_metavar(param)[source]

Returns the metavar default for this param if it provides one.

get_missing_message(param)[source]

Optionally might return extra information about a missing parameter.

New in version 2.0.

name = 'choice'
class aiida.cmdline.MpirunCommandParamType[source]

Bases: click.types.StringParamType

Custom click param type for mpirun-command

Note

requires also a scheduler to be provided, and the scheduler must be called first!

Validate that the provided ‘mpirun’ command only contains replacement fields (e.g. {tot_num_mpiprocs}) that are known.

Return a list of arguments (by using ‘value.strip().split(” “) on the input string)

__module__ = 'aiida.cmdline.params.types.computer'
__repr__()[source]

Return repr(self).

convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

name = 'mpiruncommandstring'
class aiida.cmdline.MultipleValueParamType(param_type)[source]

An extension of click.ParamType that can parse multiple values for a given ParamType

__init__(param_type)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.types.multiple'
convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

get_metavar(param)[source]

Returns the metavar default for this param if it provides one.

class aiida.cmdline.NodeParamType(sub_classes=None)[source]

The ParamType for identifying Node entities or its subclasses

__abstractmethods__ = frozenset({})
__module__ = 'aiida.cmdline.params.types.node'
_abc_impl = <_abc_data object>
name = 'Node'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.NonEmptyStringParamType[source]

Bases: click.types.StringParamType

Parameter whose values have to be string and non-empty.

__module__ = 'aiida.cmdline.params.types.strings'
__repr__()[source]

Return repr(self).

convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

name = 'nonemptystring'
class aiida.cmdline.PathOrUrl(timeout_seconds=10, **kwargs)[source]

Extension of click’s Path-type to include URLs.

A PathOrUrl can either be a click.Path-type or a URL.

Parameters

timeout_seconds (int) – Maximum timeout accepted for URL response. Must be an integer in the range [0;60].

__init__(timeout_seconds=10, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.types.path'
checks_url(url, param, ctx)[source]

Check whether URL is reachable within timeout.

convert(value, param, ctx)[source]

Overwrite convert Check first if click.Path-type, then check if URL.

name = 'PathOrUrl'
class aiida.cmdline.PluginParamType(group=None, load=False, *args, **kwargs)[source]

AiiDA Plugin name parameter type.

Parameters
• group – string or tuple of strings, where each is a valid entry point group. Adding the aiida. prefix is optional. If it is not detected it will be prepended internally.

• load – when set to True, convert will not return the entry point, but the loaded entry point

Usage:

click.option(... type=PluginParamType(group='aiida.calculations')


or:

click.option(... type=PluginParamType(group=('calculations', 'data'))

__init__(group=None, load=False, *args, **kwargs)[source]

Validate that group is either a string or a tuple of valid entry point groups, or if it is not specified use the tuple of all recognized entry point groups.

__module__ = 'aiida.cmdline.params.types.plugin'
_init_entry_points()[source]

Populate entry point information that will be used later on. This should only be called once in the constructor after setting self.groups because the groups should not be changed after instantiation

complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value

Returns

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)[source]

Convert the string value to an entry point instance, if the value can be successfully parsed into an actual entry point. Will raise click.BadParameter if validation fails.

get_entry_point_from_string(entry_point_string)[source]

Validate a given entry point string, which means that it should have a valid entry point string format and that the entry point unambiguously corresponds to an entry point in the groups configured for this instance of PluginParameterType.

Returns

the entry point if valid

Raises

ValueError if the entry point string is invalid

get_missing_message(param)[source]

Optionally might return extra information about a missing parameter.

New in version 2.0.

get_possibilities(incomplete='')[source]

Return a list of plugins starting with incomplete

get_valid_arguments()[source]

Return a list of all available plugins for the groups configured for this PluginParamType instance. If the entry point names are not unique, because there are multiple groups that contain an entry point that has an identical name, we need to prefix the names with the full group name

Returns

list of valid entry point strings

property groups
property has_potential_ambiguity

Returns whether the set of supported entry point groups can lead to ambiguity when only an entry point name is specified. This will happen if one ore more groups share an entry point with a common name

name = 'plugin'
class aiida.cmdline.ProcessParamType(sub_classes=None)[source]

The ParamType for identifying ProcessNode entities or its subclasses

__abstractmethods__ = frozenset({})
__module__ = 'aiida.cmdline.params.types.process'
_abc_impl = <_abc_data object>
name = 'Process'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

class aiida.cmdline.ProfileParamType(*args, **kwargs)[source]

The profile parameter type for click.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'aiida.cmdline.params.types.profile'
complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value

Returns

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)[source]

Attempt to match the given value to a valid profile.

static deconvert_default(value)[source]
name = 'profile'
class aiida.cmdline.ShebangParamType[source]

Bases: click.types.StringParamType

Custom click param type for shebang line

__module__ = 'aiida.cmdline.params.types.computer'
__repr__()[source]

Return repr(self).

convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

name = 'shebangline'
class aiida.cmdline.TestModuleParamType[source]

Parameter type to represent a unittest module.

Defunct - remove when removing the “verdi devel tests” command.

__module__ = 'aiida.cmdline.params.types.test_module'
name = 'test module'
class aiida.cmdline.UserParamType(create=False)[source]

The user parameter type for click. Can get or create a user.

__init__(create=False)[source]
Parameters

create – If the user does not exist, create a new instance (unstored).

__module__ = 'aiida.cmdline.params.types.user'
complete(ctx, incomplete)[source]

Return possible completions based on an incomplete value

Returns

list of tuples of valid entry points (matching incomplete) and a description

convert(value, param, ctx)[source]

Converts the value. This is not invoked for values that are None (the missing value).

name = 'user'
class aiida.cmdline.WorkflowParamType(sub_classes=None)[source]

The ParamType for identifying WorkflowNode entities or its subclasses

__abstractmethods__ = frozenset({})
__module__ = 'aiida.cmdline.params.types.workflow'
_abc_impl = <_abc_data object>
name = 'WorkflowNode'
property orm_class_loader

Return the orm entity loader class, which should be a subclass of OrmEntityLoader. This class is supposed to be used to load the entity for a given identifier

Returns

the orm entity loader class for this ParamType

aiida.cmdline.dbenv()[source]

Loads the dbenv for a specific region of code, does not unload afterwards

Only use when it makes it possible to avoid loading the dbenv for certain code paths

Good Example:

# do this
@click.command()
@click.option('--with-db', is_flag=True)
def profile_info(with_db):
click.echo(profile_config)

# load the db only if necessary
if with_db:
with dbenv():
# gather db statistics for the profile
click.echo(db_statistics)


This will run very fast without the –with-db flag and slow only if database info is requested

Do not use if you will end up loading the dbenv anyway

# don't do this
def my_function():
with dbenv():

# do db unrelated stuff

aiida.cmdline.echo(message, bold=False, nl=True, err=False)[source]

Print a normal message through click’s echo function to stdout

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold

• nl – whether to print a newline at the end of the message

• err – whether to print to stderr

aiida.cmdline.echo_critical(message, bold=False, nl=True, err=True)[source]

Print an error message through click’s echo function to stdout, prefixed with ‘Critical:’ and then calls sys.exit with the given exit_status.

This should be used to print messages for errors that cannot be recovered from and so the script should be directly terminated with a non-zero exit status to indicate that the command failed

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold

• nl – whether to print a newline at the end of the message

• err – whether to print to stderr

aiida.cmdline.echo_dictionary(dictionary, fmt='json+date', sort_keys=True)[source]

Print the given dictionary to stdout in the given format

Parameters
• dictionary – the dictionary

• fmt – the format to use for printing

• sort_keys – Whether to automatically sort keys

aiida.cmdline.echo_error(message, bold=False, nl=True, err=True)[source]

Print an error message through click’s echo function to stdout, prefixed with ‘Error:’

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold

• nl – whether to print a newline at the end of the message

• err – whether to print to stderr

aiida.cmdline.echo_highlight(message, nl=True, bold=True, color='highlight')[source]

Print a highlighted message to stdout

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold

• nl – whether to print a newline at the end of the message

• color – a color from COLORS

aiida.cmdline.echo_info(message, bold=False, nl=True, err=False)[source]

Print an info message through click’s echo function to stdout, prefixed with ‘Info:’

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold

• nl – whether to print a newline at the end of the message

• err – whether to print to stderr

aiida.cmdline.echo_success(message, bold=False, nl=True, err=False)[source]

Print a success message through click’s echo function to stdout, prefixed with ‘Success:’

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold include a newline character

• nl – whether to print a newline at the end of the message

• err – whether to print to stderr

aiida.cmdline.echo_warning(message, bold=False, nl=True, err=False)[source]

Print a warning message through click’s echo function to stdout, prefixed with ‘Warning:’

Parameters
• message – the string representing the message to print

• bold – whether to print the message in bold

• nl – whether to print a newline at the end of the message

• err – whether to print to stderr

aiida.cmdline.graph_traversal_rules(rules)[source]

Apply the graph traversal rule options to the command.

aiida.cmdline.only_if_daemon_running(echo_function=<function echo_critical>, message=None)[source]

Function decorator for CLI command to print critical error and exit automatically when daemon is not running.

The error printing and exit behavior can be controlled with the decorator keyword arguments. The default message that is printed can be overridden as well as the echo function that is to be used. By default it uses the aiida.cmdline.utils.echo.echo_critical function which automatically aborts the command. The function can be substituted by for example aiida.cmdline.utils.echo.echo_warning to instead print just a warning and continue.

Example:

@only_if_daemon_running(echo_function=echo.echo_warning, message='beware that the daemon is not running')
def create_node():
pass

Parameters
• echo_function – echo function to issue the message, should be from aiida.cmdline.utils.echo

• message – optional message to override the default message

aiida.cmdline.with_dbenv()[source]

Function decorator that will load the database environment for the currently loaded profile.

Note

if no profile has been loaded yet, the default profile will be loaded first.

Example:

@with_dbenv()
def create_node():
from aiida.orm import Int  # note the local import
node = Int(1).store()