Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add API for event listeners #7

Closed
Zsailer opened this issue Aug 11, 2022 · 0 comments · Fixed by #10
Closed

Feature request: add API for event listeners #7

Zsailer opened this issue Aug 11, 2022 · 0 comments · Fixed by #10
Labels
enhancement New feature or request

Comments

@Zsailer
Copy link
Member

Zsailer commented Aug 11, 2022

One way to extend Jupyter's Event system would be to enable extensions/plugins of Jupyter Applications to listen for specific events and trigger a callback function. One common use-case would be to enable an extension to emit additional event data that immediately follows the source event.

I think the easiest way to achieve this is to add a simple API to the main EventLogger object, something like:

class EventLogger:
    listeners: dict
    ...
    def add_listener(self, schema_id: str, version: int, listener) -> None:
        ...

    def emit(self, schema_id: str, version: int, data: dict) -> dict:
        ...
        # Event has already been validated and emitted
        for listener in self.listeners[(schema_id, version)]:
            listener(self, schema_id, version, data)

where the signature of the callback is :

def my_listener(logger: EventLogger, schema_id:str, version: int, data: dict) -> None:
    ...

data is the raw (validated) event data.

@Zsailer Zsailer added the enhancement New feature or request label Aug 11, 2022
@Zsailer Zsailer mentioned this issue Aug 11, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant