Python 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 create_client_sync(). It supports the same methods as the default asyncio client, except that they block the calling thread:
import libsql_client
url = "file:local.db"
with libsql_client.create_client_sync(url) as client:
result_set = client.execute("SELECT * from users")
print(len(result_set.rows), "rows")
for row in result_set.rows:
print(row)
The synchronous client is just a thin wrapper around the asynchronous client, but it runs the event loop in a background thread.
Contributing to this package
First, please install Python and Poetry. To install all dependencies for local development to a virtual environment, run:
poetry install --with dev
To run the tests, use:
poetry run pytest
To check types with MyPy, use:
poetry run mypy
License
This project is licensed under the MIT license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in libsql-client by you, shall be licensed as MIT, without any additional terms or conditions.
Metadata
Release files for libsql-client 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| libsql_client-0.3.1.tar.gz | 39.6 kB | Without provenance | Details for libsql_client-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| libsql_client-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for libsql_client-0.3.1-py3-none-any.whl |
Total release size: 85.7 kB
Release files / libsql_client-0.3.1.tar.gz
| Download URL | libsql_client-0.3.1.tar.gz |
|---|---|
| Size | 39.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1815893bf5271f1940919b2a583ebbafb0ec54028e9d01e4eda151a6e85a8618
|
|
BLAKE2b-256 checksum How to use checksums |
d2768968356d45ee174ebe966ff0112bed1bd932851d6532737c2ee8b40ed6e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0
|
Release files / libsql_client-0.3.1-py3-none-any.whl
| Download URL | libsql_client-0.3.1-py3-none-any.whl |
|---|---|
| Size | 46.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
088756f65802f5ca5857a99cf374d9b7aa015b97b91b0cb725ef6a033e23268b
|
|
BLAKE2b-256 checksum How to use checksums |
83f0b0d7c7331f975bcc3effd01abb094723891fd42bca7f702b4a0cf06c1bff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0
|
Security for libsql-client 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.