# Connect to Turso using Python

> Connect to Turso using Python — Turso documentation.
> Canonical HTML: https://tursodb.cn/docs/connect/python/
> Upstream Source (MIT): https://docs.turso.tech/connect/python
> Language: en

---
**1. Install**

Add the Turso package to your Python project:

```bash
uv pip install pyturso
```

**2. Connect**

Here's how you can connect to a local SQLite database:

```python
import turso

con = turso.connect("sqlite.db")
cur = con.cursor()
```

**3. Create table**

Create a table for users:

```python
cur.execute("""
  CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL
  )
""")
con.commit()
```

**4. Insert data**

Insert some data into the users table:

```python
cur.execute("INSERT INTO users (username) VALUES (?)", ("alice",))
cur.execute("INSERT INTO users (username) VALUES (?)", ("bob",))
con.commit()
```

**5. Query data**

Query all users from the table:

```python
res = cur.execute("SELECT * FROM users")
users = res.fetchall()
print(users)
```
