Python Client for accessing the turbopuffer API
Project description
turbopuffer Python Client ![CI Test](https://pypi-camo.freetls.fastly.net/4abc47883af3f8b630f76a21f00e2be94ebb2842/68747470733a2f2f6769746875622e636f6d2f747572626f7075666665722f747572626f7075666665722d707974686f6e2f616374696f6e732f776f726b666c6f77732f63695f746573742e796d6c2f62616467652e737667)
The official Python client for accessing the turbopuffer API.
Usage
- Install the turbopuffer package and set your API key.
$ pip install turbopuffer
Or if you're able to run C binaries for JSON encoding, use:
$ pip install turbopuffer[fast]
- Start using the API
import turbopuffer as tpuf
tpuf.api_key = 'your-token' # Alternatively: export=TURBOPUFFER_API_KEY=your-token
# Open a namespace
ns = tpuf.Namespace('hello_world')
# Read namespace metadata
if ns.exists():
print(f'Namespace {ns.name} exists with {ns.dimensions()} dimensions and approximately {ns.approx_count()} vectors.')
# Upsert your dataset
ns.upsert(
ids=[1, 2],
vectors=[[0.1, 0.2], [0.3, 0.4]],
attributes={'name': ['foo', 'foos']},
distance_metric='cosine_distance',
)
# Alternatively, upsert using a row iterator
ns.upsert(
{
'id': id,
'vector': [id/10, id/10],
'attributes': {'name': 'food', 'num': 8}
} for id in range(3, 10),
distance_metric='cosine_distance',
)
# Query your dataset
vectors = ns.query(
vector=[0.15, 0.22],
distance_metric='cosine_distance',
top_k=10,
filters=['And', [
['name', 'Glob', 'foo*'],
['name', 'NotEq', 'food'],
]],
include_attributes=['name'],
include_vectors=True
)
print(vectors)
# [
# VectorRow(id=2, vector=[0.30000001192092896, 0.4000000059604645], attributes={'name': 'foos'}, dist=0.001016080379486084),
# VectorRow(id=1, vector=[0.10000000149011612, 0.20000000298023224], attributes={'name': 'foo'}, dist=0.009067952632904053)
# ]
# List all namespaces
namespaces = tpuf.namespaces()
print('Total namespaces:', len(namespaces))
for namespace in namespaces:
print('Namespace', namespace.name, 'contains approximately', namespace.approx_count(),
'vectors with', namespace.dimensions(), 'dimensions.')
# Delete vectors using the separate delete method
ns.delete([1, 2])
Endpoint Documentation
For more details on request parameters and query options, check the docs at https://turbopuffer.com/docs
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
turbopuffer-0.1.17.tar.gz
(13.5 kB
view hashes)
Built Distribution
Close
Hashes for turbopuffer-0.1.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12e0bc9d1ddf0aaca81437534331411556811f75c1bea41769060886f4e01e98 |
|
MD5 | 308458352b1192551884c636e0670d2e |
|
BLAKE2b-256 | 8acf136af460c296b91eaf910b426307db73aa45acd6d1c00d4b1cc4e2bc9a28 |