Skip to content

Commit 08d0242

Browse files
committed
Release 0.0.43
1 parent c826c91 commit 08d0242

22 files changed

Lines changed: 1371 additions & 190 deletions

README.md

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ Instantiate and use the client with the following:
2121

2222
```python
2323
from agentmail import AgentMail
24-
client = AgentMail(api_key="YOUR_API_KEY", )
24+
25+
client = AgentMail(
26+
api_key="YOUR_API_KEY",
27+
)
2528
client.inboxes.create()
2629
```
2730

@@ -30,11 +33,19 @@ client.inboxes.create()
3033
The SDK also exports an `async` client so that you can make non-blocking calls to our API.
3134

3235
```python
33-
from agentmail import AsyncAgentMail
3436
import asyncio
35-
client = AsyncAgentMail(api_key="YOUR_API_KEY", )
37+
38+
from agentmail import AsyncAgentMail
39+
40+
client = AsyncAgentMail(
41+
api_key="YOUR_API_KEY",
42+
)
43+
44+
3645
async def main() -> None:
3746
await client.inboxes.create()
47+
48+
3849
asyncio.run(main())
3950
```
4051

@@ -45,6 +56,7 @@ will be thrown.
4556

4657
```python
4758
from agentmail.core.api_error import ApiError
59+
4860
try:
4961
client.inboxes.create(...)
5062
except ApiError as e:
@@ -61,7 +73,10 @@ The `.with_raw_response` property returns a "raw" client that can be used to acc
6173

6274
```python
6375
from agentmail import AgentMail
64-
client = AgentMail(..., )
76+
77+
client = AgentMail(
78+
...,
79+
)
6580
response = client.inboxes.with_raw_response.create(...)
6681
print(response.headers) # access the response headers
6782
print(response.data) # access the underlying object
@@ -94,7 +109,12 @@ The SDK defaults to a 60 second timeout. You can configure this with a timeout o
94109
```python
95110

96111
from agentmail import AgentMail
97-
client = AgentMail(..., timeout=20.0, )
112+
113+
client = AgentMail(
114+
...,
115+
timeout=20.0,
116+
)
117+
98118

99119
# Override timeout for a specific method
100120
client.inboxes.create(..., request_options={
@@ -108,9 +128,17 @@ You can override the `httpx` client to customize it for your use-case. Some comm
108128
and transports.
109129

110130
```python
111-
from agentmail import AgentMail
112131
import httpx
113-
client = AgentMail(..., httpx_client=httpx.Client(proxies="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0"), ))```
132+
from agentmail import AgentMail
133+
134+
client = AgentMail(
135+
...,
136+
httpx_client=httpx.Client(
137+
proxies="http://my.test.proxy.example.com",
138+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
139+
),
140+
)
141+
```
114142

115143
## Contributing
116144

@@ -121,3 +149,59 @@ a proof of concept, but know that we will not be able to merge it as-is. We sugg
121149
an issue first to discuss with us!
122150

123151
On the other hand, contributions to the README are always very welcome!
152+
## Websockets
153+
154+
The SDK supports both sync and async websocket connections for real-time, low-latency communication. Sockets can be created using the `connect` method, which returns a context manager.
155+
You can either iterate through the returned `SocketClient` to process messages as they arrive, or attach handlers to respond to specific events.
156+
157+
```python
158+
159+
# Connect to the websocket (Sync)
160+
import threading
161+
162+
from agentmail import AgentMail
163+
164+
client = AgentMail(...)
165+
166+
with client.websockets.connect(...) as socket:
167+
# Iterate over the messages as they arrive
168+
for message in socket
169+
print(message)
170+
171+
# Or, attach handlers to specific events
172+
socket.on(EventType.OPEN, lambda _: print("open"))
173+
socket.on(EventType.MESSAGE, lambda message: print("received message", message))
174+
socket.on(EventType.CLOSE, lambda _: print("close"))
175+
socket.on(EventType.ERROR, lambda error: print("error", error))
176+
177+
178+
# Start the listening loop in a background thread
179+
listener_thread = threading.Thread(target=socket.start_listening, daemon=True)
180+
listener_thread.start()
181+
```
182+
183+
```python
184+
185+
# Connect to the websocket (Async)
186+
import asyncio
187+
188+
from agentmail import AsyncAgentMail
189+
190+
client = AsyncAgentMail(...)
191+
192+
async with client.websockets.connect(...) as socket:
193+
# Iterate over the messages as they arrive
194+
async for message in socket
195+
print(message)
196+
197+
# Or, attach handlers to specific events
198+
socket.on(EventType.OPEN, lambda _: print("open"))
199+
socket.on(EventType.MESSAGE, lambda message: print("received message", message))
200+
socket.on(EventType.CLOSE, lambda _: print("close"))
201+
socket.on(EventType.ERROR, lambda error: print("error", error))
202+
203+
204+
# Start listening for events in an asyncio task
205+
listen_task = asyncio.create_task(socket.start_listening())
206+
```
207+

poetry.lock

Lines changed: 96 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "agentmail"
33

44
[tool.poetry]
55
name = "agentmail"
6-
version = "0.0.42"
6+
version = "0.0.43"
77
description = ""
88
readme = "README.md"
99
authors = []
@@ -37,8 +37,9 @@ Repository = 'https://github.com/agentmail-to/agentmail-python'
3737
python = "^3.8"
3838
httpx = ">=0.21.2"
3939
pydantic = ">= 1.9.2"
40-
pydantic-core = "^2.18.2"
40+
pydantic-core = ">=2.18.2"
4141
typing_extensions = ">= 4.0.0"
42+
websockets = ">=12.0"
4243

4344
[tool.poetry.group.dev.dependencies]
4445
mypy = "==1.13.0"

0 commit comments

Comments
 (0)