pydantic-ai-persistence
Backend-agnostic persistence for PydanticAI: chat history and durable step persistence, over one small async KV interface. Backends (DynamoDB, CosmosDB, Firestore) implement AsyncKV and get both stores.
PydanticAI has two persistence layers:
- History — you serialize
result.all_messages()and store it yourself.KVHistoryStoredoes exactly that. - Step persistence — PydanticAI's
StepStore(append-only events, continuable snapshots, tool-effect ledger) for durable/resumable runs.KVStepStoreimplements the asyncStepStoreprotocol.
Install
pip install pydantic-ai-persistence # core (in-memory backend)
pip install "pydantic-ai-persistence[dynamodb]" # + DynamoDB backend
Core pieces
| Component | What it does |
|---|---|
AsyncKV |
tiny async interface a backend implements (put/get/query/delete) |
InMemoryAsyncKV |
in-memory backend for tests/dev |
KVHistoryStore |
save(conversation_id, messages) / load(conversation_id) |
KVStepStore |
implements PydanticAI's async StepStore over an AsyncKV |
History
from pydantic_ai import Agent
from pydantic_ai_persistence import KVHistoryStore, InMemoryAsyncKV
store = KVHistoryStore(InMemoryAsyncKV())
result = agent.run_sync("Hi, I'm Kamal")
await store.save("conv-1", result.all_messages())
prior = await store.load("conv-1")
result = agent.run_sync("What's my name?", message_history=prior)
Step persistence
from pydantic_ai import Agent
from pydantic_ai_harness.step_persistence import StepPersistence
from pydantic_ai_persistence import KVStepStore, InMemoryAsyncKV
step_store = KVStepStore(InMemoryAsyncKV(), max_snapshots_per_run=10)
agent = Agent("openai:gpt-4o", capabilities=[StepPersistence(store=step_store)])
KVStepStore records runs, append-only events, continuable snapshots (with pruning), and the tool-effect ledger — everything the StepStore protocol requires.
Build your own backend
Implement AsyncKV (four async methods) and hand it to KVStepStore / KVHistoryStore. See pydantic-ai-dynamodb-persistence for an example.
Note:
StepStoreis a beta/experimental PydanticAI harness feature; its API may still change.
License
MIT
Metadata
Release files for pydantic-ai-persistence 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydantic_ai_persistence-0.1.0.tar.gz | 7.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_ai_persistence-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / pydantic_ai_persistence-0.1.0.tar.gz
| Download URL | pydantic_ai_persistence-0.1.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd7dba206d1e58bd4c1c8ebbbb87dd8068511d323e8ab632fe7166818c5f388f
|
|
BLAKE2b-256 checksum How to use checksums |
c03919e1367a7c38e3982d0d132130ecc9da717cd553e8c84ac38f5019ae0726
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.5
|
Release files / pydantic_ai_persistence-0.1.0-py3-none-any.whl
| Download URL | pydantic_ai_persistence-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0d035ed246ecb11c0ccbc80c79f61ffbb02953b4406d767231178c43a275c13
|
|
BLAKE2b-256 checksum How to use checksums |
dd86ba4d78f9f888f6cdc8f39ac4807952023ed72549163d08979cd73afed740
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.5
|
Security for pydantic-ai-persistence 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.