swarmauri_transport_sseoutbound 0.1.1.dev18__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.
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Jacob Stewart
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_transport_sseoutbound
3
+ Version: 0.1.1.dev18
4
+ Summary: Server-Sent Events broadcaster transport for Swarmauri agents.
5
+ License: Copyright 2024 Jacob Stewart
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+ License-File: LICENSE
19
+ Keywords: swarmauri,transport,sse,events,broadcast,streaming,http,asyncio,realtime,sdk,standards,sseoutbound
20
+ Author: Jacob Stewart
21
+ Author-email: jacob@swarmauri.com
22
+ Requires-Python: >=3.10
23
+ Classifier: Development Status :: 2 - Pre-Alpha
24
+ Classifier: Intended Audience :: Developers
25
+ Classifier: License :: OSI Approved :: Apache Software License
26
+ Classifier: Programming Language :: Python
27
+ Classifier: Programming Language :: Python :: 3
28
+ Classifier: Programming Language :: Python :: 3 :: Only
29
+ Classifier: Programming Language :: Python :: 3.10
30
+ Classifier: Programming Language :: Python :: 3.11
31
+ Classifier: Programming Language :: Python :: 3.12
32
+ Classifier: Topic :: Internet :: WWW/HTTP
33
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
34
+ Requires-Dist: swarmauri-base
35
+ Requires-Dist: swarmauri-core
36
+ Project-URL: Homepage, https://github.com/swarmauri/swarmauri-sdk
37
+ Project-URL: Repository, https://github.com/swarmauri/swarmauri-sdk
38
+ Description-Content-Type: text/markdown
39
+
40
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
41
+
42
+ <p align="center">
43
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
44
+ <img src="https://img.shields.io/pypi/dm/swarmauri-transport-sseoutbound" alt="PyPI - Downloads"/>
45
+ </a>
46
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/swarmauri_transport_sseoutbound/">
47
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/swarmauri_transport_sseoutbound.svg"/>
48
+ </a>
49
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
50
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri-transport-sseoutbound" alt="PyPI - Python Version"/>
51
+ </a>
52
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
53
+ <img src="https://img.shields.io/pypi/l/swarmauri-transport-sseoutbound" alt="PyPI - License"/>
54
+ </a>
55
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
56
+ <img src="https://img.shields.io/pypi/v/swarmauri-transport-sseoutbound?label=swarmauri-transport-sseoutbound&color=green" alt="PyPI - swarmauri-transport-sseoutbound"/>
57
+ </a>
58
+ </p>
59
+
60
+ ---
61
+
62
+ # Swarmauri Transport – Server-Sent Events
63
+
64
+ `swarmauri-transport-sseoutbound` hosts a lightweight SSE endpoint for broadcasting real-time updates to browsers or other streaming clients.
65
+
66
+ ## Installation
67
+
68
+ ### Using `uv`
69
+
70
+ ```bash
71
+ uv pip install swarmauri-transport-sseoutbound --index-url https://pypi.org/simple
72
+ ```
73
+
74
+ ### Using `pip`
75
+
76
+ ```bash
77
+ pip install swarmauri-transport-sseoutbound
78
+ ```
79
+
80
+ ## Usage
81
+
82
+ ```python
83
+ import asyncio
84
+ from swarmauri_transport_sseoutbound import SSEOutboundTransport
85
+
86
+ async def main() -> None:
87
+ transport = SSEOutboundTransport()
88
+ async with transport.server(host="0.0.0.0", port=8082):
89
+ await transport.broadcast(b"hello, world!")
90
+
91
+ asyncio.run(main())
92
+ ```
93
+
94
+ Attach your own event loop or scheduler to push updates whenever your agents produce new data.
95
+
@@ -0,0 +1,55 @@
1
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
+
3
+ <p align="center">
4
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
5
+ <img src="https://img.shields.io/pypi/dm/swarmauri-transport-sseoutbound" alt="PyPI - Downloads"/>
6
+ </a>
7
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/swarmauri_transport_sseoutbound/">
8
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/swarmauri_transport_sseoutbound.svg"/>
9
+ </a>
10
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
11
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri-transport-sseoutbound" alt="PyPI - Python Version"/>
12
+ </a>
13
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
14
+ <img src="https://img.shields.io/pypi/l/swarmauri-transport-sseoutbound" alt="PyPI - License"/>
15
+ </a>
16
+ <a href="https://pypi.org/project/swarmauri-transport-sseoutbound/">
17
+ <img src="https://img.shields.io/pypi/v/swarmauri-transport-sseoutbound?label=swarmauri-transport-sseoutbound&color=green" alt="PyPI - swarmauri-transport-sseoutbound"/>
18
+ </a>
19
+ </p>
20
+
21
+ ---
22
+
23
+ # Swarmauri Transport – Server-Sent Events
24
+
25
+ `swarmauri-transport-sseoutbound` hosts a lightweight SSE endpoint for broadcasting real-time updates to browsers or other streaming clients.
26
+
27
+ ## Installation
28
+
29
+ ### Using `uv`
30
+
31
+ ```bash
32
+ uv pip install swarmauri-transport-sseoutbound --index-url https://pypi.org/simple
33
+ ```
34
+
35
+ ### Using `pip`
36
+
37
+ ```bash
38
+ pip install swarmauri-transport-sseoutbound
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```python
44
+ import asyncio
45
+ from swarmauri_transport_sseoutbound import SSEOutboundTransport
46
+
47
+ async def main() -> None:
48
+ transport = SSEOutboundTransport()
49
+ async with transport.server(host="0.0.0.0", port=8082):
50
+ await transport.broadcast(b"hello, world!")
51
+
52
+ asyncio.run(main())
53
+ ```
54
+
55
+ Attach your own event loop or scheduler to push updates whenever your agents produce new data.
@@ -0,0 +1,77 @@
1
+ [project]
2
+ name = "swarmauri_transport_sseoutbound"
3
+ version = "0.1.1.dev18"
4
+ description = "Server-Sent Events broadcaster transport for Swarmauri agents."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
8
+ license = { file = "LICENSE" }
9
+ dependencies = [
10
+ "swarmauri-base",
11
+ "swarmauri-core",
12
+ ]
13
+ keywords = [
14
+ "swarmauri",
15
+ "transport",
16
+ "sse",
17
+ "events",
18
+ "broadcast",
19
+ "streaming",
20
+ "http",
21
+ "asyncio",
22
+ "realtime",
23
+ "sdk",
24
+ "standards",
25
+ "sseoutbound",
26
+ ]
27
+ classifiers = [
28
+ "Development Status :: 2 - Pre-Alpha",
29
+ "Intended Audience :: Developers",
30
+ "License :: OSI Approved :: Apache Software License",
31
+ "Programming Language :: Python",
32
+ "Programming Language :: Python :: 3",
33
+ "Programming Language :: Python :: 3 :: Only",
34
+ "Programming Language :: Python :: 3.10",
35
+ "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
37
+ "Topic :: Internet :: WWW/HTTP",
38
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
39
+ ]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/swarmauri/swarmauri-sdk"
43
+ Repository = "https://github.com/swarmauri/swarmauri-sdk"
44
+
45
+ [build-system]
46
+ requires = ["poetry-core>=1.8.0"]
47
+ build-backend = "poetry.core.masonry.api"
48
+
49
+ [tool.pytest.ini_options]
50
+ markers = [
51
+ "test: standard test",
52
+ "unit: Unit tests",
53
+ "i9n: Integration tests",
54
+ "r8n: Regression tests",
55
+ "acceptance: Acceptance tests",
56
+ "perf: Performance tests",
57
+ "example: Documentation examples",
58
+ ]
59
+ timeout = 300
60
+ log_cli = true
61
+ log_cli_level = "INFO"
62
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
63
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
64
+ asyncio_default_fixture_loop_scope = "function"
65
+ addopts = "--pylicense-accept-deps=sniffio"
66
+
67
+ [dependency-groups]
68
+ dev = [
69
+ "pytest>=8.0",
70
+ "pytest-asyncio>=0.24.0",
71
+ "pytest-xdist>=3.6.1",
72
+ "pytest-json-report>=1.5.0",
73
+ "pytest-timeout>=2.3.1",
74
+ "pytest-benchmark>=4.0.0",
75
+ "ruff>=0.9.9",
76
+ "swarmauri_tests_pylicense",
77
+ ]
@@ -0,0 +1,5 @@
1
+ """Server-Sent Events outbound transport package."""
2
+
3
+ from .sse_outbound import SSEOutboundTransport
4
+
5
+ __all__ = ["SSEOutboundTransport"]
@@ -0,0 +1,87 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import contextlib
5
+ import ssl
6
+ from typing import Optional, Set
7
+
8
+ from swarmauri_base.transports.runnable_mixin import RunnableMixin
9
+ from swarmauri_base.transports.TransportBase import TransportBase
10
+ from swarmauri_core.transports.capabilities import TransportCapabilities
11
+ from swarmauri_core.transports.enums import (
12
+ AddressScheme,
13
+ Cast,
14
+ Feature,
15
+ IOModel,
16
+ Protocol,
17
+ SecurityMode,
18
+ )
19
+
20
+
21
+ class SSEOutboundTransport(TransportBase, RunnableMixin):
22
+ """Server-Sent Events transport for broadcasting data to clients."""
23
+
24
+ def __init__(self) -> None:
25
+ super().__init__(name="SSE")
26
+ self._server: asyncio.AbstractServer | None = None
27
+ self._clients: Set[asyncio.StreamWriter] = set()
28
+
29
+ def supports(self) -> TransportCapabilities:
30
+ return TransportCapabilities(
31
+ protocols=frozenset({Protocol.HTTP1, Protocol.H2}),
32
+ io=IOModel.STREAM,
33
+ casts=frozenset({Cast.BROADCAST}),
34
+ features=frozenset({Feature.RELIABLE, Feature.ORDERED}),
35
+ security=SecurityMode.TLS,
36
+ schemes=frozenset({AddressScheme.HTTP, AddressScheme.HTTPS}),
37
+ )
38
+
39
+ async def _start_server(
40
+ self,
41
+ host: str = "0.0.0.0",
42
+ port: int = 8082,
43
+ ssl_ctx: Optional[ssl.SSLContext] = None,
44
+ ) -> None:
45
+ async def _handler(
46
+ reader: asyncio.StreamReader, writer: asyncio.StreamWriter
47
+ ) -> None:
48
+ writer.write(
49
+ b"HTTP/1.1 200 OK\r\n"
50
+ b"Content-Type: text/event-stream\r\n"
51
+ b"Cache-Control: no-cache\r\n\r\n"
52
+ )
53
+ await writer.drain()
54
+ self._clients.add(writer)
55
+ try:
56
+ await asyncio.Event().wait()
57
+ finally:
58
+ self._clients.discard(writer)
59
+ writer.close()
60
+ with contextlib.suppress(Exception):
61
+ await writer.wait_closed()
62
+
63
+ self._server = await asyncio.start_server(_handler, host, port, ssl=ssl_ctx)
64
+
65
+ async def _stop_server(self) -> None:
66
+ if self._server is not None:
67
+ self._server.close()
68
+ await self._server.wait_closed()
69
+ self._server = None
70
+
71
+ async def _open_client(self, **kwargs) -> None:
72
+ raise NotImplementedError("SSE transport is server-only")
73
+
74
+ async def _close_client(self) -> None:
75
+ return None
76
+
77
+ async def broadcast(self, data: bytes) -> None:
78
+ frame = b"data: " + data + b"\n\n"
79
+ dead: list[asyncio.StreamWriter] = []
80
+ for writer in list(self._clients):
81
+ try:
82
+ writer.write(frame)
83
+ await writer.drain()
84
+ except Exception:
85
+ dead.append(writer)
86
+ for writer in dead:
87
+ self._clients.discard(writer)