What is db_storage_path()?
db_storage_path() is the supported API for discovering where CrewAI drops SQLite corpora, LanceDB folders, Chroma persistence, and other local artifacts — defaulting to `./.crewai/` relative to the process current working directory unless CREWAI_STORAGE_DIR overrides it. Ops scripts should always call the helper instead of hard-coding paths so containers, laptops, and CI runners stay aligned when operators export the env var.
Use the returned Path-like string in backup jobs, disk-quota monitors, and GDPR deletion workflows. Pair it with reset_memories flags when you need logical wipes without deleting the entire directory, and with filesystem rm -rf only when you intentionally nuke all persisted state for a tenant.
Remember cwd sensitivity: daemons that chdir after startup may resolve different paths than your shell session. Set CREWAI_STORAGE_DIR to an absolute location in systemd units, Kubernetes manifests, and Windows services.
Use Cases
- • Backup
- • Migration
- • Cleanup
Key Features
- ✓ Honors CREWAI_STORAGE_DIR
When NOT to Use
Within normal flow code — use higher-level memory APIs.
Notes
Working directory surprises
Relative defaults resolve against cwd, not the project root. Pin absolute CREWAI_STORAGE_DIR in long-running services.
Multi-tenant hosts
A single path per machine means tenants share physical storage unless you fork processes with distinct env vars or containers.
Backup locking
SQLite files may be WAL-mode locked while crews run. Use VSS snapshots or online backup tools instead of blind copy during active kickoffs.
Log redaction
Paths may include usernames or customer ids on shared laptops. Scrub logs before shipping diagnostics externally.
Code Examples
print(db_storage_path())
Archive directory size before maintenance
from pathlib import Path
from crewai.utilities.paths import db_storage_path
root = Path(db_storage_path())
print(sum(p.stat().st_size for p in root.rglob('*') if p.is_file()))
Docker-friendly absolute root
import os
from crewai.utilities.paths import db_storage_path
os.environ.setdefault('CREWAI_STORAGE_DIR', '/var/lib/crewai')
DATA = db_storage_path()
print(DATA)
When to Use
Ops scripts that need to manipulate persistent state.
Common Mistakes
❌ Hard-coding `./.crewai`
✅ Use db_storage_path() so env overrides work.
Related: @tool decorator reference, Agent class reference, and the first Crew tutorial.
db_storage_path() FAQ
What is db_storage_path() in CrewAI?
Returns the on-disk path where CrewAI stores memory and knowledge databases. db_storage_path() is the supported API for discovering where CrewAI drops SQLite corpora, LanceDB folders, Chroma persistence, and other local artifacts — defaulting to `./.crewai/` relative to the process current working directory unless CREWAI_STORAGE_DIR overrides it. Ops scripts should always call the helper instead of hard-coding paths so containers, laptops, and CI runners stay aligned when operators export the env var. Use the returned Path-like string in backup jobs,…
Which CrewAI types expose the method db_storage_path()?
DevShelfHub documents db_storage_path() on Storage utilities. The reference maps it to Python module crewai.utilities.paths — pin your installed crewai version and match imports to the snippet on this page.
When should I use db_storage_path()?
Ops scripts that need to manipulate persistent state.
When should I avoid db_storage_path()?
Within normal flow code — use higher-level memory APIs.
How do I call db_storage_path() from Python?
path = db_storage_path()
Where can I explore more CrewAI API reference pages?
Open the CrewAI API reference index on DevShelfHub to search classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.