- Install the Turso package
- Connect to a local or remote database
- Execute a query using SQL
- Sync changes to local database
Recommended: pyturso (Local / Embedded)
pyturso is the recommended package for local and embedded use cases. It is built on the Turso Database engine — a ground-up rewrite of SQLite with concurrent writes (MVCC) and async I/O. The API follows the standard Python sqlite3 interface, so it works as a drop-in replacement.
1
Install
2
Connect
3
Execute
4
Sync (push and pull)
If you need to sync your local database with Turso Cloud, use All reads and writes happen against the local database file — fast, offline-capable.
turso.sync:push() sends your changes to the cloud. pull() brings remote changes down. See Turso Sync for details on conflict resolution, checkpointing, and more.Remote Access (Over-the-Wire)
If your application needs to query a Turso Cloud database directly over the network (e.g., from a web server or serverless function), use the driver that matches your database engine:turso_serverless for Turso databases, or libsql for libSQL databases.
For most applications, we recommend running a local database with Turso Sync (
turso.sync) instead — it gives you faster reads, offline support, and lower latency. Remote access is useful when you cannot store a local database file (e.g., stateless serverless environments).Remote Turso database: turso_serverless
turso_serverless connects to a remote Turso database over HTTP — no persistent connections, no native extensions, just the standard library. Like pyturso, it implements the standard DB-API interface.
1
Retrieve database credentials
You will need an existing Turso database to continue. If you don’t have one, create one with Get the database authentication token:Assign credentials to the environment variables inside
turso db create --tursodb (see the quickstart).Get the database URL:.env.You will want to store these as environment variables.
2
Install
3
Connect and query
Remote libSQL database: libsql
libsql connects to a remote libSQL database via HTTP — no local file needed.
1
Retrieve database credentials
You will need an existing libSQL database to continue. If you don’t have one, create one.Get the database URL:Get the database authentication token:Assign credentials to the environment variables inside
.env.You will want to store these as environment variables.
2
Install
3
Connect and query
Embedded Replicas (libsql)
Thelibsql package also supports Embedded Replicas — local reads from a file, with writes sent to the cloud primary and reflected back to the replica. Embedded Replicas are fully supported in production. For new projects that need sync, we recommend turso.sync instead: both reads and writes are local, and you sync explicitly with push() / pull().
See the reference for full documentation on Embedded Replicas, encryption, and periodic sync.