Skip to main content

The zope.event package provides a simple event system. It provides:

  • An event publishing system

  • A very simple event-dispatching system on which more sophisticated event dispatching systems can be built. For example, a type-based event dispatching system that builds on zope.event can be found in zope.component.

Detailed Documentation

Events

This package provides a simple event system on which application-specific event systems can be built.

Application code can generate events without being concerned about the event-processing frameworks that might handle the events.

Events are objects that represent something happening in a system. They are used to extend processing by providing processing plug points.

The package has a list of subscribers. Application code can manage subscriptions by manipulating this list. For the examples here, we’ll save the current contents away and empty the list. We’ll restore the contents when we’re done with our examples.

>>> import zope.event
>>> old_subscribers = zope.event.subscribers[:]
>>> del zope.event.subscribers[:]

The package provides a notify function, which is used to notify subscribers that something has happened:

>>> class MyEvent:
...     pass
>>> event = MyEvent()
>>> zope.event.notify(event)

The notify function is called with a single object, which we call an event. Any object will do:

>>> zope.event.notify(None)
>>> zope.event.notify(42)

An extremely trivial subscription mechanism is provided. Subscribers are simply callback functions:

>>> def f(event):
...     print 'got:', event

that are put into the subscriptions list:

>>> zope.event.subscribers.append(f)
>>> zope.event.notify(42)
got: 42
>>> def g(event):
...     print 'also got:', event
>>> zope.event.subscribers.append(g)
>>> zope.event.notify(42)
got: 42
also got: 42

To unsubscribe, simply remove a subscriber from the list:

>>> zope.event.subscribers.remove(f)
>>> zope.event.notify(42)
also got: 42

Generally, application frameworks will provide more sophisticated subscription mechanisms that build on this simple mechanism. The frameworks will install subscribers that then dispatch to other subscribers based on event types or data.

We’re done, so we’ll restore the subscribers:

>>> zope.event.subscribers[:] = old_subscribers

Download

Release files for zope.event 3.4.1

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

Source distribution (sdist)

Source distribution for zope.event 3.4.1
File Size Uploaded
zope.event-3.4.1.tar.gz 3.9 kB Details

Release files / zope.event-3.4.1.tar.gz

Download URL zope.event-3.4.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
677b5884adb59073eefb540096e5791753981fc6a96c6e34dfc1cc79c8ccdc8e
BLAKE2b-256 checksum
How to use checksums
519d2d66c40d4e1e5a99688b9f062d649e5d6539d7a69e70040c09bacf618083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

6.2

2 release files

6.1

2 release files

6.0

2 release files

5.1.1

2 release files

5.1

2 release files

5.0

2 release files

4.6

2 release files

4.5.1

2 release files

4.5.0

2 release files

4.4

2 release files

4.3.0

2 release files

4.2.0

3 release files

4.1.0

1 release file

4.0.3

1 release file

4.0.2

1 release file

4.0.1

1 release file

4.0.0

1 release file

3.5.2

1 release file

3.5.1

1 release file

3.5.0

1 release file

This release

3.4.1 This release

1 release file

3.4.0

2 release files

3.3.0

1 release file

1.0

1 release file

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