Skip to main content

GenericEventsManager

Overview

It is a generic class for managing events generated by an application.

Installing GenericEventsManager and Supported Versions

GenericEventsManager is available on PyPI:

$ python -m pip install generic-events-manager

GenericEventsManager officially supports Python 3.8+.

Cloning the repository

$ git clone https://github.com/tatianno/generic-events-manager.git

Example

from events_manager import GenericEventsManager
from events_manager.entities import GenericObserver


class CustomObserver(GenericObserver):

    def _exec_routine_update_obj(self, obj_new: GenericEventsManager.EventObject, obj_old: GenericEventsManager.EventObject) -> None:
        '''
        Method called each time the observed object changes state
        '''
        print(f'The object {obj_new.key} has been updated with the state {obj_new.state}')
        print(f'The previous state was {obj_old.state}')

    def _exec_routine_delete_obj(self, obj: GenericEventsManager.EventObject) -> None:
        '''
        Method called when observed object is deleted
        '''
        print(f'The object {obj.key} has been deleted')


class CustomEventsManager(GenericEventsManager):

    class EventObject(GenericEventsManager.EventObject):
        observer_class = CustomObserver

    def create(self, entity: EventObject) -> None:
        self.perfom_create(entity)

    def update(self, entity: EventObject) -> None:
        old_entity = self.get(entity.get_key())
        self.perfom_update(entity, old_entity)

    def delete(self, entity: EventObject) -> None:
        self.perfom_destroy(entity)


# Instantiating the Event Handler and Observer
events_manager = CustomEventsManager()
observer = CustomObserver()

# Dictionary containing event data
data = {
    'state' : 'ON',
    'key' : 'k1'
}

# Updating the object with the received event data
response = events_manager.event_update(data)

# Subscribing observer
obj = events_manager.get('k1')
obj.subscribe(observer)

# Dictionary containing event data
data = {
    'state' : 'OFF',
    'key' : 'k1'
}

# Updating the object with the received event data
response = events_manager.event_update(data)

# Deleting object
obj = events_manager.get('k1')
events_manager.delete(obj)

Metadata

Release files for generic-events-manager 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for generic-events-manager 0.0.6
File Interpreter ABI Platform Actions
generic_events_manager-0.0.6-py3-none-any.whl Python 3 none any Details for generic_events_manager-0.0.6-py3-none-any.whl

Release files / generic_events_manager-0.0.6-py3-none-any.whl

Download URL generic_events_manager-0.0.6-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
448351f2cef0d116015f015fa4dc80cfaebc2d19e5ea51f6a8c2b24465482418
BLAKE2b-256 checksum
How to use checksums
974bb95e684121e131f883d630f8dd6f197256e4cf088e6f1ce151c8285428f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for generic-events-manager 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page