swarmauri_transport_stdio 0.1.1.dev18__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.
- swarmauri_transport_stdio/__init__.py +5 -0
- swarmauri_transport_stdio/stdio_transport.py +70 -0
- swarmauri_transport_stdio-0.1.1.dev18.dist-info/METADATA +96 -0
- swarmauri_transport_stdio-0.1.1.dev18.dist-info/RECORD +6 -0
- swarmauri_transport_stdio-0.1.1.dev18.dist-info/WHEEL +4 -0
- swarmauri_transport_stdio-0.1.1.dev18.dist-info/licenses/LICENSE +13 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import contextlib
|
|
5
|
+
from typing import Optional, Sequence
|
|
6
|
+
|
|
7
|
+
from swarmauri_base.transports.peer_mixin import PeerTransportMixin
|
|
8
|
+
from swarmauri_base.transports.runnable_mixin import RunnableMixin
|
|
9
|
+
from swarmauri_base.transports.TransportBase import TransportBase
|
|
10
|
+
from swarmauri_base.transports.unicast_mixin import UnicastTransportMixin
|
|
11
|
+
from swarmauri_core.transports.capabilities import TransportCapabilities
|
|
12
|
+
from swarmauri_core.transports.enums import (
|
|
13
|
+
AddressScheme,
|
|
14
|
+
Cast,
|
|
15
|
+
Feature,
|
|
16
|
+
IOModel,
|
|
17
|
+
Protocol,
|
|
18
|
+
SecurityMode,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class StdioTransport(
|
|
23
|
+
TransportBase, RunnableMixin, PeerTransportMixin, UnicastTransportMixin
|
|
24
|
+
):
|
|
25
|
+
"""Spawned process transport that communicates over stdio."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, argv: Sequence[str]) -> None:
|
|
28
|
+
super().__init__(name="STDIO")
|
|
29
|
+
self._argv = list(argv)
|
|
30
|
+
self._process: asyncio.Process | None = None
|
|
31
|
+
|
|
32
|
+
def supports(self) -> TransportCapabilities:
|
|
33
|
+
return TransportCapabilities(
|
|
34
|
+
protocols=frozenset({Protocol.STDIO}),
|
|
35
|
+
io=IOModel.STREAM,
|
|
36
|
+
casts=frozenset({Cast.UNICAST}),
|
|
37
|
+
features=frozenset({Feature.RELIABLE, Feature.ORDERED}),
|
|
38
|
+
security=SecurityMode.NONE,
|
|
39
|
+
schemes=frozenset({AddressScheme.STDIO}),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
async def _start_server(self, **kwargs) -> None:
|
|
43
|
+
raise NotImplementedError("STDIO transport launches child processes only")
|
|
44
|
+
|
|
45
|
+
async def _open_client(self) -> None:
|
|
46
|
+
self._process = await asyncio.create_subprocess_exec(
|
|
47
|
+
*self._argv,
|
|
48
|
+
stdin=asyncio.subprocess.PIPE,
|
|
49
|
+
stdout=asyncio.subprocess.PIPE,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
async def _close_client(self) -> None:
|
|
53
|
+
if self._process is not None:
|
|
54
|
+
self._process.terminate()
|
|
55
|
+
with contextlib.suppress(Exception):
|
|
56
|
+
await self._process.wait()
|
|
57
|
+
self._process = None
|
|
58
|
+
|
|
59
|
+
async def send(
|
|
60
|
+
self, target: str, data: bytes, *, timeout: Optional[float] = None
|
|
61
|
+
) -> None:
|
|
62
|
+
if self._process is None or self._process.stdin is None:
|
|
63
|
+
raise RuntimeError("not connected")
|
|
64
|
+
self._process.stdin.write(data)
|
|
65
|
+
await asyncio.wait_for(self._process.stdin.drain(), timeout)
|
|
66
|
+
|
|
67
|
+
async def recv(self, *, timeout: Optional[float] = None) -> bytes:
|
|
68
|
+
if self._process is None or self._process.stdout is None:
|
|
69
|
+
raise RuntimeError("not connected")
|
|
70
|
+
return await asyncio.wait_for(self._process.stdout.read(65536), timeout)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_transport_stdio
|
|
3
|
+
Version: 0.1.1.dev18
|
|
4
|
+
Summary: STDIO bridge transport for spawning Swarmauri-compatible subprocesses.
|
|
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,stdio,subprocess,cli,asyncio,bridge,sdk,standards
|
|
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 :: Software Development :: Libraries
|
|
33
|
+
Classifier: Topic :: System :: Shells
|
|
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
|
+

|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
<a href="https://pypi.org/project/swarmauri-transport-stdio/">
|
|
44
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri-transport-stdio" alt="PyPI - Downloads"/>
|
|
45
|
+
</a>
|
|
46
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/swarmauri_transport_stdio/">
|
|
47
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/swarmauri_transport_stdio.svg"/>
|
|
48
|
+
</a>
|
|
49
|
+
<a href="https://pypi.org/project/swarmauri-transport-stdio/">
|
|
50
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri-transport-stdio" alt="PyPI - Python Version"/>
|
|
51
|
+
</a>
|
|
52
|
+
<a href="https://pypi.org/project/swarmauri-transport-stdio/">
|
|
53
|
+
<img src="https://img.shields.io/pypi/l/swarmauri-transport-stdio" alt="PyPI - License"/>
|
|
54
|
+
</a>
|
|
55
|
+
<a href="https://pypi.org/project/swarmauri-transport-stdio/">
|
|
56
|
+
<img src="https://img.shields.io/pypi/v/swarmauri-transport-stdio?label=swarmauri-transport-stdio&color=green" alt="PyPI - swarmauri-transport-stdio"/>
|
|
57
|
+
</a>
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
# Swarmauri Transport – STDIO Bridge
|
|
63
|
+
|
|
64
|
+
`swarmauri-transport-stdio` spawns subprocesses and communicates over standard input/output so command-line tools can act as Swarmauri peers.
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
### Using `uv`
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
uv pip install swarmauri-transport-stdio --index-url https://pypi.org/simple
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Using `pip`
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install swarmauri-transport-stdio
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Usage
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import asyncio
|
|
84
|
+
from swarmauri_transport_stdio import StdioTransport
|
|
85
|
+
|
|
86
|
+
async def run_tool() -> None:
|
|
87
|
+
transport = StdioTransport(["python", "script.py"])
|
|
88
|
+
async with transport.client():
|
|
89
|
+
await transport.send("tool", b"input\n")
|
|
90
|
+
print(await transport.recv())
|
|
91
|
+
|
|
92
|
+
asyncio.run(run_tool())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Wrap any CLI-friendly model or service and adapt its IO using the Swarmauri transport interfaces.
|
|
96
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
swarmauri_transport_stdio/__init__.py,sha256=Za_ARONZuTqcMKw6OGzoDunpKEkaj9NxX5Fvdffczvo,106
|
|
2
|
+
swarmauri_transport_stdio/stdio_transport.py,sha256=iRC3Ze88g4yoQPbOC1ukDbINwcYkJl2zf7sP9pnf8is,2535
|
|
3
|
+
swarmauri_transport_stdio-0.1.1.dev18.dist-info/METADATA,sha256=ZJpLoaUFK360jnJDQF495Trfg6Ajc50ZuIAV9d_SvJQ,3789
|
|
4
|
+
swarmauri_transport_stdio-0.1.1.dev18.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
5
|
+
swarmauri_transport_stdio-0.1.1.dev18.dist-info/licenses/LICENSE,sha256=kkwAgrDtfQ7c-Ozql2xlztDDjHt0YwGmRG7b_oUU9Jg,554
|
|
6
|
+
swarmauri_transport_stdio-0.1.1.dev18.dist-info/RECORD,,
|
|
@@ -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.
|