Skip to main content
In this Python quickstart we will learn how to:
  • Install the Turso package
  • Connect to a local or remote database
  • Execute a query using SQL
  • Sync changes to local database
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

Or with pip:
2

Connect

In-memory databases are also supported:
3

Execute

4

Sync (push and pull)

If you need to sync your local database with Turso Cloud, use turso.sync:
All reads and writes happen against the local database file — fast, offline-capable. 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), you can use the libsql package. It connects to your database via HTTP — no local file needed.
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).
1

Retrieve database credentials

You will need an existing 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

Or with pip:
3

Connect and query

Embedded Replicas (libsql)

The libsql 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.