event-collector
Event-collector is a toolkit for creating lightweight event processing pipelines.
This library implements an in-memory competing consumer queue using only Python standard library functions and asyncio primitives. The collector queue runs as asyncio background tasks and can autoscale according to load. Using collector queues you can set up data processing workflows quickly without having to deploy a heavy stack of external services.
Requirements
>= Python 3.13
The only external dependencies are the following:
orjsonstructlog
Documentation
How to install
Using pip:
pip install event-collector
Or, if using uv:
uv add event-collector
Quickstart example
To run a collector queue with an event collector, we need to perform the following steps:
- create a
Collectorwith an event handling function to process events; - configure a
CollectorQueueto run background consumer tasks that will wait for input events; - run the collector queue and publish events to the queue.
"""
example.py
"""
import asyncio
import json
import sys
from event_collector import (
Collector,
CollectorQueue,
Context,
Payload,
Ok,
Result,
)
async def event_handler(payload: Payload, ctx: Context) -> Result:
"""
Extract the input data and return a result dict wrapped in
an "Ok" Result object. Also simulate a backend processing delay.
"""
data = payload.value
result = {
"data": data,
"status": "OK",
}
await asyncio.sleep(1)
return Ok(result)
async def main() -> None:
"""
Create a Collector with the event handler and initialize
a CollectorQueue with it. Run the queue and send a batch
of event payloads to the collector.
We'll set "report_interval" to a positive value (a
report interval in seconds) so the collector queue will
print runtime metrics at the specified interval on the
stdout log output.
"""
collector = Collector("demo-collector", event_handler)
async with CollectorQueue(
[collector],
min_consumers=1,
max_consumers=100,
report_interval=1.0,
) as collector_queue:
# Send event payloads to the event handler.
publisher = collector_queue.get_publisher()
for i in range(3):
payload = Payload({"payload": f"payload data {i}"})
event = await publisher.send(payload)
# The publisher.send() call returns a CollectorEvent
# object. We await the event object -- it will block
# until the result is ready -- then fetch the
# results from a ResultList.
result_list = await event.wait()
result = result_list.first().unwrap()
# Print the result in JSON format.
print(json.dumps(result))
if __name__ == "__main__":
asyncio.run(main())
sys.exit(0)
The collector queue will emit logs with runtime metrics.
Run the example code using the following command (we'll pipe the output to jq to format the log output):
python example.py | jq .
Here is the printed result with part of the metrics log output:
(.venv) [event-collector]$ python example.py | jq .
...
[snip]
{
"logger": "CollectorQueue-107974cacc474a3298202c299d1497d8",
"metrics_timestamp": "2026-05-06T05:57:01.322421+00:00",
"qsize": 0,
"busy": 1,
"consumers": 2,
"load": 0.5,
"avg_load": 0.5,
"service_time": 1.0007,
"wait_time": 1.0023,
"arrival_rate": 0.0,
"departure_rate": 0.0,
"wip": 0.0,
"t_delta": 0.0,
"event_count": 2,
"event": "collector queue metrics",
"level": "info",
"timestamp": "2026-05-06T05:57:01.399931Z"
}
{
"data": {
"payload": "payload data 0"
},
"status": "OK"
}
{
"data": {
"payload": "payload data 1"
},
"status": "OK"
}
{
"data": {
"payload": "payload data 2"
},
"status": "OK"
}
Example projects
See the event-collector-examples repository for example projects using event-collector to implement HTTP API and MQTT listener services:
Contact
- Kevin Chan
<kc@kchan.io>
Metadata
Release files for event-collector 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| event_collector-0.2.4.tar.gz | 24.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| event_collector-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.8 kB
Release files / event_collector-0.2.4.tar.gz
| Download URL | event_collector-0.2.4.tar.gz |
|---|---|
| Size | 24.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0d678461e4e347a158a1870ca8b2d8751252b859ddcd8d0158f25402ff077f0
|
|
BLAKE2b-256 checksum How to use checksums |
ce097b8684e93f2ec69f10057c765604d7fcaa6f0e9e643db503e9c724f93bdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / event_collector-0.2.4-py3-none-any.whl
| Download URL | event_collector-0.2.4-py3-none-any.whl |
|---|---|
| Size | 29.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e388f0a3b4068fa10a5c74cf497a156f4cf7276a45143437c9a7e31e898d704
|
|
BLAKE2b-256 checksum How to use checksums |
05d5c90c5827eff493291a12e78351a2b4336f965d04ff6b66da70781b5c9a71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for event-collector 0.2.4
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.