Skip to main content

Weave multiple streams of intervals into combinations

Project description

eventweave

Eventweave is a lightweight Python utility that groups overlapping events into chronological combinations. It is useful for temporal reasoning and event sourcing, allowing you to analyze and visualize the relationships between events that occur simultaneously.

Features

  • Accepts any iterable of events with user-defined start and end times
  • Yields sets of events that are simultaneously active at some point in time
  • Handles edge cases for back-to-back, non-overlapping intervals
  • Runs in O(n log n) time and O(n) space

Installation

This project is self-contained with no dependencies beyond the Python standard library.

You can install it using pip:

python -m pip install eventweave

Supported for Python 3.13 and above.

Example Usage

Define your events and a key function:

>>> from eventweave import interweave
>>>
>>> events = [
...     ("A", (1, 4)),
...     ("B", (2, 5)),
...     ("C", (5, 6)),
... ]
>>>
>>> def key(event):
...     return event[1]

Use interweave to iterate over overlapping combinations:

>>> result = list(interweave(events, key))
>>> expected = [
...     {('A', (1, 4))},
...     {('A', (1, 4)), ('B', (2, 5))},
...     {('B', (2, 5))},
...     {('C', (5, 6))},
... ]
>>> assert result == expected

Clarification of Overlapping Events

If one event ends at time T and another begins at time T, they are not considered overlapping. The model assumes the starting event ends just after T to preserve strict separation of events that merely touch.

This handling of edge cases can lead to surprising results in certain situations. For example, if a long-running event spans two shorter events - where the first ends exactly when the second starts - an additional combination may currently be produced that contains only the long-running event. This behavior may change in future versions.

Currently, instantaneous events - where the start and end times are the same - are not supported. Support will be added once their semantics are clearly defined.

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

eventweave-0.2.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

eventweave-0.2.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file eventweave-0.2.0.tar.gz.

File metadata

  • Download URL: eventweave-0.2.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for eventweave-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8e0b6bd0f8eec53c850523be2bcb79dfe7f6bb3298056449b0721016be37b449
MD5 f1f636e51290ad7b1d8a0dbab8753afd
BLAKE2b-256 7afcd6d677b992f3a2f25246fc4bff09f7b9ad1f30c9494d47e60d1fc5d9c221

See more details on using hashes here.

File details

Details for the file eventweave-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: eventweave-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for eventweave-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fdfd8d71616fda8117c8625bc0a655faae23d61d44e1085c83b0c464f57d9d9
MD5 085efdc6ce79959748edfb10e2dd56d9
BLAKE2b-256 6797ec97db2eb99420c47a068aea66c242ab5bd22305920a0e877e905fda5cce

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