Skip to main content

Python Client for accessing the turbopuffer API

Project description

turbopuffer Python Client CI Test

The official Python client for accessing the turbopuffer API.

Usage

  1. 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]
  1. 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

This version

0.1.9

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.9.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

turbopuffer-0.1.9-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file turbopuffer-0.1.9.tar.gz.

File metadata

  • Download URL: turbopuffer-0.1.9.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.6 Darwin/23.2.0

File hashes

Hashes for turbopuffer-0.1.9.tar.gz
Algorithm Hash digest
SHA256 a200809ff51715a2a7abb96900400882b610f453c1b43af0a13960e8a66b4172
MD5 f14b26a779a0a887506f91ebceea824c
BLAKE2b-256 f932e2df2d8dca2a7faecb38b6eb5f875a887b5f7e9262d164607145e34ca2d3

See more details on using hashes here.

File details

Details for the file turbopuffer-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: turbopuffer-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.6 Darwin/23.2.0

File hashes

Hashes for turbopuffer-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 4898ae735d2f0c2ad179af0a17ed1a29c54cd4ba3b2325d8b20942605e03d84c
MD5 56e87e1dcf99c69ecc20cf379e759063
BLAKE2b-256 1a328100c554a35799ad96f826c00ebaf678b2ddaf80458a448532ae4b52c7de

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