python-cq 0.8.0__tar.gz → 0.9.0__tar.gz

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.
Files changed (25) hide show
  1. {python_cq-0.8.0 → python_cq-0.9.0}/PKG-INFO +1 -1
  2. {python_cq-0.8.0 → python_cq-0.9.0}/cq/__init__.py +2 -0
  3. python_cq-0.9.0/cq/_core/defer.py +10 -0
  4. python_cq-0.9.0/cq/ext/fastapi.py +44 -0
  5. python_cq-0.9.0/cq/ext/fastapi.pyi +5 -0
  6. python_cq-0.9.0/cq/py.typed +0 -0
  7. {python_cq-0.8.0 → python_cq-0.9.0}/pyproject.toml +3 -1
  8. {python_cq-0.8.0 → python_cq-0.9.0}/.gitignore +0 -0
  9. {python_cq-0.8.0 → python_cq-0.9.0}/LICENSE +0 -0
  10. {python_cq-0.8.0 → python_cq-0.9.0}/README.md +0 -0
  11. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/__init__.py +0 -0
  12. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/dispatcher/__init__.py +0 -0
  13. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/dispatcher/base.py +0 -0
  14. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/dispatcher/bus.py +0 -0
  15. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/dispatcher/pipe.py +0 -0
  16. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/handler.py +0 -0
  17. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/message.py +0 -0
  18. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/middleware.py +0 -0
  19. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/related_events.py +0 -0
  20. {python_cq-0.8.0 → python_cq-0.9.0}/cq/_core/scope.py +0 -0
  21. {python_cq-0.8.0 → python_cq-0.9.0}/cq/exceptions.py +0 -0
  22. {python_cq-0.8.0/cq/middlewares → python_cq-0.9.0/cq/ext}/__init__.py +0 -0
  23. /python_cq-0.8.0/cq/py.typed → /python_cq-0.9.0/cq/middlewares/__init__.py +0 -0
  24. {python_cq-0.8.0 → python_cq-0.9.0}/cq/middlewares/retry.py +0 -0
  25. {python_cq-0.8.0 → python_cq-0.9.0}/cq/middlewares/scope.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-cq
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: Lightweight CQRS library for async Python projects.
5
5
  Project-URL: Repository, https://github.com/100nm/python-cq
6
6
  Author: remimd
@@ -1,3 +1,4 @@
1
+ from ._core.defer import DeferredBus
1
2
  from ._core.dispatcher.bus import Bus
2
3
  from ._core.dispatcher.pipe import Pipe
3
4
  from ._core.message import (
@@ -25,6 +26,7 @@ __all__ = (
25
26
  "CQScope",
26
27
  "Command",
27
28
  "CommandBus",
29
+ "DeferredBus",
28
30
  "Event",
29
31
  "EventBus",
30
32
  "Middleware",
@@ -0,0 +1,10 @@
1
+ from abc import abstractmethod
2
+ from typing import Protocol
3
+
4
+
5
+ class DeferredBus[I](Protocol):
6
+ __slots__ = ()
7
+
8
+ @abstractmethod
9
+ async def defer(self, input_value: I, /) -> None:
10
+ raise NotImplementedError
@@ -0,0 +1,44 @@
1
+ from dataclasses import dataclass
2
+ from typing import Annotated, Any
3
+
4
+ from fastapi import BackgroundTasks, Depends
5
+ from injection.ext.fastapi import Inject
6
+
7
+ from cq import Bus, Command, CommandBus, DeferredBus, Event, EventBus, Query, QueryBus
8
+
9
+ __all__ = ("DeferredCommandBus", "DeferredEventBus", "DeferredQueryBus")
10
+
11
+
12
+ @dataclass(repr=False, eq=False, frozen=True, slots=True)
13
+ class FastAPIDeferredBus[I](DeferredBus[I]):
14
+ background_tasks: BackgroundTasks
15
+ bus: Bus[I, Any]
16
+
17
+ async def defer(self, input_value: I, /) -> None:
18
+ self.background_tasks.add_task(self.bus.dispatch, input_value)
19
+
20
+
21
+ async def new_deferred_command_bus[T](
22
+ background_tasks: BackgroundTasks,
23
+ command_bus: Inject[CommandBus[T]],
24
+ ) -> DeferredBus[Command]:
25
+ return FastAPIDeferredBus(background_tasks, command_bus)
26
+
27
+
28
+ async def new_deferred_event_bus(
29
+ background_tasks: BackgroundTasks,
30
+ event_bus: Inject[EventBus],
31
+ ) -> DeferredBus[Event]:
32
+ return FastAPIDeferredBus(background_tasks, event_bus)
33
+
34
+
35
+ async def new_deferred_query_bus[T](
36
+ background_tasks: BackgroundTasks,
37
+ query_bus: Inject[QueryBus[T]],
38
+ ) -> DeferredBus[Query]:
39
+ return FastAPIDeferredBus(background_tasks, query_bus)
40
+
41
+
42
+ DeferredCommandBus = Annotated[DeferredBus[Command], Depends(new_deferred_command_bus)]
43
+ DeferredEventBus = Annotated[DeferredBus[Event], Depends(new_deferred_event_bus)]
44
+ DeferredQueryBus = Annotated[DeferredBus[Query], Depends(new_deferred_query_bus)]
@@ -0,0 +1,5 @@
1
+ from cq import Command, DeferredBus, Event, Query
2
+
3
+ type DeferredCommandBus = DeferredBus[Command]
4
+ type DeferredEventBus = DeferredBus[Event]
5
+ type DeferredQueryBus = DeferredBus[Query]
File without changes
@@ -14,6 +14,8 @@ example = [
14
14
  "pydantic",
15
15
  ]
16
16
  test = [
17
+ "fastapi",
18
+ "httpx",
17
19
  "pytest",
18
20
  "pytest-asyncio",
19
21
  "pytest-cov",
@@ -21,7 +23,7 @@ test = [
21
23
 
22
24
  [project]
23
25
  name = "python-cq"
24
- version = "0.8.0"
26
+ version = "0.9.0"
25
27
  description = "Lightweight CQRS library for async Python projects."
26
28
  license = "MIT"
27
29
  license-files = ["LICENSE"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes