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 keybase_url(str): Base URL for the API (default:http://localhost:8000)properties(dict, optional): Default properties to include in all requeststimeout(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 addspace(str, optional): Optional space identifierproperties(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 stringlimit(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 identifierproperties(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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lithio_sdk-0.1.1.tar.gz.
File metadata
- Download URL: lithio_sdk-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32d9d747b3243c2054edcc732dd97356328d9583c52d9e574edb64c6ad06926a
|
|
| MD5 |
1d067b42ae346236590cd737a656ab22
|
|
| BLAKE2b-256 |
cbb0806609ab4ff1f35713bfd585e44c4829cef239b4a3aec346b1c45f62e41b
|
File details
Details for the file lithio_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lithio_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7575301c13ce820d78e0d3a44dabeb48e0dd130043ffe990c87f25811627c493
|
|
| MD5 |
ee14574eb9eb6faeb622dca6e68785ba
|
|
| BLAKE2b-256 |
567b16ce33b86e4e251f8a70d6dd22851e38fa75b9c909225cc082070fd3f282
|