Skip to main content

Python SDK for libSQL

Project description

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).

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 builtin sqlite3 package)
    • file:/absolute/path or file:///absolute/path is an absolute path on local filesystem
    • file:relative/path is a relative path on local filesystem
    • (file://path is not a valid URL)
  • ws: or wss: connect to sqld using WebSockets (the Hrana protocol).
  • http: or https: connect to sqld using HTTP. The transaction() API is not available in this case.
  • libsql: is equivalent to wss:.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libsql-client-0.2.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libsql_client-0.2.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file libsql-client-0.2.2.tar.gz.

File metadata

  • Download URL: libsql-client-0.2.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-70-generic

File hashes

Hashes for libsql-client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8b5b4da6051eabc7e98694832de6cbba16c7734b9f1a7c907dada7c17f1dd250
MD5 5abacc885c5053dd6eed14074ec8ffb9
BLAKE2b-256 4110cdf7a97359180089e909d135def913a3f4af564ac40a0050938b2c98dc9c

See more details on using hashes here.

File details

Details for the file libsql_client-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: libsql_client-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-70-generic

File hashes

Hashes for libsql_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94589a69c7c4fbd96ca1f52515b9f02b9d3360f87154fec25e96a309f29ed08b
MD5 0db310cbb8e83d9e364ecd12f7c9be18
BLAKE2b-256 98bac9a0737b1b6da033da5bb228ae8eb45d588afe2223a94369525113ddd1f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page