msa.core package


msa.core.config_manager module

class msa.core.config_manager.ConfigManager(cli_config)[source]

Bases: object

A class that reads, validates, and exposes the application configuration.


Applies any command line interface overrides of configuration file values.


Returns the validated application configuration.


Loads the configuration value into memory. The file location is derived from the command line interface options.


Validates the configfile against the config schema.

msa.core.event module

class msa.core.event.Event(priority: int, schema: schema.Schema)[source]

Bases: object

The base Event Class. All other events should be subclasses of this class.

get_metadata() → Dict[KT, VT][source]

Returns the metadata of this event. Used for network serialization of an event.

init(data: Dict[KT, VT] = None) → None[source]

Sets the data property on this event. Used when creating a new event, and when deserializing an event.

Parameters:data (Dict) – Event specific data. Must follow the defined schema for the event type.
set_metadata(metadata: Dict[KT, VT]) → None[source]

Sets the metadata of this event. Used for network deserialization of an event.

Parameters:metadata (Dict) – A dictionary containing the event metadata

msa.core.event_bus module

class msa.core.event_bus.EventBus(loop)[source]

Bases: object

The event bus is responsible for tracking event queues and pushing new events into the event queues so that the event handlers can wait until a new event is sent to them via their event queue.


Creates a new event queue. Each handler should receive its own event queue.


Fires an event to each event handler via its corresponding event queue.

Parameters:new_event (msa.core.event.Event) – A subclass of msa.core.event.Event to propagate to event handlers.

msa.core.event_handler module

class msa.core.event_handler.EventHandler(loop:, event_queue: asyncio.queues.Queue, logger: logging.Logger, config: Optional[Dict[KT, VT]] = None)[source]

Bases: object

The base event handler class, all other event handlers should be a subclass of this type.


An abstract method which must be overwritten. Once the system is started, the handle method will be called repeatedly until the system shuts down. The handler must be non-blocking.


A method that wraps self.handle and handles repeatedly calling the handler while the system is still running. Called automatically by the supervisor during startup.


An optional initialization hook, may be used for executing setup code before all handlers have benn fully started.

msa.core.loader module


Loads builtin modules.

msa.core.loader.load_plugin_modules(plugin_module_names, mode)[source]

Loads plugin modules as specified in the configuration file.

  • plugin_module_names (List[str]) – Plugin module names to load. Module names should be fully qualified modules existing in msa.plugins.
  • mode (msa.core.RunMode) – The mode the system is being run in.

msa.core.supervisor module

class msa.core.supervisor.Supervisor[source]

Bases: object

The supervisor is responsible for managing the execution of the application and orchestrating the event system.


Applies the granular log levels configured in the conficuration file.

Parameters:granular_level_config (List[Dict[String, String]]) – A list of namespace to log level mappings to be applied.

Shuts down running tasks and stops the event loop, exiting the application.


Fires an event to all event listeners.

Parameters:new_event (Event) – A new instance of a subclass of Event to be propagated to other event handlers.

Returns the handler instance for a given type of handler. Used for unit tests.

Parameters:- handler_type (A type of handler.)
init(mode, cli_config)[source]

Initializes the supervisor.

  • mode (int) – A msa.core.RunMode enum value to configure which modules should be started based on the environment the system is being run in.
  • cli_config (Dict) – A dictionary containing configuration options derived from the command line interface.

Initializes application logging, setting up the global log namespace, and the supervisor log namespace.


The main coroutine that manages starting the handlers, and waiting for a shutdown signal.

Parameters:additional_coros (List[Coroutines]) – Additional coroutines to be run in the event loop.

Indicates whether the supervisor is in the process is shutting down. Used for signaling event_handlers to cancel rescheduling.


Starts the supervisor.

Parameters:additional_coros (List[Coroutines]) – a list of other coroutines to be started. Acts as a hook for specialized startup scenarios.

Schedules the supervisor to stop, and exit the application.

Module contents

class msa.core.RunMode[source]

Bases: object

CLI = 0