Storage Backends
PraisonAI provides pluggable storage backends for training data, session state, and general persistence. Switch between file-based and database storage without changing your application code.Supported Backends
| Backend | Type | Dependencies | Best For |
|---|---|---|---|
| FileBackend | JSON files | None (built-in) | Development, simple deployments |
| SQLiteBackend | SQLite DB | None (built-in) | Production, concurrent access |
| PostgreSQL | Via adapters | psycopg2 | Large-scale production |
| MySQL | Via adapters | mysql-connector | Enterprise deployments |
| Redis | Via adapters | redis | High-speed caching |
Quick Start
Any Component with Any Backend
All storage components support pluggable backends. Create a backend once and use it with any component:FileBackend
JSON file-based storage. Each key becomes a separate.json file.
- Zero dependencies (uses built-in
json) - Thread-safe with atomic writes
- Human-readable files
- Easy debugging and inspection
SQLiteBackend
SQLite database storage. All data in a single.db file.
- Zero dependencies (uses built-in
sqlite3) - ACID transactions
- Better concurrent access
- Faster for large datasets
- Single file deployment
Using with Training Storage
Using with Learn Stores
Async Support
For async applications, useAsyncBaseJSONStore:
Custom Backends
ImplementStorageBackendProtocol for custom backends:
Protocol Reference
RedisBackend
Redis-based storage for high-speed caching and ephemeral data.- Sub-millisecond latency
- Built-in TTL support
- Automatic key prefixing
- Requires
redispackage:pip install redis
Using with RunHistory (Recipe History)
Store recipe run history with pluggable backends:Using with SessionManager (Session State)
Persist CLI session state with different backends:Using with MCPToolIndex (Tool Index)
Store MCP tool schemas with pluggable backends:Choosing a Backend
| Use Case | Recommended Backend | Why |
|---|---|---|
| Development | FileBackend | Easy debugging, human-readable |
| Single-user app | SQLiteBackend | Better performance, single file |
| Multi-process | SQLiteBackend | Handles concurrent access |
| Production web | PostgreSQL adapter | Scalable, reliable |
| High-speed cache | RedisBackend | Sub-ms latency, TTL support |
| Serverless | SQLiteBackend or cloud DB | No server management |
| Session caching | RedisBackend | Fast, ephemeral data |
| Distributed systems | RedisBackend | Shared state across nodes |
| Recipe history | SQLiteBackend | Reliable, queryable |
| MCP tool registry | SQLiteBackend or RedisBackend | Fast lookups |
Backend Comparison
| Feature | FileBackend | SQLiteBackend | RedisBackend |
|---|---|---|---|
| Dependencies | None | None | redis package |
| Concurrency | File locks | ACID transactions | Native |
| Performance | Good | Better | Best |
| TTL Support | ❌ | ❌ | ✅ |
| Distributed | ❌ | ❌ | ✅ |
| Human-readable | ✅ | ❌ | ❌ |
| Single file | ❌ | ✅ | N/A |

