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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crewai_persistence_sql-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crewai_persistence_sql-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file crewai_persistence_sql-0.1.0.tar.gz.

File metadata

  • Download URL: crewai_persistence_sql-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.13

File hashes

Hashes for crewai_persistence_sql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83b6ac30d53c7f996bf0c0a5fff375050d8b8a81f75826f5bfba7aee68048355
MD5 43393b28be2d7f7d921bf27157d505bb
BLAKE2b-256 8bb44ea39b52e1007ea22cf924a0146f195d99453638024c8395e4f0d65aa635

See more details on using hashes here.

File details

Details for the file crewai_persistence_sql-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crewai_persistence_sql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de69fe1c22edb77f0676fc55ffe86f5d26a8d5d9fb5fb8b027ef912960e17d22
MD5 dc57aec648ea565cdf5ec5347cb704f3
BLAKE2b-256 d60750e4b79d9ec68b2338d2143cfa30ba8c506dacf308888f8773a74e56ac12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page