pyinfra.api.util module

class pyinfra.api.util.FallbackDict(*datas)

Bases: object

Combines multiple AttrData’s to search for attributes.

override_datas = None
pyinfra.api.util.ensure_host_list(hosts, inventory)
pyinfra.api.util.get_arg_value(state, host, arg)

Runs string arguments through the jinja2 templating system with a state and host. Used to avoid string formatting in deploy operations which result in one operation per host/variable. By parsing the commands after we generate the op_hash, multiple command variations can fall under one op.

class pyinfra.api.util.get_file_io(filename_or_io, mode='rb')

Bases: object

Given either a filename or an existing IO object, this context processor will open and close filenames, and leave IO objects alone.

property cache_key
close = False

Calculates the SHA1 of a file or file object using a buffer to handle larger files.

pyinfra.api.util.get_template(filename_or_string, is_string=False)

Gets a jinja2 Template object for the input filename or string, with caching based on the filename of the template, or the SHA1 of the input string.

pyinfra.api.util.log_host_command_error(host, e, timeout=0)

Make a hash from an arbitrary nested dictionary, list, tuple or set, used to generate ID’s for operations based on their name & arguments.

pyinfra.api.util.pop_global_op_kwargs(state, kwargs)

Pop and return operation global keyword arguments.

pyinfra.api.util.read_buffer(type_, io, output_queue, print_output=False, print_func=None)

Reads a file-like buffer object into lines and optionally prints the output.


Return the SHA1 of the input string.


Transform CamelCase -> snake_case.


Take a generator and unroll any sub-generators recursively. This is essentially a Python 2 way of doing yield from in Python 3 (given iterating the entire thing).