Skip to main content

pevl

Python Event Versioning Library

This library provides code to upgrade events. Think of it as an event equivalent to flyway, where you can define the mappings between events and have all incoming events upgraded to a version your code can deal with, on the fly.

The target environment is either an event sourcing system, or microservices with an event bus - anywhere you're consuming events and doing something with them.

Pre-requisites

All events must be versioned. That is, there must be a version number in the event structure somewhere.

There must be a way to map from a given event version to version+1 for every version number. This is typically done by defining an upgrade method.

The library provides a class, Upgrader, which will take events in, extract the version number, run all appropriate upgrade methods until the version is current, then call an event factory with the upgraded data and return the appropriate object.

Design decisions (and whys)

  • Factory is only called with the latest data, not for each version - this is to save from having to maintain factories for every version.

  • Supporting Python 3.8 and above - because I want static types.

  • All events are dictionaries - for simplicity. Events are deepcopy'ed as part of the implementation.

  • Upgrade methods may mutate events in place - each event is provided as a deepcopy (so don't upgrade things that don't deepcopy). If you return, that will be used - if not, the assumed mutated event will be used.

  • Upgrade methods will get dictionaries and return dictionaries, and wrapping will be invisible - because I want this to be as simple to use as possible.

  • All versions should be strings, not numbers or other oddball things - for simplicity.

  • No version will be represented with str(None) (ie. 'None')

How to Use

Create a module that holds a bunch of version upgrade methods.

Each method should use the @pevl.event.upgrade decorator, and in the decorator you specify a version number to apply to and a new-version number to set (otherwise you must set the new version number in the upgrade script itself).

Each method should apply an appropriate upgrade from the version number given to the next version number.

Each method should be named descriptively.

Each method takes an event :dict, and returns an event: dict

Version numbers do not need to sort properly - but each version needs to upgrade to another version that is then handled (or not, if final version)

Example:

from pevl.event import upgrade

@upgrade('v0.1', 'v0.2')
def split_first_last_name(event):
    event['first'], event['last'] = event['name'].split()

The code to upgrade the events:

from pevl.event import Upgrader

upgrader = event.Upgrader(upgrades=[split_first_name, ])
upgraded = upgrader.ingest(event, target_version='v0.2')

For an example of the code that does the upgrades, see sample_sns.py

Likely Failure Modes

Make sure your versions match what comes out of the event itself. str/int mismatches may be silently ignored.

Make sure you have a version. Again, failed version matches may be ignored.

Release files for pevl 0.0.3

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

Source distribution (sdist)

Source distribution for pevl 0.0.3
File Size Uploaded
pevl-0.0.3.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pevl 0.0.3
File Interpreter ABI Platform
pevl-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / pevl-0.0.3.tar.gz

Download URL pevl-0.0.3.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0009915e94ae7b8865054744e48320d29dd68482e311e9e4b159fbec11175126
BLAKE2b-256 checksum
How to use checksums
8bd33ea2b8f41412f6e3948fa88d50da30656b4f9a31e3631fb9d99994916a10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

Release files / pevl-0.0.3-py3-none-any.whl

Download URL pevl-0.0.3-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ff1f6761b564ec8d8dbea50c46ea6ff7b30150113f85a411ef92f22a707429e
BLAKE2b-256 checksum
How to use checksums
bcf86c7a61995e5ca72ace3b6c9d24bf6db52f29ca545b71a6aa97d9513214c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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