Python SDK for libSQL
Archived. The repository is read-only: no more fixes or releases will come.
pip install libsql-clientPython SDK for libSQL
API reference | Github | PyPI
This is the source repository of the Python SDK for libSQL. You can either connect to a local SQLite database or to a remote libSQL server (sqld).
NOTE: If you want to use libSQL with SQLAlchemy, you should check out the libSQL dialect.
Installation
pip install libsql-client
Getting Started
Connecting to a local SQLite database:
import asyncio
import libsql_client
async def main():
url = "file:local.db"
async with libsql_client.create_client(url) as client:
result_set = await client.execute("SELECT * from users")
print(len(result_set.rows), "rows")
for row in result_set.rows:
print(row)
asyncio.run(main())
To connect to a remote libSQL server (sqld), just change the URL:
url = "ws://localhost:8080"
Supported URLs
The client can connect to the database using different methods depending on the scheme (protocol) of the passed URL:
file:connects to a local SQLite database (using the builtinsqlite3package)file:/absolute/pathorfile:///absolute/pathis an absolute path on local filesystemfile:relative/pathis a relative path on local filesystem- (
file://pathis not a valid URL)
ws:orwss:connect to sqld using WebSockets (the Hrana protocol).http:orhttps:connect to sqld using HTTP. Thetransaction()API is not available in this case.libsql:is equivalent towss:.
Synchronous API
This package also provides a synchronous version of the client, which can be created by calling . It supports the same methods as the default client, except that they block the calling thread: