Skip to content

Commit 681e90f

Browse files
docs: add more examples
1 parent dde1e8b commit 681e90f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,40 @@ async def main() -> None:
127127
asyncio.run(main())
128128
```
129129

130+
## Streaming responses
131+
132+
We provide support for streaming responses using Server Side Events (SSE).
133+
134+
```python
135+
from stagehand import Stagehand
136+
137+
client = Stagehand()
138+
139+
stream = client.sessions.act(
140+
id="00000000-your-session-id-000000000000",
141+
input="click the first link on the page",
142+
stream_response=True,
143+
)
144+
for response in stream:
145+
print(response.data)
146+
```
147+
148+
The async client uses the exact same interface.
149+
150+
```python
151+
from stagehand import AsyncStagehand
152+
153+
client = AsyncStagehand()
154+
155+
stream = await client.sessions.act(
156+
id="00000000-your-session-id-000000000000",
157+
input="click the first link on the page",
158+
stream_response=True,
159+
)
160+
async for response in stream:
161+
print(response.data)
162+
```
163+
130164
## Using types
131165

132166
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:

0 commit comments

Comments
 (0)