Modules (pyobs.modules)

A module in pyobs is the smalles executable unit. The base class for all modules is Module, so all modules should derive from this class and, usually, implement one or more Interfaces.

Modules are usually not created directly in code, but via a configuration file, which is a YAML file that directly maps to the constructor of the module plus an additional entry class containing the full reference to the class of the module to instantiate.

Take, for instance, the StandAlone class, which has two parameters in its constructor: message and interval. So a valid configuration file would look like this:

class: pyobs.modules.test.Standalone
message: Test
interval: 5

Note that both parameters have default values, so both could be omitted from the configuration. So, this would also work:

class: pyobs.modules.test.Standalone
message: Test

In this case, interval would have to its default value of 10.


Remember that the *args and **kwargs are always forwarded to the super class(es), so the constructor of a module always also provides the parameters from Object and Module.

Quite often, a parameter will accept both an object of a given type and a dict. If this is the case, the dict must be another class definition with a class keyword, referring to a class of the given type. See, for example, the comm parameter of Module: it takes both a dict and a pyobs.comm.Comm. So in a configuration file, we can always specify a Comm object like this:

    class: pyobs.comm.sleekxmpp.XmppComm
    password: secret

An object of type XmppComm (which is a class derived from Comm) will automatically be created.

With a Comm object, proxies to other modules can easily be created (see comm for details):

camera: ICamera = self.comm['camera']

Sometimes, multiple modules have to run in a single process, so that they can access a common resource. For this case a MultiModule can contain multiple module descriptions.


class Module(name: str | None = None, label: str | None = None, own_comm: bool = True, additional_config_variables: List[str] | None = None, **kwargs: Any)

Bases: Object, IModule, IConfig

Base class for all pyobs modules.

  • name – Name of module. If None, ID from comm object is used.

  • label – Label for module. If None, name is used.

  • own_comm – If True, module owns comm and opens/closes it.

  • additional_config_variables – List of additional variable names available to remote config getter/setter.

async close() None[source]

Close module.

async execute(method: str, *args: Any, **kwargs: Any) Any[source]

Execute a local method safely with type conversion

All incoming variables in args and kwargs must be of simple type (i.e. int, float, str, bool, tuple) and will be converted to the requested type automatically. All outgoing variables are converted to simple types automatically as well.

  • method – Name of method to execute.

  • *args – Parameters for method.

  • **kwargs – Parameters for method.


Response from method call.


KeyError – If method does not exist.

async get_config_caps(**kwargs: Any) Dict[str, Tuple[bool, bool, bool]][source]

Returns dict of all config capabilities. First value is whether it has a getter, second is for the setter, third is for a list of possible options..


Dict with config caps

async get_config_value(name: str, **kwargs: Any) Any[source]

Returns current value of config item with given name.


name – Name of config item.


Current value.


ValueError – If config item of given name does not exist.

async get_config_value_options(name: str, **kwargs: Any) List[str][source]

Returns possible values for config item with given name.


name – Name of config item.


Possible values.


ValueError – If config item of given name does not exist.

async get_error_string(**kwargs: Any) str[source]

Returns description of error, if any.

async get_label(**kwargs: Any) str[source]

Returns label of module.

async get_state(**kwargs: Any) ModuleState[source]

Returns current state of module.

async get_version(**kwargs: Any) str[source]

Returns pyobs version of module.

property interfaces: List[Type[Interface]]

List of implemented interfaces.

async main() None[source]

Main loop for application.

property methods: Dict[str, Tuple[Callable[[...], Any], Signature, Dict[Any, Any]]]

List of methods.

property name: str

Returns name of module.

async open() None[source]

Open module.

quit() None[source]

Quit module.

async reset_error(**kwargs: Any) bool[source]

Reset error of module, if any. Should be overwritten by derived class to handle error resolution.

async set_config_value(name: str, value: Any, **kwargs: Any) None[source]

Sets value of config item with given name.

  • name – Name of config item.

  • value – New value.


ValueError – If config item of given name does not exist or value is invalid.

set_error_string(error: str = '') None[source]

Set error string.

async set_state(state: ModuleState, error_string: str | None = None) None[source]

Set state of module.

  • state – New state to set.

  • error_string – If given, set error string.


class MultiModule(modules: Dict[str, Module | Dict[str, Any]], shared: Dict[str, object | Dict[str, Any]] | None = None, **kwargs: Any)

Bases: Module

Wrapper for running multiple modules in a single process.

  • modules – Dictionary with modules.

  • shared – Shared objects between modules.