busline 0.3.1__py3-none-any.whl → 0.5.1__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.
Files changed (53) hide show
  1. busline/client/client.py +27 -0
  2. busline/{eventbus_client → client}/eventbus_connector.py +5 -10
  3. busline/client/multiclient.py +41 -0
  4. busline/client/publisher/publisher.py +60 -0
  5. busline/client/pubsub_client.py +151 -0
  6. busline/client/subscriber/event_handler/closure_event_handler.py +18 -0
  7. busline/client/subscriber/event_handler/event_handler.py +15 -0
  8. busline/client/subscriber/event_handler/multi_handler.py +30 -0
  9. busline/client/subscriber/subscriber.py +109 -0
  10. busline/client/subscriber/topic_subscriber.py +79 -0
  11. busline/event/event.py +43 -21
  12. busline/event/registry.py +67 -0
  13. busline/event/test.py +47 -0
  14. busline/exceptions.py +8 -0
  15. busline/local/__init__.py +3 -0
  16. busline/local/eventbus/__init__.py +0 -0
  17. busline/local/eventbus/async_local_eventbus.py +26 -0
  18. busline/local/eventbus/eventbus.py +86 -0
  19. busline/local/eventbus/local_eventbus.py +23 -0
  20. busline/local/local_pubsub_client.py +54 -0
  21. busline/local/publisher/__init__.py +0 -0
  22. busline/local/publisher/local_publisher.py +38 -0
  23. busline/local/subscriber/__init__.py +0 -0
  24. busline/local/subscriber/local_subscriber.py +43 -0
  25. busline/local/test.py +156 -0
  26. busline-0.5.1.dist-info/METADATA +215 -0
  27. busline-0.5.1.dist-info/RECORD +36 -0
  28. {busline-0.3.1.dist-info → busline-0.5.1.dist-info}/WHEEL +1 -1
  29. busline/event/event_content.py +0 -18
  30. busline/event/event_metadata.py +0 -26
  31. busline/eventbus/async_local_eventbus.py +0 -32
  32. busline/eventbus/eventbus.py +0 -112
  33. busline/eventbus/exceptions.py +0 -2
  34. busline/eventbus/queued_local_eventbus.py +0 -50
  35. busline/eventbus/topic.py +0 -35
  36. busline/eventbus_client/eventbus_client.py +0 -99
  37. busline/eventbus_client/exceptions.py +0 -4
  38. busline/eventbus_client/local_eventbus_client.py +0 -25
  39. busline/eventbus_client/publisher/local_eventbus_publisher.py +0 -35
  40. busline/eventbus_client/publisher/publisher.py +0 -59
  41. busline/eventbus_client/subscriber/closure_event_listener.py +0 -19
  42. busline/eventbus_client/subscriber/event_listener.py +0 -15
  43. busline/eventbus_client/subscriber/local_eventbus_closure_subscriber.py +0 -17
  44. busline/eventbus_client/subscriber/local_eventbus_subscriber.py +0 -40
  45. busline/eventbus_client/subscriber/subscriber.py +0 -93
  46. busline-0.3.1.dist-info/METADATA +0 -111
  47. busline-0.3.1.dist-info/RECORD +0 -30
  48. /busline/{eventbus → client}/__init__.py +0 -0
  49. /busline/{eventbus_client → client/publisher}/__init__.py +0 -0
  50. /busline/{eventbus_client/publisher → client/subscriber}/__init__.py +0 -0
  51. /busline/{eventbus_client/subscriber → client/subscriber/event_handler}/__init__.py +0 -0
  52. {busline-0.3.1.dist-info → busline-0.5.1.dist-info/licenses}/LICENSE +0 -0
  53. {busline-0.3.1.dist-info → busline-0.5.1.dist-info}/top_level.txt +0 -0
@@ -1,35 +0,0 @@
1
- from busline.event.event import Event
2
- from busline.eventbus.eventbus import EventBus
3
- from busline.eventbus_client.exceptions import EventBusClientNotConnected
4
- from busline.eventbus_client.publisher.publisher import Publisher
5
-
6
-
7
- class LocalEventBusPublisher(Publisher):
8
- """
9
- Publisher which works with local eventbus, this class can be initialized and used stand-alone
10
-
11
- Author: Nicola Ricciardi
12
- """
13
-
14
- def __init__(self, eventbus_instance: EventBus):
15
- Publisher.__init__(self)
16
-
17
- self._eventbus = eventbus_instance
18
- self._connected = False
19
-
20
- async def connect(self):
21
- self._connected = True
22
-
23
- async def disconnect(self):
24
- self._connected = False
25
-
26
- async def _internal_publish(self, topic_name: str, event: Event, raise_if_not_connected: bool = False, **kwargs):
27
-
28
- if raise_if_not_connected and not self._connected:
29
- raise EventBusClientNotConnected()
30
- else:
31
- await self.connect()
32
-
33
- self.on_publishing(topic_name, event)
34
- await self._eventbus.put_event(topic_name, event)
35
- self.on_published(topic_name, event)
@@ -1,59 +0,0 @@
1
- import logging
2
- from abc import ABC, abstractmethod
3
- from uuid import uuid4
4
-
5
- from busline.event.event import Event
6
- from busline.eventbus_client.eventbus_connector import EventBusConnector
7
-
8
-
9
- class Publisher(EventBusConnector, ABC):
10
- """
11
- Abstract class which can be implemented by your components which must be able to publish on eventbus
12
-
13
- Author: Nicola Ricciardi
14
- """
15
-
16
- def __init__(self, publisher_id: str = str(uuid4())):
17
- EventBusConnector.__init__(self, publisher_id)
18
-
19
- @abstractmethod
20
- async def _internal_publish(self, topic_name: str, event: Event, **kwargs):
21
- """
22
- Actual publish on topic the event
23
-
24
- :param topic_name:
25
- :param event:
26
- :return:
27
- """
28
-
29
- async def publish(self, topic_name: str, event: Event, **kwargs):
30
- """
31
- Publish on topic the event
32
-
33
- :param topic_name:
34
- :param event:
35
- :return:
36
- """
37
-
38
- logging.debug(f"{self._id} publishing on {topic_name}: {event}")
39
- self.on_publishing(topic_name, event)
40
- await self._internal_publish(topic_name, event, **kwargs)
41
- self.on_published(topic_name, event)
42
-
43
- def on_publishing(self, topic_name: str, event: Event):
44
- """
45
- Callback called on publishing start
46
-
47
- :param topic_name:
48
- :param event:
49
- :return:
50
- """
51
-
52
- def on_published(self, topic_name: str, event: Event):
53
- """
54
- Callback called on publishing end
55
-
56
- :param topic_name:
57
- :param event:
58
- :return:
59
- """
@@ -1,19 +0,0 @@
1
- from typing import Callable
2
- from busline.event.event import Event
3
- from busline.eventbus_client.subscriber.event_listener import EventListener
4
-
5
-
6
- class ClosureEventListener(EventListener):
7
- """
8
- Abstract event listener which use a pre-defined callback as `on_event`
9
-
10
- Author: Nicola Ricciardi
11
- """
12
-
13
- def __init__(self, on_event_callback: Callable[[str, Event], None]):
14
- EventListener.__init__(self)
15
-
16
- self.__on_event_callback = on_event_callback
17
-
18
- async def on_event(self, topic_name: str, event: Event, **kwargs):
19
- self.__on_event_callback(topic_name, event, **kwargs)
@@ -1,15 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from busline.event.event import Event
3
-
4
-
5
- class EventListener(ABC):
6
-
7
- @abstractmethod
8
- async def on_event(self, topic_name: str, event: Event, **kwargs):
9
- """
10
- Callback called when new event arrives
11
-
12
- :param topic_name:
13
- :param event:
14
- :return:
15
- """
@@ -1,17 +0,0 @@
1
- from typing import Callable
2
- from busline.event.event import Event
3
- from busline.eventbus.eventbus import EventBus
4
- from busline.eventbus_client.subscriber.closure_event_listener import ClosureEventListener
5
- from busline.eventbus_client.subscriber.local_eventbus_subscriber import LocalEventBusSubscriber
6
-
7
-
8
- class LocalEventBusClosureSubscriber(LocalEventBusSubscriber, ClosureEventListener):
9
- """
10
- Subscriber which works with local eventbus, this class can be initialized and used stand-alone
11
-
12
- Author: Nicola Ricciardi
13
- """
14
-
15
- def __init__(self, eventbus_instance: EventBus, on_event_callback: Callable[[str, Event], None]):
16
- LocalEventBusSubscriber.__init__(self, eventbus_instance)
17
- ClosureEventListener.__init__(self, on_event_callback)
@@ -1,40 +0,0 @@
1
- from abc import ABC
2
- from busline.eventbus.eventbus import EventBus
3
- from busline.eventbus_client.exceptions import EventBusClientNotConnected
4
- from busline.eventbus_client.subscriber.subscriber import Subscriber
5
-
6
-
7
- class LocalEventBusSubscriber(Subscriber, ABC):
8
- """
9
- Abstract subscriber which works with local eventbus without implementing `on_event` method
10
-
11
- Author: Nicola Ricciardi
12
- """
13
-
14
- def __init__(self, eventbus_instance: EventBus):
15
- Subscriber.__init__(self)
16
-
17
- self._eventbus = eventbus_instance
18
- self._connected = False
19
-
20
- async def connect(self):
21
- self._connected = True
22
-
23
- async def disconnect(self):
24
- self._connected = False
25
-
26
- async def _internal_subscribe(self, topic_name: str, raise_if_not_connected: bool = False, **kwargs):
27
- if raise_if_not_connected and not self._connected:
28
- raise EventBusClientNotConnected()
29
- else:
30
- await self.connect()
31
-
32
- self._eventbus.add_subscriber(topic_name, self)
33
-
34
- async def _internal_unsubscribe(self, topic_name: str | None = None, raise_if_not_connected: bool = False, **kwargs):
35
- if raise_if_not_connected and not self._connected:
36
- raise EventBusClientNotConnected()
37
- else:
38
- await self.connect()
39
-
40
- self._eventbus.remove_subscriber(self, topic_name)
@@ -1,93 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from uuid import uuid4
3
-
4
- from busline.event.event import Event
5
- from busline.eventbus_client.eventbus_connector import EventBusConnector
6
- from busline.eventbus_client.subscriber.event_listener import EventListener
7
-
8
-
9
- class Subscriber(EventBusConnector, EventListener, ABC):
10
- """
11
- Abstract class which can be implemented by your components which must be able to subscribe on eventbus
12
-
13
- Author: Nicola Ricciardi
14
- """
15
-
16
- def __init__(self, subscriber_id: str = str(uuid4())):
17
- EventBusConnector.__init__(self, subscriber_id)
18
- EventListener.__init__(self)
19
-
20
-
21
- @abstractmethod
22
- async def _internal_subscribe(self, topic_name: str, **kwargs):
23
- """
24
- Actual subscribe to topic
25
-
26
- :param topic_name:
27
- :return:
28
- """
29
-
30
- @abstractmethod
31
- async def _internal_unsubscribe(self, topic_name: str | None = None, **kwargs):
32
- """
33
- Actual unsubscribe to topic
34
-
35
- :param topic_name:
36
- :return:
37
- """
38
-
39
- async def subscribe(self, topic_name: str, **kwargs):
40
- """
41
- Subscribe to topic
42
-
43
- :param topic_name:
44
- :return:
45
- """
46
-
47
- self.on_subscribing(topic_name)
48
- await self._internal_subscribe(topic_name, **kwargs)
49
- self.on_subscribed(topic_name)
50
-
51
- async def unsubscribe(self, topic_name: str | None = None, **kwargs):
52
- """
53
- Unsubscribe to topic
54
-
55
- :param topic_name:
56
- :return:
57
- """
58
-
59
- self.on_unsubscribing(topic_name)
60
- await self._internal_unsubscribe(topic_name, **kwargs)
61
- self.on_unsubscribed(topic_name)
62
-
63
- def on_subscribing(self, topic_name: str):
64
- """
65
- Callback called on subscribing
66
-
67
- :param topic_name:
68
- :return:
69
- """
70
-
71
- def on_subscribed(self, topic_name: str):
72
- """
73
- Callback called on subscribed
74
-
75
- :param topic_name:
76
- :return:
77
- """
78
-
79
- def on_unsubscribing(self, topic_name: str):
80
- """
81
- Callback called on unsubscribing
82
-
83
- :param topic_name:
84
- :return:
85
- """
86
-
87
- def on_unsubscribed(self, topic_name: str):
88
- """
89
- Callback called on unsubscribed
90
-
91
- :param topic_name:
92
- :return:
93
- """
@@ -1,111 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: busline
3
- Version: 0.3.1
4
- Summary: Agnostic eventbus for Python
5
- Author-email: Nicola Ricciardi <ricciardincl@gmail.com>
6
- Project-URL: Homepage, https://github.com/nricciardi/py-busline
7
- Project-URL: Issues, https://github.com/nricciardi/py-busline/issues
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
-
15
- # Busline for Python
16
-
17
- Agnostic eventbus for Python.
18
-
19
- Official eventbus library for [Orbitalis](https://github.com/nricciardi/orbitalis)
20
-
21
- ## Local EventBus
22
-
23
- ### Using Publisher/Subscriber
24
-
25
- ```python
26
- from busline.eventbus.async_local_eventbus import AsyncLocalEventBus
27
- from busline.eventbus_client.publisher.local_eventbus_publisher import LocalEventBusPublisher
28
- from busline.event.event import Event
29
- from busline.eventbus_client.subscriber.local_eventbus_closure_subscriber import LocalEventBusClosureSubscriber
30
-
31
- local_eventbus_instance = AsyncLocalEventBus() # singleton
32
-
33
-
34
- def callback(topic_name: str, event: Event):
35
- print(event)
36
-
37
-
38
- subscriber = LocalEventBusClosureSubscriber(local_eventbus_instance, callback)
39
- publisher = LocalEventBusPublisher(local_eventbus_instance)
40
-
41
- await subscriber.subscribe("test-topic")
42
-
43
- await publisher.publish("test-topic", Event()) # publish empty event
44
- ```
45
-
46
- ### Using EventBusClient
47
-
48
- ```python
49
- from busline.event.event import Event
50
- from busline.eventbus_client.local_eventbus_client import LocalEventBusClient
51
-
52
-
53
- def callback(topic_name: str, event: Event):
54
- print(event)
55
-
56
-
57
- client = LocalEventBusClient(callback)
58
-
59
- await client.subscribe("test")
60
-
61
- await client.publish("test", Event())
62
- ```
63
-
64
-
65
- ## Create Agnostic EventBus
66
-
67
- Implement business logic of your `Publisher` and `Subscriber` and... done. Nothing more.
68
-
69
- ```python
70
- from busline.event.event import Event
71
- from busline.eventbus_client.publisher.publisher import Publisher
72
-
73
-
74
- class YourEventBusPublisher(Publisher):
75
-
76
- async def _internal_publish(self, topic_name: str, event: Event, **kwargs):
77
- pass # send events to your eventbus (maybe in cloud?)
78
- ```
79
-
80
- ```python
81
- from busline.eventbus_client.subscriber.subscriber import Subscriber
82
- from busline.event.event import Event
83
-
84
-
85
- class YourEventBusSubscriber(Subscriber):
86
-
87
- async def on_event(self, topic_name: str, event: Event, **kwargs):
88
- pass # receive your events
89
- ```
90
-
91
- You could create a client to allow components to use it instead of become a publisher or subscriber.
92
-
93
- ```python
94
- from busline.eventbus_client.eventbus_client import EventBusClient
95
- from busline.event.event import Event
96
-
97
-
98
- def client_callback(topic_name: str, e: Event):
99
- print(e)
100
-
101
-
102
- subscriber = YourEventBusSubscriber(...)
103
- publisher = YourEventBusPublisher(...)
104
-
105
- client = EventBusClient(publisher, subscriber, ClosureEventListener(client_callback))
106
- ```
107
-
108
-
109
-
110
-
111
-
@@ -1,30 +0,0 @@
1
- busline/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- busline/event/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- busline/event/event.py,sha256=dwO0MD9jw2ENRcW5TJy8aCayudYH-rf1k9WDxYdJanM,595
4
- busline/event/event_content.py,sha256=tPvltxfs66yRmUppHvdw5ThYR_K2WitvE5sLybg6vZE,341
5
- busline/event/event_metadata.py,sha256=7aaSG4Z9uQzJKRe7Jz8zD6jo6WEo3PORNbJA_RElp8I,556
6
- busline/eventbus/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- busline/eventbus/async_local_eventbus.py,sha256=LnuKtq1bha0yr6ucV_m-bBtldcB0iwVkIFmfFwoPU7w,772
8
- busline/eventbus/eventbus.py,sha256=Uhcdjcb3EZRYSeV8-I19qFB3CHHR1v8m0BQPkZo0n3Q,2997
9
- busline/eventbus/exceptions.py,sha256=sjWa3Eyeqyci2yVWO9jSlnaZggM3SFDbTKzMtdBX1-E,40
10
- busline/eventbus/queued_local_eventbus.py,sha256=PMqTE28fHkx1MYgj5VsxdM3jAQVyKW1elzlUTBM0jtw,1376
11
- busline/eventbus/topic.py,sha256=rzbdYrv0YLbC6CDoFGhbc8dOVc19OHCQknkTP4fZHh4,950
12
- busline/eventbus_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- busline/eventbus_client/eventbus_client.py,sha256=OqfYgmNkrkXQ4Hjoxji4H4YoqDxHxcrUMqHDKlP1TGc,3099
14
- busline/eventbus_client/eventbus_connector.py,sha256=zys73X8ul1UHyJHbIcmXBLucqCQhnLLVj9xDOVc1arU,702
15
- busline/eventbus_client/exceptions.py,sha256=gm7oZsXHlymheYDZb209T4FqeZN9Saft0Xklk4rOg54,55
16
- busline/eventbus_client/local_eventbus_client.py,sha256=k_Nqafe5McHCKwqnZHe52Fy9UFtSaN_A7CUFdOpjTCg,887
17
- busline/eventbus_client/publisher/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- busline/eventbus_client/publisher/local_eventbus_publisher.py,sha256=Gh50GuArq-jLaJMB-uCfUUFQ9PMKz03wY1NY1YIk3s4,1123
19
- busline/eventbus_client/publisher/publisher.py,sha256=JtUwIVj0_9SjX3lIzgepVAVrlE0fGqKETnGRGymcxIU,1544
20
- busline/eventbus_client/subscriber/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- busline/eventbus_client/subscriber/closure_event_listener.py,sha256=KSU2CyKto_wS-zASZ-5qNa5usCrg-iTj7dpWTHixe90,607
22
- busline/eventbus_client/subscriber/event_listener.py,sha256=EeQSkCuhAQNTLigzh2645tNH59tHneEiFzhmrPIzy-k,331
23
- busline/eventbus_client/subscriber/local_eventbus_closure_subscriber.py,sha256=LGvUDsiklHritTsblxvWXbyEmwbhDQN7Ze9rAgeVgdc,764
24
- busline/eventbus_client/subscriber/local_eventbus_subscriber.py,sha256=EyZqeVNe2WqXEnCoInnqhdADrGi3Zlqw-_umLIiAd74,1343
25
- busline/eventbus_client/subscriber/subscriber.py,sha256=AO3PenhPXrXuxp3jsvyr4r4zZh-zYDpkpoXG5Ut0SUs,2258
26
- busline-0.3.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
27
- busline-0.3.1.dist-info/METADATA,sha256=ezHdhoNgkpGCb2TGedtWYPEh8VF1v6_5DPw_Kirt6uc,2921
28
- busline-0.3.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
29
- busline-0.3.1.dist-info/top_level.txt,sha256=bZY0fK2wgNEI5igR7DBF3CyXHGkzujGvmoqdSzG6Zp0,8
30
- busline-0.3.1.dist-info/RECORD,,
File without changes