![](https://github.com/turbopuffer/turbopuffer-python/assets/1594638/0482aa50-4665-4998-afd3-78afe56b52f3) turbopuffer Python Client [![CI Test](https://github.com/turbopuffer/turbopuffer-python/actions/workflows/ci_test.yml/badge.svg)](https://github.com/turbopuffer/turbopuffer-python/actions/workflows/ci_test.yml)
=========================
The official Python client for accessing the turbopuffer API.
Usage
-----
1. Install the turbopuffer package and set your API key.
```sh
$ pip install turbopuffer
```
Or if you're able to run C binaries for JSON encoding, use:
```sh
$ pip install turbopuffer[fast]
```
2. Start using the API
```py
import turbopuffer as tpuf
tpuf.api_key = 'your-token' # Alternatively: export=TURBOPUFFER_API_KEY=your-token
# Choose the best region for your data https://turbopuffer.com/docs/regions
tpuf.api_base_url = "https://gcp-us-east4.turbopuffer.com"
# 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
## Development
Run `poetry install --with=test` to set up the project and dependencies.
1. `poetry run pytest`
2. Bump version in `turbopuffer/version.py` and `pyproject.toml`
3. `git tag vX.Y.Z && git push --tags`
3. `poetry build`
4. `poetry publish`
Raw data
{
"_id": null,
"home_page": "https://turbopuffer.com",
"name": "turbopuffer",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "turbopuffer, vector, database, cloud",
"author": "turbopuffer Inc.",
"author_email": "info@turbopuffer.com",
"download_url": "https://files.pythonhosted.org/packages/e4/2b/85b0b0ed3cea98d31cbca5b9afd07bbf518fe996779020053d71c971bf73/turbopuffer-0.1.25.tar.gz",
"platform": null,
"description": "![](https://github.com/turbopuffer/turbopuffer-python/assets/1594638/0482aa50-4665-4998-afd3-78afe56b52f3) turbopuffer Python Client [![CI Test](https://github.com/turbopuffer/turbopuffer-python/actions/workflows/ci_test.yml/badge.svg)](https://github.com/turbopuffer/turbopuffer-python/actions/workflows/ci_test.yml)\n=========================\n\nThe official Python client for accessing the turbopuffer API.\n\nUsage\n-----\n\n1. Install the turbopuffer package and set your API key.\n```sh\n$ pip install turbopuffer\n```\nOr if you're able to run C binaries for JSON encoding, use:\n```sh\n$ pip install turbopuffer[fast]\n```\n\n2. Start using the API\n```py\nimport turbopuffer as tpuf\ntpuf.api_key = 'your-token' # Alternatively: export=TURBOPUFFER_API_KEY=your-token\n# Choose the best region for your data https://turbopuffer.com/docs/regions\ntpuf.api_base_url = \"https://gcp-us-east4.turbopuffer.com\"\n\n# Open a namespace\nns = tpuf.Namespace('hello_world')\n\n# Read namespace metadata\nif ns.exists():\n print(f'Namespace {ns.name} exists with {ns.dimensions()} dimensions and approximately {ns.approx_count()} vectors.')\n\n# Upsert your dataset\nns.upsert(\n ids=[1, 2],\n vectors=[[0.1, 0.2], [0.3, 0.4]],\n attributes={'name': ['foo', 'foos']},\n distance_metric='cosine_distance',\n)\n\n# Alternatively, upsert using a row iterator\nns.upsert(\n {\n 'id': id,\n 'vector': [id/10, id/10],\n 'attributes': {'name': 'food', 'num': 8}\n } for id in range(3, 10),\n distance_metric='cosine_distance',\n)\n\n# Query your dataset\nvectors = ns.query(\n vector=[0.15, 0.22],\n distance_metric='cosine_distance',\n top_k=10,\n filters=['And', [\n ['name', 'Glob', 'foo*'],\n ['name', 'NotEq', 'food'],\n ]],\n include_attributes=['name'],\n include_vectors=True\n)\nprint(vectors)\n# [\n# VectorRow(id=2, vector=[0.30000001192092896, 0.4000000059604645], attributes={'name': 'foos'}, dist=0.001016080379486084),\n# VectorRow(id=1, vector=[0.10000000149011612, 0.20000000298023224], attributes={'name': 'foo'}, dist=0.009067952632904053)\n# ]\n\n# List all namespaces\nnamespaces = tpuf.namespaces()\nprint('Total namespaces:', len(namespaces))\nfor namespace in namespaces:\n print('Namespace', namespace.name, 'contains approximately', namespace.approx_count(),\n 'vectors with', namespace.dimensions(), 'dimensions.')\n\n# Delete vectors using the separate delete method\nns.delete([1, 2])\n```\n\nEndpoint Documentation\n----------------------\n\nFor more details on request parameters and query options, check the docs at https://turbopuffer.com/docs\n\n## Development\n\nRun `poetry install --with=test` to set up the project and dependencies.\n\n1. `poetry run pytest`\n2. Bump version in `turbopuffer/version.py` and `pyproject.toml`\n3. `git tag vX.Y.Z && git push --tags`\n3. `poetry build`\n4. `poetry publish`\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python Client for accessing the turbopuffer API",
"version": "0.1.25",
"project_urls": {
"Documentation": "https://turbopuffer.com/docs",
"Homepage": "https://turbopuffer.com",
"Repository": "https://github.com/turbopuffer/turbopuffer-python"
},
"split_keywords": [
"turbopuffer",
" vector",
" database",
" cloud"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "18789589df5fb775cd6daa4019567dbf7fac0c7f13d883dedec2e3a7d9679650",
"md5": "a335b0b7c4941c8797316d5efdbca916",
"sha256": "1aa31bb50413bd882f215e31736ab805dc5c598959c2de0c82d101c247d5bccf"
},
"downloads": -1,
"filename": "turbopuffer-0.1.25-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a335b0b7c4941c8797316d5efdbca916",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 16299,
"upload_time": "2024-12-17T23:47:19",
"upload_time_iso_8601": "2024-12-17T23:47:19.215771Z",
"url": "https://files.pythonhosted.org/packages/18/78/9589df5fb775cd6daa4019567dbf7fac0c7f13d883dedec2e3a7d9679650/turbopuffer-0.1.25-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e42b85b0b0ed3cea98d31cbca5b9afd07bbf518fe996779020053d71c971bf73",
"md5": "ba6c188a020067b756ff7ea47e0e6a14",
"sha256": "8dd1626194ba853045e9154d7fbfea53b9476896601d0de2bc5b4927c5e4929f"
},
"downloads": -1,
"filename": "turbopuffer-0.1.25.tar.gz",
"has_sig": false,
"md5_digest": "ba6c188a020067b756ff7ea47e0e6a14",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 14876,
"upload_time": "2024-12-17T23:47:21",
"upload_time_iso_8601": "2024-12-17T23:47:21.434711Z",
"url": "https://files.pythonhosted.org/packages/e4/2b/85b0b0ed3cea98d31cbca5b9afd07bbf518fe996779020053d71c971bf73/turbopuffer-0.1.25.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-17 23:47:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "turbopuffer",
"github_project": "turbopuffer-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "turbopuffer"
}