fidem 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fidem/__init__.py ADDED
File without changes
fidem/environment.py ADDED
@@ -0,0 +1,137 @@
1
+ from abc import ABC, abstractmethod
2
+ from collections.abc import Collection, Sequence
3
+ from dataclasses import dataclass
4
+ from typing import Any
5
+
6
+ from fidem.intents import (
7
+ DatabaseIntent,
8
+ DatabaseWriteIntent,
9
+ ExternalIntent,
10
+ ExternalWriteIntent,
11
+ IntentCompensationHandler,
12
+ IntentCompensationMiddleware,
13
+ IntentContext,
14
+ IntentHandler,
15
+ IntentMiddleware,
16
+ ReadIntent,
17
+ WriteIntent,
18
+ )
19
+ from fidem.operation_engine import CommandContextIn, EventContextIn, OperationEngine
20
+ from fidem.operations import Command, Event
21
+
22
+
23
+ class DatabaseIntegration[ResourceT](ABC):
24
+ @abstractmethod
25
+ async def execute[ResultT](
26
+ self,
27
+ handler: IntentHandler[ResourceT, DatabaseIntent[ResultT], ResultT],
28
+ context: IntentContext,
29
+ intent: DatabaseIntent[ResultT],
30
+ ) -> ResultT:
31
+ raise NotImplementedError
32
+
33
+ @abstractmethod
34
+ async def execute_compensation[ResultT](
35
+ self,
36
+ handler: IntentCompensationHandler[ResourceT, DatabaseWriteIntent[ResultT], ResultT],
37
+ context: IntentContext,
38
+ intent: DatabaseWriteIntent[ResultT],
39
+ result: ResultT,
40
+ ) -> None:
41
+ raise NotImplementedError
42
+
43
+
44
+ class ExternalIntegration[ResourceT](ABC):
45
+ @abstractmethod
46
+ async def execute[ResultT](
47
+ self,
48
+ handler: IntentHandler[ResourceT, ExternalIntent[ResultT], ResultT],
49
+ context: IntentContext,
50
+ intent: ExternalIntent[ResultT],
51
+ ) -> ResultT:
52
+ raise NotImplementedError
53
+
54
+ @abstractmethod
55
+ async def execute_compensation[ResultT](
56
+ self,
57
+ handler: IntentCompensationHandler[ResourceT, ExternalWriteIntent[ResultT], ResultT],
58
+ context: IntentContext,
59
+ intent: ExternalWriteIntent[ResultT],
60
+ result: ResultT,
61
+ ) -> None:
62
+ raise NotImplementedError
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class ReadIntentDef[ResourceT = Any, ReadIntentT: ReadIntent[Any] = Any, ResultT = Any]:
67
+ intent_type: type[ReadIntent[ResultT]]
68
+ handler: IntentHandler[ResourceT, ReadIntentT, ResultT]
69
+ middlewares: Sequence[IntentMiddleware[ResourceT, ReadIntentT, ResultT]] | None = None
70
+ name: str | None = None
71
+ version: int = 1
72
+
73
+
74
+ @dataclass(frozen=True)
75
+ class WriteIntentDef[ResourceT = Any, WriteIntentT: WriteIntent[Any] = Any, ResultT = Any]:
76
+ intent_type: type[WriteIntent[ResultT]]
77
+ handler: IntentHandler[ResourceT, WriteIntentT, ResultT]
78
+ compensation_handler: IntentCompensationHandler[ResourceT, WriteIntentT, ResultT]
79
+ middlewares: Sequence[IntentMiddleware[ResourceT, WriteIntentT, ResultT]] | None = None
80
+ compensation_middlewares: Sequence[IntentCompensationMiddleware[ResourceT, WriteIntentT, ResultT]] | None = None
81
+ name: str | None = None
82
+ version: int = 1
83
+
84
+
85
+ @dataclass(frozen=True)
86
+ class IntegrationDef[ResourceT = Any]:
87
+ integration: DatabaseIntegration[ResourceT] | ExternalIntegration[ResourceT]
88
+ intent_routes: Collection[ReadIntentDef[ResourceT] | WriteIntentDef[ResourceT]] = ()
89
+ middlewares: Sequence[IntentMiddleware[ResourceT]] | None = None
90
+ compensation_middlewares: Sequence[IntentCompensationMiddleware[ResourceT]] | None = None
91
+
92
+
93
+ @dataclass(frozen=True)
94
+ class DatabaseIntegrationDef[ResourceT = Any](IntegrationDef[ResourceT]):
95
+ integration: DatabaseIntegration[ResourceT]
96
+
97
+
98
+ @dataclass(frozen=True)
99
+ class ExternalIntegrationDef[ResourceT = Any](IntegrationDef[ResourceT]):
100
+ integration: ExternalIntegration[ResourceT]
101
+
102
+
103
+ class Environment(ABC):
104
+ @abstractmethod
105
+ def __init__(
106
+ self,
107
+ operation_engine: OperationEngine,
108
+ database_integration_def: DatabaseIntegrationDef,
109
+ external_integration_defs: Collection[IntegrationDef] = (),
110
+ middlewares: Sequence[IntentMiddleware] | None = None,
111
+ compensation_middlewares: Sequence[IntentCompensationMiddleware] | None = None,
112
+ ) -> None:
113
+ raise NotImplementedError
114
+
115
+ @abstractmethod
116
+ async def execute[ResultT](self, command: Command[ResultT], context: CommandContextIn | None = None) -> ResultT:
117
+ raise NotImplementedError
118
+
119
+ @abstractmethod
120
+ async def publish(self, event: Event, context: EventContextIn | None = None) -> None:
121
+ raise NotImplementedError
122
+
123
+ @abstractmethod
124
+ async def schedule(self, name: str, cron: str, event: Event, context: EventContextIn | None = None) -> None:
125
+ raise NotImplementedError
126
+
127
+ @abstractmethod
128
+ def unschedule(self, name: str) -> None:
129
+ raise NotImplementedError
130
+
131
+ @abstractmethod
132
+ def run_outbox_dispatcher(self) -> None:
133
+ raise NotImplementedError
134
+
135
+ @abstractmethod
136
+ def run_scheduler(self) -> None:
137
+ raise NotImplementedError
fidem/intents.py ADDED
@@ -0,0 +1,90 @@
1
+ from collections.abc import Awaitable, Callable, Generator, Hashable
2
+ from dataclasses import dataclass
3
+ from typing import Any
4
+
5
+ from fidem.serialization import Serializable
6
+
7
+ type IntentId = Hashable
8
+
9
+
10
+ @dataclass(frozen=True)
11
+ class IntentContext:
12
+ intent_id: IntentId
13
+
14
+
15
+ class Intent[ResultT]:
16
+ pass
17
+
18
+
19
+ class UserIntent[ResultT](Intent[ResultT], Serializable):
20
+ pass
21
+
22
+
23
+ class IntegrationIntent[ResultT](UserIntent[ResultT]):
24
+ pass
25
+
26
+
27
+ class ReadIntent[ResultT](IntegrationIntent[ResultT]):
28
+ pass
29
+
30
+
31
+ class DatabaseReadIntent[ResultT](ReadIntent[ResultT]):
32
+ pass
33
+
34
+
35
+ class ExternalReadIntent[ResultT](ReadIntent[ResultT]):
36
+ pass
37
+
38
+
39
+ class WriteIntent[ResultT](IntegrationIntent[ResultT]):
40
+ pass
41
+
42
+
43
+ class DatabaseWriteIntent[ResultT](WriteIntent[ResultT]):
44
+ pass
45
+
46
+
47
+ class ExternalWriteIntent[ResultT](WriteIntent[ResultT]):
48
+ pass
49
+
50
+
51
+ type DatabaseIntent[ResultT] = DatabaseReadIntent[ResultT] | DatabaseWriteIntent[ResultT]
52
+ type ExternalIntent[ResultT] = ExternalReadIntent[ResultT] | ExternalWriteIntent[ResultT]
53
+
54
+
55
+ type IntentHandler[
56
+ ResourceT = Any,
57
+ IntentT: IntegrationIntent[Any] = Any,
58
+ ResultT = Any,
59
+ ] = Callable[
60
+ [ResourceT, IntentContext, IntentT],
61
+ Awaitable[ResultT],
62
+ ]
63
+ type IntentCompensationHandler[
64
+ ResourceT = Any,
65
+ IntentT: WriteIntent[Any] = Any,
66
+ ResultT = Any,
67
+ ] = Callable[
68
+ [ResourceT, IntentContext, IntentT, ResultT],
69
+ Awaitable[None],
70
+ ]
71
+ type IntentMiddleware[
72
+ ResourceT = Any,
73
+ IntentT: IntegrationIntent[Any] = Any,
74
+ ResultT = Any,
75
+ ] = Callable[
76
+ [IntentHandler[ResourceT, IntentT, ResultT]],
77
+ IntentHandler[ResourceT, IntentT, ResultT],
78
+ ]
79
+ type IntentCompensationMiddleware[
80
+ ResourceT = Any,
81
+ IntentT: WriteIntent[Any] = Any,
82
+ ResultT = Any,
83
+ ] = Callable[
84
+ [IntentCompensationHandler[ResourceT, IntentT, ResultT]],
85
+ IntentCompensationHandler[ResourceT, IntentT, ResultT],
86
+ ]
87
+
88
+
89
+ def ask[ResultT](intent: Intent[ResultT]) -> Generator[Intent[ResultT], ResultT, ResultT]:
90
+ return (yield intent)
@@ -0,0 +1,118 @@
1
+ from abc import ABC, abstractmethod
2
+ from collections.abc import Collection, Generator, Sequence
3
+ from dataclasses import dataclass
4
+ from typing import Any
5
+
6
+ from fidem.intents import Intent
7
+ from fidem.operations import (
8
+ Command,
9
+ CommandHandler,
10
+ CommandMiddleware,
11
+ Event,
12
+ EventHandler,
13
+ EventMiddleware,
14
+ OperationId,
15
+ )
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class OperationContextIn:
20
+ operation_id: OperationId | None = None
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class CommandContextIn(OperationContextIn):
25
+ pass
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class EventContextIn(OperationContextIn):
30
+ pass
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class CommandDef[CommandT: Command[Any] = Any, ResultT = Any, EventOutT: Event | None = None]:
35
+ command_type: type[Command[ResultT]]
36
+ handler: CommandHandler[CommandT, ResultT, EventOutT]
37
+ middlewares: Sequence[CommandMiddleware[CommandT, ResultT, EventOutT]] | None = None
38
+ name: str | None = None
39
+ version: int = 1
40
+
41
+
42
+ @dataclass(frozen=True)
43
+ class EventDef[EventT: Event = Any, EventOutT: Event | None = None]:
44
+ event_type: type[EventT]
45
+ handler: EventHandler[EventT, EventOutT]
46
+ middlewares: Sequence[EventMiddleware[EventT, EventOutT]] | None = None
47
+ name: str | None = None
48
+ version: int = 1
49
+
50
+
51
+ @dataclass(frozen=True)
52
+ class ScheduledEventDef[EventT: Event = Any]:
53
+ name: str
54
+ cron: str
55
+ event: EventT
56
+
57
+
58
+ type ExecutionPlan[
59
+ ResultT,
60
+ ] = Generator[
61
+ Intent[Any],
62
+ Any,
63
+ ResultT,
64
+ ]
65
+
66
+
67
+ class OperationEngine(ABC):
68
+ @abstractmethod
69
+ def __init__(
70
+ self,
71
+ command_defs: Collection[CommandDef] = (),
72
+ event_defs: Collection[EventDef] = (),
73
+ scheduled_event_defs: Collection[ScheduledEventDef] = (),
74
+ command_middlewares: Sequence[CommandMiddleware] = (),
75
+ event_middlewares: Sequence[EventMiddleware] = (),
76
+ ) -> None:
77
+ raise NotImplementedError
78
+
79
+ @abstractmethod
80
+ def execute[ResultT](
81
+ self,
82
+ command: Command[ResultT],
83
+ context: CommandContextIn | None = None,
84
+ ) -> ExecutionPlan[ResultT]:
85
+ raise NotImplementedError
86
+
87
+ @abstractmethod
88
+ def publish(
89
+ self,
90
+ event: Event,
91
+ context: EventContextIn | None = None,
92
+ ) -> ExecutionPlan[None]:
93
+ raise NotImplementedError
94
+
95
+ @abstractmethod
96
+ def schedule(
97
+ self,
98
+ name: str,
99
+ cron: str,
100
+ event: Event,
101
+ context: EventContextIn | None = None,
102
+ ) -> ExecutionPlan[None]:
103
+ raise NotImplementedError
104
+
105
+ @abstractmethod
106
+ def unschedule(
107
+ self,
108
+ name: str,
109
+ ) -> ExecutionPlan[None]:
110
+ raise NotImplementedError
111
+
112
+ @abstractmethod
113
+ def run_outbox_dispatcher(self) -> ExecutionPlan[None]:
114
+ raise NotImplementedError
115
+
116
+ @abstractmethod
117
+ def run_scheduler(self) -> ExecutionPlan[None]:
118
+ raise NotImplementedError
fidem/operations.py ADDED
@@ -0,0 +1,111 @@
1
+ from collections.abc import Callable, Collection, Generator, Hashable
2
+ from dataclasses import dataclass
3
+ from typing import Any
4
+
5
+ from fidem.intents import UserIntent
6
+ from fidem.serialization import Serializable
7
+
8
+ type OperationId = Hashable
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class OperationContext:
13
+ operation_id: OperationId
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class CommandContext(OperationContext):
18
+ pass
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class EventContext(OperationContext):
23
+ pass
24
+
25
+
26
+ class Operation[ResultT](Serializable):
27
+ pass
28
+
29
+
30
+ class Command[ResultT](Operation[ResultT]):
31
+ pass
32
+
33
+
34
+ class Event(Operation[None]):
35
+ pass
36
+
37
+
38
+ type OperationGenerator[
39
+ ResultT = Any,
40
+ EventOutT: Event | None = None,
41
+ ] = Generator[
42
+ UserIntent[Any],
43
+ Any,
44
+ ResultT | Collection[EventOutT] | tuple[ResultT, Collection[EventOutT]],
45
+ ]
46
+ type OperationHandler[
47
+ OperationContextT: OperationContext = Any,
48
+ OperationT: Operation[Any] = Any,
49
+ ResultT = Any,
50
+ EventOutT: Event | None = None,
51
+ ] = Callable[
52
+ [OperationContextT, OperationT],
53
+ OperationGenerator[ResultT, EventOutT],
54
+ ]
55
+ type OperationMiddleware[
56
+ OperationContextT: OperationContext = Any,
57
+ OperationT: Operation[Any] = Any,
58
+ ResultT = Any,
59
+ EventOutT: Event | None = None,
60
+ ] = Callable[
61
+ [OperationHandler[OperationContextT, OperationT, ResultT, EventOutT]],
62
+ OperationHandler[OperationContextT, OperationT, ResultT, EventOutT],
63
+ ]
64
+ type CommandGenerator[
65
+ ResultT = Any,
66
+ EventOutT: Event | None = None,
67
+ ] = OperationGenerator[ResultT, EventOutT]
68
+ type CommandHandler[
69
+ CommandT: Command[Any] = Any,
70
+ ResultT = Any,
71
+ EventOutT: Event | None = None,
72
+ ] = OperationHandler[
73
+ CommandContext,
74
+ CommandT,
75
+ ResultT,
76
+ EventOutT,
77
+ ]
78
+ type CommandMiddleware[
79
+ CommandT: Command[Any] = Any,
80
+ ResultT = Any,
81
+ EventOutT: Event | None = None,
82
+ ] = OperationMiddleware[
83
+ CommandContext,
84
+ CommandT,
85
+ ResultT,
86
+ EventOutT,
87
+ ]
88
+ type EventGenerator[
89
+ EventOutT: Event | None = None,
90
+ ] = OperationGenerator[
91
+ None,
92
+ EventOutT,
93
+ ]
94
+ type EventHandler[
95
+ EventT: Event = Any,
96
+ EventOutT: Event | None = None,
97
+ ] = OperationHandler[
98
+ EventContext,
99
+ EventT,
100
+ None,
101
+ EventOutT,
102
+ ]
103
+ type EventMiddleware[
104
+ EventT: Event = Any,
105
+ EventOutT: Event | None = None,
106
+ ] = OperationMiddleware[
107
+ EventContext,
108
+ EventT,
109
+ None,
110
+ EventOutT,
111
+ ]
fidem/py.typed ADDED
File without changes
fidem/serialization.py ADDED
@@ -0,0 +1,12 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Self
3
+
4
+
5
+ class Serializable(ABC):
6
+ @abstractmethod
7
+ def serialize(self) -> bytes:
8
+ raise NotImplementedError
9
+
10
+ @classmethod
11
+ def deserialize(cls, data: bytes) -> Self:
12
+ raise NotImplementedError
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.3
2
+ Name: fidem
3
+ Version: 0.1.0
4
+ Summary: Fidem is a framework for building consistent, fault‑tolerant applications. Replace chaos with order—explicit contracts, durable execution, and complete observability out of the box.
5
+ Author: Maxim Sakhno
6
+ Author-email: Maxim Sakhno <maxim.sakhno@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 Maxim Sakhno
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Classifier: Development Status :: 2 - Pre-Alpha
29
+ Classifier: Intended Audience :: Developers
30
+ Classifier: Intended Audience :: Information Technology
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Programming Language :: Python
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3 :: Only
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Programming Language :: Python :: 3.14
38
+ Classifier: Typing :: Typed
39
+ Classifier: Framework :: AsyncIO
40
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
41
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
42
+ Classifier: Topic :: Software Development :: Libraries
43
+ Classifier: Topic :: Software Development
44
+ Classifier: Topic :: System :: Distributed Computing
45
+ Classifier: Topic :: Database
46
+ Requires-Python: >=3.13
47
+ Project-URL: Repository, https://github.com/maximsakhno/fidem
48
+ Project-URL: Homepage, https://github.com/maximsakhno/fidem
49
+ Project-URL: Issues, https://github.com/maximsakhno/fidem/issues
50
+ Project-URL: Documentation, https://github.com/maximsakhno/fidem#readme
51
+ Description-Content-Type: text/markdown
52
+
53
+ # fidem
54
+
55
+ Fidem is a framework for building consistent, fault‑tolerant applications. Replace chaos with order—explicit contracts, durable execution, and complete observability out of the box.
56
+
57
+ <div align="center">
58
+
59
+ [![CI](https://github.com/maximsakhno/fidem/actions/workflows/ci.yml/badge.svg)](https://github.com/maximsakhno/fidem/actions/workflows/ci.yml)
60
+ [![codecov](https://codecov.io/gh/maximsakhno/fidem/graph/badge.svg?token=T4VS9W5SMC)](https://codecov.io/gh/maximsakhno/fidem)
61
+ [![PyPI](https://img.shields.io/pypi/v/fidem?color=green)](https://pypi.org/project/fidem/)
62
+ [![Python Versions](https://img.shields.io/pypi/pyversions/fidem?color=green)](https://pypi.org/project/fidem/)
63
+ [![Ruff](https://img.shields.io/badge/linter-ruff-green.svg)](https://github.com/astral-sh/ruff)
64
+ [![Basedpyright](https://img.shields.io/badge/type%20checker-basedpyright-green.svg)](https://github.com/DetachHead/basedpyright)
65
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
66
+
67
+ </div>
@@ -0,0 +1,10 @@
1
+ fidem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ fidem/environment.py,sha256=TUbg3npoaiHlR-9EIg1DCVAlI2ud9o22vm0JP0OSk2Q,4671
3
+ fidem/intents.py,sha256=p86vTu8T9NOWms0_IhPMu2VzGH2_tep-shaw7PhQtmI,1996
4
+ fidem/operation_engine.py,sha256=Y8x5vARj86bcFv857OFS69X6z7mlMAyc3VItuBgD3B8,2854
5
+ fidem/operations.py,sha256=yXi0OzOQsM6dVd-MS30K68I6WENcTiYzyuZsQhQ3lD0,2361
6
+ fidem/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ fidem/serialization.py,sha256=XM-OqXQD5vudV01zyWYifEyKjJHNfZ7g5LK91bjw9h0,274
8
+ fidem-0.1.0.dist-info/WHEEL,sha256=WvwXFgRajeoYkfRVmDhkP4Qlqo31Mk687zIO2QQoFmw,80
9
+ fidem-0.1.0.dist-info/METADATA,sha256=8JDAXfUba3kmWQGR19JCKNtJe5LoeuZuXrWdSHPxZcI,3820
10
+ fidem-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.11.7
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any