Casper Python client
Python client library for the Casper Vector Database.
Installation
pip install casper-client
Quick start
import math
import os
import random
import time
from casper_client import CasperClient, VectorPoint
def gen_vec(dim: int) -> list[float]:
vec = [random.uniform(-1.0, 1.0) for _ in range(dim)]
norm = math.sqrt(sum(x * x for x in vec)) or 1.0
return [x / norm for x in vec]
def main() -> None:
host = os.getenv("CASPER_HOST", "http://127.0.0.1")
http_port = int(os.getenv("CASPER_HTTP_PORT", "7222"))
with CasperClient(host=host, http_port=http_port) as client:
client.health()
collection = "example_collection"
dim = 128
client.create_collection(collection, dim=dim, max_size=10_000)
# Upsert vectors (batch)
points = [VectorPoint(id=vid, vector=gen_vec(dim)) for vid in range(1, 6)]
client.upsert_vectors(collection, points)
# Mixed insert + delete
batch = [VectorPoint(id=vid, vector=gen_vec(dim)) for vid in range(6, 11)]
client.batch_update(collection, insert=batch, delete=[])
# Create HNSW index — build is asynchronous on the server.
client.create_hnsw_index(
collection,
metric="inner-product",
quantization="i8",
m=16,
m0=32,
ef_construction=200,
normalization=True,
)
# Wait until the index is ready before searching.
while not client.get_collection(collection).has_index:
time.sleep(0.2)
hits = client.search(collection, query=gen_vec(dim), limit=10)
for i, h in enumerate(hits[:5], start=1):
print(f" {i}. id={h.id} score={h.score}")
client.delete_vectors(collection, [10])
client.delete_index(collection)
client.delete_collection(collection)
if __name__ == "__main__":
main()
Examples
Run the example provided in this repository:
python examples/example.py
The example demonstrates:
- Collection management (create, delete, list, info)
- Vector operations:
upsert_vectors(batch PUT),delete_vectors(batch by id),batch_update(mixed insert+delete),get_vector - Mute / unmute (
mute_collection,unmute_collection) - Index management (
create_hnsw_index,delete_index) — the index build is asynchronous; the server returns 202 and the client should pollget_collection().has_index - Search (
search, with optionalef_searchoverride). Binary response format is decoded automatically.
License
Licensed under the Apache License Version 2.0.
Metadata
Release files for casper-client 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| casper_client-0.1.2.tar.gz | 12.7 kB | Without provenance | Details for casper_client-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| casper_client-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for casper_client-0.1.2-py3-none-any.whl |
Total release size: 26.6 kB
Release files / casper_client-0.1.2.tar.gz
| Download URL | casper_client-0.1.2.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89581047a48cd130e9c6416eb6f9963bf42b35094cafae6332c051f414dddef7
|
|
BLAKE2b-256 checksum How to use checksums |
a13d755c22ac6e73feaeb28eee54003e3f2d29f8ad836762e4769f7de5e38e8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.12.7 Linux/6.17.0-35-generic
|
Release files / casper_client-0.1.2-py3-none-any.whl
| Download URL | casper_client-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf385969be078d1bd543df6283c2a59ef7ec17484c4f35366e9f3f6857c2ecfa
|
|
BLAKE2b-256 checksum How to use checksums |
7fccaa1e4a9fe74893b0a6e7cda95ebf43b3fc421ada0b7eeca253a4b0f47745
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.12.7 Linux/6.17.0-35-generic
|
Security for casper-client 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.