Skip to main content

crewai-persistence-sql

SQL persistence backend for CrewAI Flows via SQLAlchemy — one provider for SQLite, PostgreSQL, MySQL, and more, selected by connection URL. Optional built-in message pruning via agentstate-reducer. Implements CrewAI's FlowPersistence interface.

Installation

pip install crewai-persistence-sql               # SQLite built-in
pip install "crewai-persistence-sql[postgres]"   # + psycopg
pip install "crewai-persistence-sql[mysql]"      # + pymysql
pip install "crewai-persistence-sql[reducer]"    # + message pruning

Requires Python 3.10–3.13.

Usage

from crewai.flow.flow import Flow, start
from crewai.flow.persistence import persist
from crewai_persistence_sql import SQLFlowPersistence

backend = SQLFlowPersistence(url="sqlite:///crewai_flows.db")
# or  "postgresql+psycopg://user:pass@host/db"  /  "mysql+pymysql://user:pass@host/db"

@persist(backend)
class MyFlow(Flow[MyState]):
    @start()
    def begin(self):
        self.state.counter += 1

With message pruning:

from agentstate_reducer import MessageReducer
backend = SQLFlowPersistence(
    url="sqlite:///crewai_flows.db",
    reducer=MessageReducer(min_messages=10, max_messages=20),
    messages_key="messages",
)

API

SQLFlowPersistence(url=None, *, table_name="crewai_flow_states", engine=None, reducer=None, messages_key="messages")

Parameter Description
url SQLAlchemy connection URL
table_name table (auto-created if absent)
engine optional pre-built SQLAlchemy Engine (supply this or url)
reducer optional MessageReducer to prune messages_key before save
messages_key state field holding the message list (default "messages")

Data model

One row per flow: flow_uuid (primary key) + data (the flow state as a JSON string). Each save upserts (portable update-then-insert), so load_state returns the latest.

License

MIT

Metadata

Release files for crewai_persistence_sql 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crewai_persistence_sql 0.1.0
File Size Uploaded
crewai_persistence_sql-0.1.0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crewai_persistence_sql 0.1.0
File Interpreter ABI Platform
crewai_persistence_sql-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / crewai_persistence_sql-0.1.0.tar.gz

Download URL crewai_persistence_sql-0.1.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
83b6ac30d53c7f996bf0c0a5fff375050d8b8a81f75826f5bfba7aee68048355
BLAKE2b-256 checksum
How to use checksums
8bb44ea39b52e1007ea22cf924a0146f195d99453638024c8395e4f0d65aa635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / crewai_persistence_sql-0.1.0-py3-none-any.whl

Download URL crewai_persistence_sql-0.1.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de69fe1c22edb77f0676fc55ffe86f5d26a8d5d9fb5fb8b027ef912960e17d22
BLAKE2b-256 checksum
How to use checksums
d60750e4b79d9ec68b2338d2143cfa30ba8c506dacf308888f8773a74e56ac12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release history Release notifications | RSS feed

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page