Skip to main content

Official Python client for OriginChain — managed database for AI applications.

Project description

originchain (Python)

Official Python client for OriginChain.

Other languages: TypeScript / JavaScript → @originchain/sdk · Go → github.com/originchain-ai/originchain-go · raw HTTP → originchain.ai/docs.

Install

pip install originchain

HTTP/2 is enabled by default — multiplexed cross-region calls save ~300 ms each vs HTTP/1.1.

Quick start

from originchain import OriginChain

# Reads OC_BASE_URL, OC_BEARER, OC_TENANT from env.
db = OriginChain.from_env()

# Register a schema.
db.schemas.register(open("orders.toml").read())

# Insert a row.
db.rows.put(
    "trading.orders",
    {"order_id": "o1", "symbol": "AAPL", "qty": 100},
    idempotency_key="user-action-42",
)

# Ask in natural language.
result = db.ask("orders for AAPL above 50 shares last week")
for row in result["rows"]:
    print(row)

Async

import asyncio
from originchain import AsyncOriginChain

async def main() -> None:
    async with AsyncOriginChain.from_env() as db:
        await db.rows.put("trading.orders", {"order_id": "o2", "symbol": "MSFT", "qty": 50})
        print(await db.ask("show me the largest MSFT order this hour"))

asyncio.run(main())

SQL

resp = db.sql("SELECT order_id, qty FROM trading.orders WHERE symbol = 'AAPL'")
for row in resp.rows:
    print(row["order_id"], row["qty"])

db.sql_one("SELECT ... LIMIT 1") returns the first row dict (or None).

Vector

db.vector_put("embeddings", id="doc-1", embedding=[0.1, 0.2, 0.3], dim=3)
hits = db.vector_topk("embeddings", query=[0.1, 0.2, 0.3], k=5, dim=3)
for h in hits:
    print(h.id, h.score)

Full-text

db.fts_index("articles", "body", doc_id="d1", text="the quick brown fox")
hits = db.fts_search("articles", "body", q="quick fox", mode="bm25", k=5)
print([(h.doc_id, h.score) for h in hits])

Graph

nbrs = db.graph.neighbors("users", rel="follows", pk="u1")
for n in nbrs:
    print(n.pk)
result = db.graph.dijkstra("users", rel="follows", src="u1", dst="u9",
                           weights={"u1|u2": 1.0, "u2|u9": 0.5})
print(result.cost)

Auth

Bearer tokens are minted in the OriginChain console and scoped to a single instance. Treat them like database passwords — env vars or secrets manager, never committed.

Errors

The client maps HTTP errors to a typed hierarchy:

from originchain import (
    OCAuthError,
    OCPaymentRequiredError,
    OCRateLimitedError,
    OCServerError,
)

try:
    db.rows.put("trading.orders", row)
except OCRateLimitedError as e:
    time.sleep(e.retry_after)
    db.rows.put("trading.orders", row)
except OCPaymentRequiredError as e:
    print(f"enable {e.name} at {e.purchase_url}")
except OCAuthError:
    print("rotate your bearer in the console")

When the leader returns 200 but synchronous replication didn't ack within the configured timeout, the client emits an OCReplicationDegraded warning. The write IS durable on the leader; the warning surfaces a follower-lag signal callers can monitor or page on.

Versioning

This client follows semver. The 0.x line is for design partners; the API surface may change before 1.0.

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

originchain-0.4.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

originchain-0.4.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file originchain-0.4.0.tar.gz.

File metadata

  • Download URL: originchain-0.4.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for originchain-0.4.0.tar.gz
Algorithm Hash digest
SHA256 3eccc25f0785ee9fb19fa43090a4b0e3eb0a7bfdbe02929d5c947d32ecf86205
MD5 0c4ed3a6328a6f98d569bf7ec15f2a72
BLAKE2b-256 02e16c24b263f00a844aa2ab480298857fcb663cc6103be839144ee9b379d199

See more details on using hashes here.

File details

Details for the file originchain-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: originchain-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for originchain-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81b0b633fb38578f82c50a1b2529c6576eb75dcc4ef66711faeee1b35291505c
MD5 1e7207ebb90216796ddf8842822f5842
BLAKE2b-256 3f6ec8b161e3ce78b61e49fc170f88bb909a68461ff15a95f103fb4e85db3b67

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