Skip to main content

Official Python client for Deltex — edge-native SQL database

Project description

deltex — Python client

Official Python client for Deltex — edge-native SQL database.

Install

pip install deltex

Quick start

import deltex

# Auto-reads DELTEX_API_KEY from environment
db = deltex.connect()

# Query
users = db.query("SELECT * FROM users WHERE active = $1", [True])
user  = db.query_one("SELECT * FROM users WHERE id = $1", [42])

# Mutation
n = db.execute("INSERT INTO events (type, ts) VALUES ($1, NOW())", ["pageview"])

# Full result with commit status
result = db.execute_raw("INSERT INTO orders (amount) VALUES ($1)", [99.99])
print(result.commit_status)  # "edge-accepted" | "committed"
print(result.execution_ms)   # server-side execution time

API

deltex.connect(api_key=None, endpoint=None, write_mode="sync", ...)

Param Default Description
api_key DELTEX_API_KEY env Bearer token
endpoint DELTEX_ENDPOINT or https://db.deltex.dev Engine URL
write_mode "sync" "sync" / "edge" / "async"
timeout 30.0 Request timeout (seconds)
max_retries 3 Auto-retry on 429
tag None X-Query-Tag for analytics

Methods

db.query(sql, params=[])        list[dict]
db.query_one(sql, params=[])    dict | None
db.execute(sql, params=[])      int  (rows affected)
db.execute_raw(sql, params=[])  QueryResult

db.transaction(fn)             # BEGIN → fn(tx) → COMMIT
db.batch(statements)           # atomic multi-statement, one round-trip → int

db.with_write_mode("sync")      Client  (per-client write mode)
db.strong                       Client  (X-Consistency: strong)
db.with_idempotency_key(key)    Client  (safe retry deduplication)
db.with_tag(tag)                Client  (X-Query-Tag)

Async

import asyncio
import deltex

async def main():
    async with deltex.async_connect() as db:
        users = await db.query("SELECT * FROM users LIMIT 10")
        print(users)

asyncio.run(main())

Transaction

def transfer(tx):
    tx.execute("UPDATE accounts SET balance = balance - $1 WHERE id = $2", [100, 1])
    tx.execute("UPDATE accounts SET balance = balance + $1 WHERE id = $2", [100, 2])

db.transaction(transfer)

Batch — fastest bulk write

batch() applies a list of SQL statements in one round-trip, committed atomically, and returns total rows affected:

n = db.batch([
    "INSERT INTO products (name, price) VALUES ('Apple', 0.99)",
    "INSERT INTO products (name, price) VALUES ('Banana', 0.59)",
])  # n == 2

Looping execute makes one durable commit per statement. batch() (and a single multi-row INSERT) coalesce them into one commit — O(1) instead of O(N) — so it's far faster for bulk writes. batch() takes raw SQL (no binding) — for untrusted values, build statements safely or use transaction.

CLI

export DELTEX_API_KEY="dtx_k_..."

deltex query "SELECT * FROM users LIMIT 5"
deltex tables
deltex schema orders
deltex exec "DELETE FROM sessions WHERE expires_at < NOW()"
deltex health
deltex bench --samples 30

Write Modes

Mode Use when
sync (default) Everything by default; durable, never loses an acked write
edge Caches, sessions, idempotent upserts — eventual durability
async High-volume telemetry, fire-and-forget

Error handling

from deltex import DeltexError, RateLimitError

try:
    db.query("SELECT * FROM nonexistent")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except DeltexError as e:
    print(f"Error {e.status}: {e.engine_message}")
    print(f"SQL: {e.sql}")

License

MIT


Common Patterns

Error handling

import time
from deltex import connect, RateLimitError, DeltexError

db = connect()
try:
    result = db.query("SELECT * FROM users WHERE id = $1", [42])
except RateLimitError as e:
    time.sleep(e.retry_after)
    result = db.query("SELECT * FROM users WHERE id = $1", [42])
except DeltexError as e:
    print(f"Query failed: {e}")
    raise

Async client (non-blocking)

import deltex

async def main():
    db = deltex.async_connect()
    rows = await db.query("SELECT * FROM products WHERE price < $1", [50.0])
    for row in rows:
        print(row["name"], row["price"])

CLI usage

# Run a query
deltex query "SELECT COUNT(*) FROM users"

# Migrate
deltex migrate --file migrations/001_create_users.sql

# Backup
deltex backup --output backup.json

# Manage API keys
deltex keys list
deltex keys create --name "production"
deltex keys revoke --id key_id_here

SDK Version

v1.3.2 — see CHANGELOG.md for history.

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

deltex-1.3.2.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

deltex-1.3.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file deltex-1.3.2.tar.gz.

File metadata

  • Download URL: deltex-1.3.2.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for deltex-1.3.2.tar.gz
Algorithm Hash digest
SHA256 10afbed4157fc5fd4c4e13012d879fc7ade854985297e292674ac729db9afcd5
MD5 fd2c36e5e73fb216bf799c0877de7070
BLAKE2b-256 2686ecae72c5ec31066a8f8a1ffb10b0b84269b0e0f5b5f8f786b6c9d8b8da51

See more details on using hashes here.

File details

Details for the file deltex-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: deltex-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for deltex-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cdff7deb10ac015cb0aa3116d72e69b2c0db6bbd7cb02f5307f489f211da0a57
MD5 ac1869b0f8deb5a78728eb1ef51796f2
BLAKE2b-256 f45ce7ae52ee0ba70d668d41aecd59c9e9477f788becce08bbc3b505451605f6

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