Skip to content

Commit 4d977f0

Browse files
committed
Update docs and add example of using a remote database
1 parent 0769ff3 commit 4d977f0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ con = libsql.connect("hello.db")
4949
cur = con.cursor()
5050
```
5151

52+
#### Remote database
53+
54+
```python
55+
import libsql_experimental as libsql
56+
57+
url = os.getenv("LIBSQL_URL")
58+
auth_token = os.getenv("LIBSQL_AUTH_TOKEN")
59+
60+
con = libsql.connect(database=url, auth_token=auth_token)
61+
cur = con.cursor()
62+
```
63+
5264
#### Embedded replica
5365

5466
```python

examples/remote_connect.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
A short example showing how to connect to a remote libsql or Turso database
3+
4+
Set the LIBSQL_URL and LIBSQL_AUTH_TOKEN environment variables to point to a database.
5+
"""
6+
import os
7+
8+
import libsql_experimental as libsql
9+
10+
print(F"connecting to {os.getenv('LIBSQL_URL')}")
11+
conn = libsql.connect(database=os.getenv('LIBSQL_URL'),
12+
auth_token=os.getenv("LIBSQL_AUTH_TOKEN"))
13+
conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER);")
14+
conn.execute("INSERT INTO users(id) VALUES (10);")
15+
conn.commit()
16+
17+
print(conn.execute("select * from users").fetchall())

0 commit comments

Comments
 (0)