Skip to main content

Jupyter Event System library

Project description

Jupyter Events

An event system for Jupyter Applications and extensions.

Jupyter Events enables Jupyter Applications (e.g. Jupyter Server, Jupyter Notebook, JupyterLab, JupyterHub, etc.) to emit events—i.e. actions by application users—to remote (or local) destinations as structured data. It works with Python's standard logging library to handle the transmission of events allowing users to send events to local files, over the web, etc.

Install

The Jupyter Events library can be installed from PyPI.

pip install jupyter_events

Basic Usage

Jupyter Events provides a configurable traitlets object, EventLogger, for emitting structured event data in Python. It leverages Python's standard logging library for filtering, routing, and emitting events. All events are validated (using jsonschema) against registered JSON schemas.

Let's look at a basic example of an EventLogger.

import logging
from jupyter_events import EventLogger


logger = EventLogger(
    # Use logging handlers to route where events
    # should be record.
    handlers=[
        logging.FileHandler('events.log')
    ],
    # List schemas of events that should be recorded.
    allowed_schemas=[
        'uri.to.event.schema'
    ]
)

EventLogger has two configurable traits:

  • handlers: a list of Python's logging handlers.
  • allowed_schemas: a list of event schemas to record.

Event schemas must be registered with the EventLogger for events to be recorded. An event schema looks something like:

{
  "$id": "url.to.event.schema",
  "title": "My Event",
  "description": "All events must have a name property.",
  "type": "object",
  "properties": {
    "name": {
      "title": "Name",
      "description": "Name of event",
      "type": "string"
    }
  },
  "required": ["name"],
  "version": 1
}

2 fields are required:

  • $id: a valid URI to identify the schema (and possibly fetch it from a remote address).
  • version: the version of the schema.

The other fields follow standard JSON schema structure.

Schemas can be registered from a Python dict object, a file, or a URL. This example loads the above example schema from file.

# Register the schema.
logger.register_schema_file('schema.json')

Events are recorded using the record_event method. This method validates the event data and routes the JSON string to the Python logging handlers listed in the EventLogger.

# Record an example event.
event = {'name': 'example event'}
logger.record_event(
    schema_id='url.to.event.schema',
    version=1,
    event=event
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_events-0.1.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_events-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_events-0.1.0.tar.gz.

File metadata

  • Download URL: jupyter_events-0.1.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for jupyter_events-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59033a19fee00cae52826527d3973b3ad22ad8cb43704e52f78757d370357b66
MD5 14223f338cac67521f55549d458d5f66
BLAKE2b-256 69c598a1ebe721ae1f55f807c621dbdb3c73cf306facad10446f6fc5143f6342

See more details on using hashes here.

File details

Details for the file jupyter_events-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jupyter_events-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for jupyter_events-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5be056129ef563e2a420568672ada36b0aab4ebb91370f12044567c375a62e5
MD5 4bc050f4351297042d56c607954c3942
BLAKE2b-256 c9e327616d3b29bea10025187a8fbae05922679b91b0f83f58dbbe66c3734ef5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page