Quick Start
Get Turso Credentials
- Install Turso CLI:
curl -sSfL https://get.tur.so/install.sh | bash - Create database:
turso db create mydb - Get credentials:
Installation
- pip
- Environment Variables
Connection Modes
Embedded Replica (Recommended)
Local SQLite file syncs with remote Turso server:Remote Only
Direct connection to Turso edge:Local Only
Pure local SQLite for development:Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
url | str | None | Turso database URL (libsql://...) |
auth_token | str | None | Turso authentication token |
local_path | str | "praisonai_turso.db" | Local SQLite replica file |
sync_on_write | bool | True | Sync to remote after writes |
auto_create_tables | bool | True | Create conversation tables |
Usage Patterns
Using Convenience Class
Multi-Region Setup
Full Lifecycle with Edge Performance
Turso-Specific Features
Manual Sync Control
Control when local replica syncs to remote:Database Scaling
Turso automatically scales to handle traffic:Global Replication
Create replicas in multiple regions:Best Practices
Optimize for Edge Performance
Optimize for Edge Performance
Use embedded replicas for fastest reads:
Handle Network Partitions
Handle Network Partitions
Embedded replicas continue working during network outages:
Monitor Replica Size
Monitor Replica Size
Local replicas grow with conversation history:
Use Multiple Databases
Use Multiple Databases
Separate different data types for optimal performance:
Environment Variables
| Variable | Required | Format | Example |
|---|---|---|---|
TURSO_DATABASE_URL | ✅ | libsql://db-user.turso.io | libsql://mydb-user.turso.io |
TURSO_AUTH_TOKEN | ✅ | JWT token | eyJhbGciOiJFZERTQS... |
OPENAI_API_KEY | ✅ | sk-... | sk-1234567890abcdef... |
Performance Comparison
| Operation | Turso Replica | Remote Only | Local Only |
|---|---|---|---|
| Read | < 5ms | 20-100ms | < 1ms |
| Write | 5-50ms | 20-150ms | < 1ms |
| Consistency | Eventually | Strong | None |
| Offline | ✅ | ❌ | ✅ |
Troubleshooting
Sync Failures
If replica sync fails:Token Expiration
Turso tokens can expire. Regenerate them:Replica File Permissions
Ensure local replica file is writable:Related
Cloud Databases Overview
Compare all cloud database providers
Local SQLite
Pure local SQLite for development

