Back to Pydantic Ai

Stream Whales

docs/examples/stream-whales.md

1.90.0709 B
Original Source

Information about whales — an example of streamed structured response validation.

Demonstrates:

This script streams structured responses about whales, validates the data and displays it as a dynamic table using rich as the data is received.

Running the Example

With dependencies installed and environment variables set, run:

bash
python/uv-run -m pydantic_ai_examples.stream_whales

Should give an output like this:

{{ video('53dd5e7664c20ae90ed90ae42f606bf3', 25) }}

Example Code

snippet {path="/examples/pydantic_ai_examples/stream_whales.py"}