# pyinfra.api.inventory module

class `pyinfra.api.inventory.``Inventory`(names_data, ssh_user=None, ssh_port=None, ssh_key=None, ssh_key_password=None, ssh_password=None, **groups)

  Bases: `object`

  Represents a collection of target hosts. Stores and provides access to group data, host data and default data for these hosts.

  Parameters:

  - names_data – tuple of `(names, data)`
  - ssh_user – default SSH user
  - ssh_port – default SSH port
  - ssh_key – default SSH key filename
  - ssh_key_password – default password for the SSH key
  - ssh_password – default SSH password
  - **groups – map of group names -> `(names, data)`

  `get_data`()

    Get the base/all data attached to this inventory.

  `get_group`(name, default=<class 'pyinfra.api.exceptions.NoGroupError'>)

    Get a list of hosts belonging to a group.

  `get_group_data`(group)

    Get data for a single group in this inventory.

  `get_groups_data`(groups)

    Gets aggregated data from a list of groups. Vars are collected in order so, for any groups which define the same var twice, the last group’s value will hold.

  `get_host`(name, default=<class 'pyinfra.api.exceptions.NoHostError'>)

    Get a single host by name.

  `get_host_data`(hostname)

    Get data for a single host in this inventory.

  `get_override_data`()

    Get override data for this inventory.

  `iter_all_hosts`()

    Iterates over all inventory hosts, active or not.

  `len_all_hosts`()

    Returns the number of hosts in the inventory, active or not.

  `state` = None