Skip to main content
`Ctrl`+`K`

# What is an event schema?

A Jupyter event schema defines the shape and type of an emitted event instance. This is a key piece of Jupyter Events. It tells the event listeners what they should expect when an event occurs.

In the Logging your first event!, you saw how to register a schema with the `EventLogger`.

In the next section, Defining an event schema, you will learn how to define a new schema.

So what exactly happens when we register a schema?

    from jupyter_events.logger import EventLogger

    schema = """
    $id: http://myapplication.org/example-event
    version: "1"
    title: Example Event
    description: An interesting event to collect
    properties:
       name:
          title: Name of Event
          type: string
    """

    logger = EventLogger()
    logger.register_event_schema(schema)

First, the schema is validated against Jupyter Event’s metaschema. This ensures that your schema adheres minimally to Jupyter Event’s expected form (read about how to define a schema here).

Second, a `jsonschema.Validator` is created and cached for each one of your event schemas in a “schema registry” object.

    print(logger.schemas)

    Validator class: Draft7Validator
    Schema: {
      "$id": "myapplication.org/example-event",
      "version": "1",
      "title": "Example Event",
      "description": "An interesting event to collect",
      "properties": {
        "name": {
          "title": "Name of Event",
          "type": "string"
        }
      }
    }

The registry’s validators will be used to check incoming events to ensure all outgoing, emitted events are registered and follow the expected form.

Lastly, if an incoming event is not found in the registry, it does not get emitted. This ensures that we only collect data that we explicitly register with the logger.