Skip to main content

python-eventemitter

Build status

A Python port of Node.js EventEmitter that supports both synchronous and asynchronous event execution

Help

See documentation for more details

Install

To install python-eventemitter, simply use pip:

$ pip install python-eventemitter

Usage

Synchronous API

from eventemitter import EventEmitter


def main():
    ee = EventEmitter()

    sounds: list[str] = []

    ee.add_listener("sound", lambda: sounds.append("woof"))
    ee.prepend_listener("sound", lambda: sounds.append("meow"))
    ee.on("sound", lambda: sounds.append("oink"))

    @ee.on("sound")
    def from_cow():
        sounds.append("moo")

    @ee.once("sound")
    def from_bee():
        sounds.append("buzz")

    ee.emit("sound")  # Run events in order
    print(sounds)  # ['meow', 'woof', 'oink', 'moo', 'buzz']


if __name__ == "__main__":
    main()

Asynchronous API

import asyncio

from eventemitter import AsyncIOEventEmitter


async def main():
    aee = AsyncIOEventEmitter()

    sounds: set[str] = set()

    aee.add_listener("sound", lambda: sounds.add("woof"))
    aee.prepend_listener("sound", lambda: sounds.add("meow"))
    aee.on("sound", lambda: sounds.add("oink"))

    @aee.on("sound")
    def from_cow():
        sounds.add("moo")

    @aee.once("sound")
    async def from_bee():
        sounds.add("buzz")

    await aee.emit("sound") # Run events concurrently
    print(sounds)  # {'woof', 'meow', 'buzz', 'moo', 'oink'}


if __name__ == "__main__":
    asyncio.run(main())

Metadata

Release files for python-eventemitter 1.0.13

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

Source distribution (sdist)

Source distribution for python-eventemitter 1.0.13
File Size Uploaded Provenance
python_eventemitter-1.0.13.tar.gz 15.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for python-eventemitter 1.0.13
File Interpreter ABI Platform
python_eventemitter-1.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 42.7 kB

Release files / python_eventemitter-1.0.13.tar.gz

Download URL python_eventemitter-1.0.13.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
35372f6a0613eb786bc158c6b2ba70167c0b82d37940b5517a0f43ea706b977f
BLAKE2b-256 checksum
How to use checksums
deaa5fbf8add73233ab8020b760b57e8313371512b3528d7d6ec63095d281458
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / python_eventemitter-1.0.13-py3-none-any.whl

Download URL python_eventemitter-1.0.13-py3-none-any.whl
Size 26.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96a01cd3b64e3d11e1b4e8521447b24d8081b359d3641de306d7ed8ce66f71ac
BLAKE2b-256 checksum
How to use checksums
f3136090fbbc0b84b58b5538f33a04dc03adfd53af098e391c8ea3c857401405
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Security for python-eventemitter 1.0.13

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.

Release history Release notifications | RSS feed

This release

1.0.13 This release

2 release files No provenance

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