Skip to content

Factory

This module contains functions to create and manage objects.

FUNCTION DESCRIPTION
create

Create object of class with arguments and keyword arguments

create_from_config

Create object of class with dictionary

dict_to_named_tuple

Creating named tuple from dictionary

dict_to_simple_namespace

Convert dictionary to SimpleNamespace

get_class

Retrieve the relevant class from the sub-package

get_imported_modules

Get all imported modules

get_method_names

Get the names of the methods in Callable object (Class/Instance)

get_plans

Get available configurations

get_setup

Load setup from files and return as NamedTuple or Platform

load_parts

Load all parts of compound tools from configuration

load_setup_from_files

Load and initialise setup

parse_configs

Decode dictionary of configuration details to get tuples and numpy.ndarray

zip_kwargs_to_dict

Checks and zips multiple keyword arguments of lists into dictionary

Documentation last updated: 2025-06-11

Part

Bases: Protocol

Protocol for Part (i.e. component tools)

connect

connect()

Connect to the device

disconnect

disconnect()

Disconnect from the device

resetFlags

resetFlags()

Reset all flags to class attribute _default_flags

shutdown

shutdown()

Shutdown the device

create

create(obj: Callable, *args, **kwargs) -> object

Create object of class with arguments and keyword arguments

PARAMETER DESCRIPTION
obj

target class

TYPE: Callable

args

arguments for class. Defaults to tuple().

TYPE: Iterable[Any] DEFAULT: ()

kwargs

keyword arguments for class. Defaults to dict().

TYPE: Mapping[str, Any] DEFAULT: {}

RETURNS DESCRIPTION
object

object of target class

TYPE: object

create_from_config

create_from_config(config: dict) -> object

Create object of class with dictionary

PARAMETER DESCRIPTION
config

dictionary of arguments

TYPE: dict

RETURNS DESCRIPTION
object

object of target class

TYPE: object

dict_to_named_tuple

dict_to_named_tuple(
    d: dict, tuple_name: str = "Setup"
) -> tuple

Creating named tuple from dictionary

PARAMETER DESCRIPTION
d

dictionary to be transformed

TYPE: dict

tuple_name

name of new namedtuple type. Defaults to 'Setup'.

TYPE: str DEFAULT: 'Setup'

RETURNS DESCRIPTION
tuple

named tuple from dictionary

TYPE: tuple

dict_to_simple_namespace

dict_to_simple_namespace(d: dict) -> SimpleNamespace

Convert dictionary to SimpleNamespace

PARAMETER DESCRIPTION
d

dictionary to be transformed

TYPE: dict

RETURNS DESCRIPTION
SimpleNamespace

SimpleNamespace object

TYPE: SimpleNamespace

get_class

get_class(
    module_name: str, class_name: str
) -> Type[object]

Retrieve the relevant class from the sub-package

PARAMETER DESCRIPTION
module_name

name of the module using dot notation

TYPE: str

class_name

name of the class

TYPE: str

RETURNS DESCRIPTION
Type

target Class

TYPE: Type[object]

get_imported_modules

get_imported_modules(
    interested_modules: str | Sequence[str] | None = None,
) -> dict

Get all imported modules

PARAMETER DESCRIPTION
interested_modules

interested module(s). Defaults to None.

TYPE: str | Sequence[str] | None DEFAULT: None

RETURNS DESCRIPTION
dict

dictionary of imported modules

TYPE: dict

get_method_names

get_method_names(obj: Callable) -> list[str]

Get the names of the methods in Callable object (Class/Instance)

PARAMETER DESCRIPTION
obj

object of interest

TYPE: Callable

RETURNS DESCRIPTION
list[str]

list[str]: list of method names

get_plans

get_plans(
    configs: dict, registry: dict | None = None
) -> dict

Get available configurations

PARAMETER DESCRIPTION
configs

dictionary of configurations

TYPE: dict

registry

dictionary of addresses. Defaults to None.

TYPE: dict | None DEFAULT: None

RETURNS DESCRIPTION
dict

dictionary of available configurations

TYPE: dict

get_setup

get_setup(
    config_file: Path | str,
    registry_file: Path | str | None = None,
    platform_type: Type | None = None,
    silent_fail: bool = False,
) -> tuple | Any

Load setup from files and return as NamedTuple or Platform

PARAMETER DESCRIPTION
config_file

config filename

TYPE: Path | str

registry_file

registry filename. Defaults to None.

TYPE: Path | str | None DEFAULT: None

platform_type

target platform type. Defaults to None.

TYPE: Type | None DEFAULT: None

silent_fail

whether to let setup errors through without raising an exception. Defualts to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
tuple | Any

tuple|Any: named tuple or Platform object

load_parts

load_parts(configs: dict, **kwargs) -> dict

Load all parts of compound tools from configuration

PARAMETER DESCRIPTION
configs

dictionary of configuration parameters

TYPE: dict

RETURNS DESCRIPTION
dict

dictionary of part tools

TYPE: dict

load_setup_from_files

load_setup_from_files(
    config_file: Path | str,
    registry_file: Path | str | None = None,
    create_tuple: bool = True,
) -> dict | tuple

Load and initialise setup

PARAMETER DESCRIPTION
config_file

config filename

TYPE: Path | str

registry_file

registry filename. Defaults to None.

TYPE: Path | str | None DEFAULT: None

create_tuple

whether to return a named tuple, if not returns dictionary. Defaults to True.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
dict | tuple

dict|tuple: dictionary or named tuple of setup objects

parse_configs

parse_configs(
    configs: dict, addresses: dict | None = None
) -> dict

Decode dictionary of configuration details to get tuples and numpy.ndarray

PARAMETER DESCRIPTION
configs

dictionary of configuration details

TYPE: dict

addresses

dictionary of registered addresses. Defaults to None.

TYPE: dict | None DEFAULT: None

RETURNS DESCRIPTION
dict

dictionary of configuration details

TYPE: dict

zip_kwargs_to_dict

zip_kwargs_to_dict(primary_key: str, kwargs: dict) -> dict

Checks and zips multiple keyword arguments of lists into dictionary

PARAMETER DESCRIPTION
primary_key

primary keyword to be used as key

TYPE: str

kwargs

{keyword, list of values} pairs

TYPE: dict

RETURNS DESCRIPTION
dict

dictionary of (primary keyword, kwargs)

TYPE: dict

RAISES DESCRIPTION
AssertionError

Ensure the lengths of inputs are the same