Skip to main content

The Official Python SDK for the Lithio API

Project description

Lithio Python SDK

A Python SDK for the Lithio API, designed with an OpenAI/xAI/Anthropic-style interface.

Installation

pip install -e .

Or install from a directory:

cd /path/to/sdk
pip install .

Usage

Basic Usage

from lithio import Client

# Initialize the client
client = Client(
    api_key="your-api-key",
    base_url="https://api.example.com"
)

# Add a query
response = client.add(
    query="This is an example query",
    space="my-space",
    properties={"custom": "property"}
)
print(response.request)  # "processing"

# Search
results = client.search(
    query="search query",
    limit=10,
    match_threshold=0.5,
    rerank_alpha=0.3,
    space="my-space"
)
print(results.results)

Using Client Properties

You can set default properties on the client that will be included in all requests:

client = Client(
    api_key="your-api-key",
    base_url="https://api.example.com",
    properties={
        "environment": "production",
        "version": "1.0"
    }
)

# These properties will be automatically included
client.add(query="test query")
client.search(query="test search")

# You can override or add more properties per request
client.add(
    query="test query",
    properties={"additional": "property"}
)

Context Manager

The client can be used as a context manager to ensure proper cleanup:

with Client(api_key="your-api-key", base_url="https://api.example.com") as client:
    response = client.add(query="example")
    results = client.search(query="example")

Manual Cleanup

client = Client(api_key="your-api-key", base_url="https://api.example.com")
try:
    response = client.add(query="example")
finally:
    client.close()

API Reference

Client

Client.__init__(api_key, base_url="http://localhost:8000", properties=None, timeout=30.0)

Initialize the Lithio client.

Parameters:

  • api_key (str): Your Lithio API key
  • base_url (str): Base URL for the API (default: http://localhost:8000)
  • properties (dict, optional): Default properties to include in all requests
  • timeout (float): Request timeout in seconds (default: 30.0)

Client.add(query, space=None, properties=None) -> AddResponse

Add a query to the system.

Parameters:

  • query (str): The query string to add
  • space (str, optional): Optional space identifier
  • properties (dict, optional): Optional properties (merged with client defaults)

Returns:

  • AddResponse: Response containing the request status

Client.search(query, limit=None, match_threshold=None, rerank_alpha=None, space=None, properties=None) -> SearchResponse

Search for results.

Parameters:

  • query (str): The search query string
  • limit (int, optional): Maximum number of results (default: 5)
  • match_threshold (float, optional): Minimum match threshold (default: 0.4)
  • rerank_alpha (float, optional): Reranking alpha parameter (default: 0.2)
  • space (str, optional): Optional space identifier
  • properties (dict, optional): Optional properties (merged with client defaults)

Returns:

  • SearchResponse: Response containing the search results

Error Handling

The SDK raises httpx.HTTPError for HTTP errors. You can handle them like this:

import httpx
from lithio import Client

client = Client(api_key="your-api-key", base_url="https://api.example.com")

try:
    response = client.add(query="example")
except httpx.HTTPStatusError as e:
    if e.response.status_code == 401:
        print("Invalid API key")
    else:
        print(f"HTTP error: {e}")
except httpx.RequestError as e:
    print(f"Request error: {e}")

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

lithio_sdk-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

lithio_sdk-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file lithio_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: lithio_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for lithio_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30b1ecc7ad7dbf5370efc1384882f1c5918c8004429aefc88a075fd788703917
MD5 e7a80da76dc7dfb9fb6828a40c6ed922
BLAKE2b-256 27a13cac1fbf94c4da3e4d215f09b1a503885a5ced4af68e29637f9f44743e46

See more details on using hashes here.

File details

Details for the file lithio_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lithio_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for lithio_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f5a965c0552fb6af6283134e446d7dbd128f2e7a1d466ca4cb6ba39a2d11ed6
MD5 8d24ed6d54292182fe1a03b85f65ba4d
BLAKE2b-256 5bf1c51b82cc0a70bc3370c1b5e10f583df82ab8d788831e954af73192bdc14e

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