Skip to main content

Python client for Crux Daemon

Project description

CoreCrux Python Client

Python client for the Crux Daemon HTTP API.

Provides both synchronous and asynchronous interfaces using httpx.

Installation

pip install corecrux-client

Or install from source:

cd sdks/python
pip install -e .

Quick start (sync)

from corecrux_client import CoreCruxClient, StoreFact

with CoreCruxClient("http://localhost:14800", token="my-token") as client:
    # Health check
    print(client.healthz())

    # Store a fact
    fact = client.store_fact(StoreFact(
        entity="user::alice",
        key="preferred_language",
        value="Python",
    ))
    print(fact.fact_id, fact.version)

    # Query facts
    result = client.query_facts("Python", top_k=5)
    for f in result.facts:
        print(f.entity, f.key, f.value)

    # Text search
    hits = client.text_search("my-tenant", "deployment guide")
    for h in hits.results:
        print(h.doc_id, h.score)

Quick start (async)

import asyncio
from corecrux_client import AsyncCoreCruxClient, StoreFact

async def main():
    async with AsyncCoreCruxClient("http://localhost:14800", token="my-token") as client:
        fact = await client.store_fact(StoreFact(
            entity="user::alice",
            key="preferred_language",
            value="Python",
        ))
        print(fact.fact_id)

asyncio.run(main())

Authentication

Pass a bearer token when constructing the client:

client = CoreCruxClient(token="my-bearer-token")

The token is sent as Authorization: Bearer <token> on every request.

Error handling

All non-2xx responses raise CoreCruxError:

from corecrux_client import CoreCruxClient, CoreCruxError

with CoreCruxClient() as client:
    try:
        client.get_fact("nonexistent-id")
    except CoreCruxError as e:
        print(e.status_code)  # 404
        print(e.detail)       # "fact 'nonexistent-id' not found"

Methods that naturally return "not found" (get_fact, get_session, delete_fact) return None or False instead of raising on 404.

API coverage

Endpoint Sync Async
GET /healthz healthz() healthz()
GET /readyz readyz() readyz()
GET /v1/version version() version()
PUT /v1/facts store_fact() store_fact()
PUT /v1/facts/bulk store_facts() store_facts()
GET /v1/facts/{id} get_fact() get_fact()
DELETE /v1/facts/{id} delete_fact() delete_fact()
GET /v1/facts/entity/{e} get_facts_by_entity() get_facts_by_entity()
GET /v1/facts query_facts() query_facts()
GET /v1/facts/export export_facts() export_facts()
PUT /v1/sessions/{id}/state put_session() put_session()
GET /v1/sessions/{id}/state get_session() get_session()
POST /v1/query/text-search text_search() text_search()
POST /v1/query/text-search/expand text_search_expand() text_search_expand()
POST /v1/query/graph-expand graph_expand() graph_expand()
POST /v1/query/time-range time_range() time_range()

Requirements

  • Python 3.10+
  • httpx >= 0.27

Licence

CueCrux Community Licence (CCL v1.0). See LICENCE.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

corecrux_client-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

corecrux_client-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file corecrux_client-0.1.0.tar.gz.

File metadata

  • Download URL: corecrux_client-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for corecrux_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9994a3673ac9edb983cb5cdbda242ecf756f787e292e0820d5e74ab7aa102789
MD5 ba2de5e72c36eb05edcabef69e6f9cc1
BLAKE2b-256 f0840d88cc5be3dd86d7d29d31403bfec1952a3cc41f08b494dea9954541cdf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for corecrux_client-0.1.0.tar.gz:

Publisher: sdk-python.yml on CueCrux/Crux

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file corecrux_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for corecrux_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c774c50fe61d90cefccad5b2323c0b4446a38ebb75d9793d3cd26a1aa3804536
MD5 be586a7f3487016741e7e45c04143054
BLAKE2b-256 7ffe0628cdd7b7e59b59e6466092befa3c41f79ef485d13d31d26310d5696cbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for corecrux_client-0.1.0-py3-none-any.whl:

Publisher: sdk-python.yml on CueCrux/Crux

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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