Simple example
# main.py
from collections.abc import Sequence
from typing import NamedTuple
import pydepot
from eventoolkit import Event, EventPublisher, StoreEventHandler
class Chatroom(NamedTuple):
users: tuple[str, ...]
class State(NamedTuple):
chatroom: Chatroom
class StateSubscriber:
def on_state(self, state: State) -> None:
print(f"[StoreSubscriber] on_state called with {state}")
class JoinUserAction(pydepot.Action):
def __init__(self, user: str):
self.user: str = user
class JoinUserReducer(pydepot.Reducer[JoinUserAction, State]):
@property
def action_type(self) -> type[JoinUserAction]:
return JoinUserAction
def apply(self, action: JoinUserAction, state: State) -> State:
return State(chatroom=Chatroom(users=(*state.chatroom.users, action.user)))
class UserJoinedEvent(Event):
@property
def name(self) -> str:
return "user_joined"
def __init__(self, user: str):
self.user: str = user
class UserJoinedEventHandler(StoreEventHandler[UserJoinedEvent, State]):
@property
def event_type(self) -> type[UserJoinedEvent]:
return UserJoinedEvent
def actions(self, event: UserJoinedEvent) -> Sequence[pydepot.Action]:
return [JoinUserAction(user=event.user)]
def main() -> None:
store = pydepot.Store(State(chatroom=Chatroom(users=())))
store.register(JoinUserReducer())
subscriber = StateSubscriber()
store.subscribe(subscriber)
handler = UserJoinedEventHandler(store=store)
publisher = EventPublisher()
publisher.subscribe(handler)
publisher.publish(UserJoinedEvent(user="Alice"))
publisher.publish(UserJoinedEvent(user="Bob"))
if __name__ == "__main__":
main()
$ python3 main.py
[StoreSubscriber] on_state called with
State(chatroom=Chatroom(users=('Alice',)))
[StoreSubscriber] on_state called with
State(chatroom=Chatroom(users=('Alice', 'Bob')))
Installation
Eventoolkit is available as eventoolkit on PyPI:
pip install eventoolkit
Usage
For detailed quickstart and API reference, visit the Documentation.
License
Copyright (C) 2023 tombartk
This program is free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program.
If not, see https://www.gnu.org/licenses/.
Metadata
Release files for eventoolkit 0.1.0
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 | Actions |
|---|---|---|---|---|
| eventoolkit-0.1.0.tar.gz | 24.3 kB | Without provenance | Details for eventoolkit-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eventoolkit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for eventoolkit-0.1.0-py3-none-any.whl |
Total release size: 44.1 kB
Release files / eventoolkit-0.1.0.tar.gz
| Download URL | eventoolkit-0.1.0.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b6ba891f2449b50562e548ed14b5900362d0369c5b21f7b6e389bbc3f6ccd99
|
|
BLAKE2b-256 checksum How to use checksums |
e4e6e079a21628f5d2c5c46e5d3f9cabb227a1e6f30c4302d9e8e9b14b38d7bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.1
|
Release files / eventoolkit-0.1.0-py3-none-any.whl
| Download URL | eventoolkit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01330dedd2f8c36f4bc144c91ceedca3ef54b3d004e6eb0ddb581e3abe7b0869
|
|
BLAKE2b-256 checksum How to use checksums |
a009b91cf378bfc47a09bef80a49efd79960ff40162a58497a645239ea8aeaf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.1
|
Security for eventoolkit 0.1.0
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.