https://docs.pyinfra.com/en/2.x/inventory-data.html should mention pyinfra.host.groups
Reading https://docs.pyinfra.com/en/2.x/inventory-data.html I didn't see any way to access the set of groups that a host is in. Printing dir(pyinfra.host) didn't help, since it looks like this:
['annotations', 'class', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'getstate', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_check_state', 'check_can_rsync', 'connect', 'connected', 'connection', 'create_fact', 'current_deploy_data', 'current_deploy_kwargs', 'current_deploy_name', 'current_op_hash', 'delete_fact', 'deploy', 'disconnect', 'executing_op_hash', 'get_deploy_data', 'get_fact', 'get_file', 'group_data', 'host_data', 'in_deploy', 'in_op', 'loop', 'nested_executing_op_hash', 'noop', 'print_prefix', 'put_file', 'reload_fact', 'rsync', 'run_shell_command', 'style_print_prefix']
Finally, code search showed me that there is a pyinfra.host.groups: list[str]. I suggest putting that in the doc page I was reading, if not also making a real pyinfra.host.groups attribute that can be discovered more easily.