Python
Turso Quickstart (Python)
Get started with Turso and Python using the libSQL client in a few simple steps.
In this Python quickstart we will learn how to:
- Retrieve database credentials
- Install the libSQL package
- Connect to a Turso database
- Execute a query using SQL
- Sync changes to local database (optional)
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
First begin by adding libSQL to your project:
3
Connect
Then import the package:
Now connect to your local or remote database using the libSQL connector:
4
Execute
You can execute SQL queries against your existing database as follows:
5
Sync (Embedded Replicas only)
When using embedded replicas you should call sync()
on the connector to sync your local database with the primary database.