Skip to main content

ThanoSQL SDK for Python

Project description

ThanoSQL Python Library

The ThanoSQL Python library provides convenient access to the ThanoSQL API from any Python 3.8+ application. The library covers all ThanoSQL operations that users can do, such as querying, editing tables, and much more.

Installation

Refer to the following instructions to install the ThanoSQL Python library from PyPI.

pip install thanosql

[!WARNING] Make sure to uninstall ThanoSQL Magic first.

pip uninstall thanosql-magic

In order to use the library with ThanoSQL Magic,

pip install 'thanosql[magic]'

Alternatively, you can also install from source. First, clone this repository.

git clone https://github.com/smartmind-team/thanosql-sdk-python.git
cd thanosql-sdk-python

Install the SDK by using pip install. Note that the Python version used during development is 3.8.10.

pip install -e .
pip install -e ."[dev]" # include unit test & docs (requires python >= 3.9)
pip install -e ."[magic]" # include magic

Usage

In order to use the library, a working workspace engine is required. Create a new Python or IPython notebook file. Import the thanosql package, create a ThanoSQL client with your API token and engine URL, and then you can use all the functions in the library. For more examples, head over to the examples directory.

  1. First, set up your API_TOKEN and ENGINE_URL (recommended). You can find them by accessing your workspace's settings page. Head over to the Developer tab, and then copy your API Token and Engine URL.

    export THANOSQL_API_TOKEN='your-api-token-here'
    export THANOSQL_ENGINE_URL='your-engine-url-here'
    
  2. Import the ThanoSQL client and use it to query your ThanoSQL Workspace.

    from thanosql import ThanoSQL
    
    client = ThanoSQL()
    # defaults to getting the token using os.environ.get("THANOSQL_API_TOKEN"),
    # and also defaults to getting the url using os.environ.get("THANOSQL_ENGINE_URL"),
    # client = ThanoSQL(
    #     api_token='your-api-token-here',
    #     engine_url='your-engine-url-here'
    # )
    
    res = client.query.execute(query="SELECT 1")
    print(res.model_dump_json(indent=4))
    
    tables = client.table.list(schema="public")
    
    # do something with the list of tables
    for table in tables:
       print(table.name)
    

Magic

thanosql-magic is a Jupyter Notebook extension that provides SQL query capabilities using ThanoSQL. This magic extension enables users to interact with ThanoSQL Workspace databases using extended SQL syntax within a Jupyter notebook.

thanosql-magic uses IPython magic. IPython magic is a special command that can be used in the IPython shell to perform specific tasks before executing the code. Since Jupyter includes the IPython shell, you can also use these magic commands in Jupyter Notebook.

IPython magic commands are prefixed with % or %% and % applies the magic to a single line of code, while %% applies the magic to multiple lines of code.

Installation

To install thanosql-magic, you can use pip:

pip install 'thanosql[magic]'

Once installed, you can load the extension in your Jupyter notebook by running:

%load_ext thanosql

Usage

After loading the extension, you can connect to your ThanoSQL Engine instance by setting the thanosql variable:

  1. Setting API_TOKEN

    %thanosql API_TOKEN=<Issued_API_TOKEN>
    
  2. Changing the Default API URI (Optional)

    %thanosql http://localhost:8000/api/v1/query
    
  3. Using Magic Commands

    You can then execute SQL queries on your Thanos data using the %thanosql magic command:

    %%thanosql
    SELECT * FROM users
    

    This will run the SQL query and display the results in your Jupyter notebook.

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

thanosql-1.0.10.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

thanosql-1.0.10-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file thanosql-1.0.10.tar.gz.

File metadata

  • Download URL: thanosql-1.0.10.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for thanosql-1.0.10.tar.gz
Algorithm Hash digest
SHA256 19fa20c4ce5f31d296d752b0b23bff04d181a8d59b95b9fe4c4e0df9f172b924
MD5 d08cc0a439091fc7b106a2b0f24129b7
BLAKE2b-256 62cd406e9f818b170c69eac52d8a6b4f3ee49c8c297b3ef37bb574db820b7244

See more details on using hashes here.

File details

Details for the file thanosql-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: thanosql-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for thanosql-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 88f495fbfcfb16fd5a1953c98894cbef076a18aad2c0e29d2e82a4a433da67a9
MD5 1a3d7f1850244e9384e08e6b3725215a
BLAKE2b-256 e245ab8b69b1f7409d672bf0e2f4fbd38d6a534477bd15ef0e235a925a1bfcf8

See more details on using hashes here.

Supported by

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