Skip to content

Instantly share code, notes, and snippets.

Last active Oct 8, 2019
What would you like to do?
Event Sourcing - event code sample
class MyEvent:
def __init__(self, foo: int):
"""For issuing new events in the application.""" = foo
def unserialize(cls, payload: dict) -> "MyEvent":
"""To use when fetching an existing event from the event log."""
return cls(foo=payload["foo"])
def serialize(self) -> dict:
"""To use when storing a new event in the event log."""
return {"foo":}
def test_my_event_serialize():
event = MyEvent(1)
assert event.serialize() == {"foo": 1}
def test_my_event_unserialize():
assert MyEvent.unserialize({"foo": 1}) == MyEvent(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment