cairn-db-client
Python client for Cairn, the hybrid search database
where a deletion is final. It comes in two flavours, sync (Client) and async
(AsyncClient), and is typed. Its only dependency is httpx.
pip install cairn-db-client
from cairn_db import Client, eq, range_, and_
db = Client("http://localhost:7200", api_key=KEY)
# Your own ids; chunks carry their parent in an ordinary field ("parent" by default).
db.upsert([
{"id": "report-9#0", "parent": "report-9", "text": "...", "embedding": [...], "lang": "en"},
{"id": "report-9#1", "parent": "report-9", "text": "...", "embedding": [...], "lang": "en"},
])
hits = db.search(
k=10,
vector={"field": "embedding", "values": query_vector},
text="nuclear energy", text_field="text",
filter=and_(eq("lang", "en"), range_("year", gte=2020)),
)
for h in hits:
print(h.id, h.score, h.document["text"])
db.delete(parent="report-9") # the document and all its chunks
db.delete(filter=eq("source", "crawler")) # everything that matches, now
db.delete(ids=["report-7#0"])
AsyncClient has the same methods, as coroutines (async with AsyncClient(...) as db:).
Read-your-writes and takedowns
The client keeps the consistency token of its writes and takedowns, and sends it with every
read. It therefore reads what it wrote, and never reads back what it deleted, through any
node. To give the same guarantee to another service, pass it db.token:
Client(..., token=token), or db.observe(token) on an existing client.
Collections
Without collection(), calls act on default, the collection defined at startup.
admin = Client(url, api_key=ADMIN_KEY)
admin.create_collection("notes", {"fields": [
{"name": "embedding", "kind": {"Vector": {"dims": 384, "metric": "Cosine"}}},
{"name": "body", "kind": "Text"},
]}, shards=4)
notes = db.collection("notes") # the same calls, on "notes"
notes.upsert([{"id": "n1", "embedding": [...], "body": "..."}])
admin.drop_collection("notes") # deletes its data on every node
create_collection and drop_collection need an admin key. list_collections needs a read key.
Tenants
acme = db.with_tenant("acme") # an unscoped key acting for tenant "acme"
acme.upsert([{"id": "note-1", "text": "...", "embedding": [...]}])
db.forget_tenant("acme") # erase everything of "acme"
A key scoped to a tenant (cairn-server keygen app read,write --tenant acme) needs nothing
else: every call stays inside its tenant. Ids belong to their tenant.
Errors and retries
InvalidInputError(400),AuthenticationError(401),ForbiddenError(403),UnavailableError(503 or network), all subclasses ofCairnErrorwith astatus.getreturnsNonefor a missing document.- 502, 503, 504 and network errors are retried (
retries=3by default) with backoff, on the next address whenurlis a list.
Tests
PYTHONPATH=src python -m pytest tests runs the unit tests. ../test-live.sh also runs the
live tests against a fresh local node.
Metadata
Release files for cairn-db-client 0.3.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 | |
|---|---|---|---|
| cairn_db_client-0.3.2.tar.gz | 11.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cairn_db_client-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.3 kB
Release files / cairn_db_client-0.3.2.tar.gz
| Download URL | cairn_db_client-0.3.2.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f2ee78d0dc2599ca889660d317268a22c02c1e2e0ab8d1f158239a8c05b17ac
|
|
BLAKE2b-256 checksum How to use checksums |
2d23b5f66d32f3b4a5911cc64bcb12232b32d6f1d37bf31ae2ee678d7c66a43e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / cairn_db_client-0.3.2-py3-none-any.whl
| Download URL | cairn_db_client-0.3.2-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fe8c9593f7c8fe98c493e46e527ec2b4d850fa0b849a0f79367054479476dce
|
|
BLAKE2b-256 checksum How to use checksums |
1d02196c1dfa2506a3ce99c7f5584f8980f37bc61e74b02816ddf67d344b26fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency log