You can work with embedded replicas that can sync from the remote database to a local SQLite file, and delegate writes to the remote primary database:
Copy
import osimport libsqlconn = libsql.connect("local.db", sync_url=os.getenv("LIBSQL_URL"), auth_token=os.getenv("LIBSQL_AUTH_TOKEN"))conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER);")conn.execute("INSERT INTO users(id) VALUES (1);")conn.commit()print(conn.execute("select * from users").fetchall())
Embedded Replicas only works where you have access to the file system.
You can automatically sync at intervals by passing time in seconds to the sync_interval option. For example, to sync every minute, you can use the following code:
Encrypted databases appear as raw data and cannot be read as standard SQLite databases. You must use the libSQL client for any operations — learn more.