Skip to content

[utils]

Shared utils used across declearn.

The functions and classes exposed by this submodule are listed below, grouped thematically.

Config serialization

Tools to create JSON config dumps of objects and instantiate from them.

  • ObjectConfig: Dataclass to wrap objects' config and interface JSON dumps.
  • deserialize_object: Instantiate an object from an ObjectConfig or a JSON file.
  • serialize_object: Return an ObjectConfig wrapping a given (supported) object.

Types-registration

Tools to map class constructors to (name, group) string tuples.

JSON-serialization

Tools to add support for 3rd-party or custom types in JSON files.

  • add_json_support: Register a (pack, unpack) pair of functions to use on a given type.
  • json_dump: Function to dump data to a JSON file, automatically using json_pack.
  • json_load: Function to load data from a JSON file, automatically using json_unpack.
  • json_pack: Function to use as default parameter in json.dump to extend it.
  • json_unpack: Function to use as object_hook parameter in json.load to extend it.

And examples of pre-registered (de)serialization functions:

Device-policy utils

Utils to access or update parameters defining a global device-selection policy.

Logging utils

Utils to set up and configure loggers:

  • get_logger: Access or create a logger, automating basic handlers' configuration.
  • LOGGING_LEVEL_MAJOR: Custom "MAJOR" severity level, between stdlib "INFO" and "WARNING".

Miscellaneous

  • Aggregate: Abstract base dataclass for cross-peers data aggregation containers.
  • TomlConfig: Abstract base class to define TOML-parsable configuration containers.
  • dataclass_from_func: Automatically build a dataclass matching a function's signature.
  • dataclass_from_init: Automatically build a dataclass matching a class's init signature.
  • run_as_processes: Run coroutines concurrently within individual processes.