Developer beta 0.1.0-beta.1 documentation. The build is not available for download yet; these pages describe the beta as built and tested on Linux x86-64.
Python SDK
Package holadb, version 0.1.0b1 (the Python spelling of
0.1.0-beta.1). Python 3.10 or later, standard library only, type hints
included. It speaks the native protocol (port 7433 by default).
Install
The package is not on PyPI in this beta. Install it from the repository:
python3 -m pip install ./rust/clients/python
or build a wheel once and install that file wherever you need it:
python3 -m pip wheel --no-deps -w dist ./rust/clients/python
python3 -m pip install dist/holadb-0.1.0b1-py3-none-any.whl
python3 -c "import holadb; print(holadb.__version__)" prints 0.1.0b1.
Example
The examples on this page run as written against the server of the
quick start: it listens on 127.0.0.1:7433, has the
table products, an administrator admin and the user app with the role
readwrite.
app can read and write rows but cannot create tables, so this example
uses the table the quick start created. It can be run any number of times.
import holadb
with holadb.connect("holadb://app:app-secret@127.0.0.1:7433") as db:
print(db.whoami()) # {'user': 'app', 'roles': ['readwrite'], 'auth_required': True}
# insert, read, update: values travel as parameters ($1, $2, ...)
db.execute("DELETE FROM products WHERE sku IN ($1, $2)", ["C3", "D4"])
db.execute("INSERT INTO products (sku, name, price, stock) VALUES ($1, $2, $3, $4)", ["C3", "washer", 0.05, 1200])
for row in db.query("SELECT sku, name, price FROM products WHERE price < $1 ORDER BY sku", [0.2]):
print(row["sku"], row["name"], row[2]) # by name or by position
products = db.table("products") # helpers that generate SQL
products.insert({"sku": "D4", "name": "screw", "price": 0.3})
products.update("sku", "D4", {"stock": 40})
print(products.get("sku", "D4")) # {'sku': 'D4', 'name': 'screw', 'price': 0.3, 'stock': 40}
# a transaction: COMMIT at the end of the block ...
with db.transaction() as tx:
tx.execute("UPDATE products SET stock = stock - $1 WHERE sku = $2", [10, "D4"])
tx.execute("UPDATE products SET stock = stock + $1 WHERE sku = $2", [10, "C3"])
# ... ROLLBACK when the block raises; the exception leaves the block
try:
with db.transaction() as tx:
tx.execute("DELETE FROM products WHERE sku = $1", ["D4"])
raise RuntimeError("changed my mind")
except RuntimeError as e:
print("rolled back:", e)
print(products.count()) # 4: D4 is still there
# a statement the server refuses: the connection stays usable
try:
db.execute("INSERT INTO products (sku, name) VALUES ($1, $2)", ["A1", "duplicate"])
except holadb.ConstraintError as e:
print(e.code_name, "-", e) # constraint - ...
# a large result, one page of 500 rows at a time
for row in db.cursor("SELECT * FROM products ORDER BY sku", batch=500):
print(row["sku"])
Creating tables
Schema changes need a user who may run DDL. This example connects as the
quick start’s administrator for that one step, then works as app. It can
also be run any number of times.
import datetime
import holadb
with holadb.connect("holadb://admin:change-me-now@127.0.0.1:7433") as admin:
admin.execute(
"CREATE TABLE IF NOT EXISTS events (id BIGINT PRIMARY KEY, at TIMESTAMP, kind TEXT NOT NULL,"
" detail JSON, payload BYTEA, counter UBIGINT)"
)
# the password comes from an argument here; it could also come from HOLADB_PASSWORD
with holadb.connect("holadb://127.0.0.1:7433", user="app", password="app-secret", timeout=5) as db:
events = db.table("events")
events.delete("id", 1)
events.insert({
"id": 1,
"at": datetime.datetime(2026, 1, 2, 3, 4, 5, 500000, tzinfo=datetime.timezone.utc),
"kind": "login",
"detail": {"ip": "192.0.2.7", "tags": ["web"]}, # dict and list are JSON
"payload": b"\x00\xff",
"counter": 2**64 - 1, # 64-bit integers are exact
})
row = events.get("id", 1)
print(row["at"].to_datetime().isoformat()) # 2026-01-02T03:04:05.500000+00:00
print(row["detail"], row["payload"], row["counter"])
Connection options
holadb.connect(url, timeout, *, user, password, ca, server_name).
Everything can be written in the URL; an argument overrides the same part
of the URL. The TypeScript SDK takes the same URL.
| Setting | In the URL | Argument | Default |
|---|---|---|---|
| Plaintext or TLS | holadb:// or holadbs:// |
(a ca also means TLS) |
|
| Host and port | host:port |
127.0.0.1, 7433 |
|
| User | user@ |
user |
none: no login |
| Password | user:password@, percent-encoded |
password |
the environment variable HOLADB_PASSWORD, else empty |
| CA file (PEM) for TLS | ?ca=FILE |
ca |
the system trust store |
| Name the certificate must carry | ?servername=NAME |
server_name |
the host |
| Timeout | ?timeout=SECONDS |
timeout (seconds) |
30 s; None or 0: none |
- Example of a TLS URL:
holadbs://app@db.example.com:7433?ca=/etc/holadb/ca.pemwith the password inHOLADB_PASSWORD. The server needs a certificate (Security); the quick-start server has none. - The server certificate chain and name are always verified. There is no
insecure mode and no fallback to plaintext. Over TLS the login is
SCRAM-SHA-256-PLUSwithtls-server-end-pointchannel binding; without TLS it isSCRAM-SHA-256.db.is_tlstells which. - The timeout covers the connect and then every request (login steps,
statements, cursor pages): when the server sends nothing for that long
while a request waits, the connection is closed and the call raises
holadb.TimeoutError. The request may or may not have run on the server. - The server cancels a statement itself after
--statement-timeout-ms(30 s by default) and answers withStatementTimeoutError(code 25). Both defaults are 30 s: give the client a longer timeout if you want the server’s answer rather than a closed connection. - URL parameters other than
ca,servernameandtimeoutare ignored. holadb.Database(host, port, timeout=…, user=…, password=…, tls=…, ca=…, server_name=…)is the same without a URL;tlsisTrueor your ownssl.SSLContext.db.authenticate(user, password)logs in on an open connection.- Differences from the TypeScript SDK:
timeoutis in seconds (TypeScript:timeoutMsin milliseconds) and the argument isserver_name(TypeScript:servername).
Values
| Python | Sent as | Read back as |
|---|---|---|
None |
NULL | None |
bool |
boolean | bool |
int from −2^63 to 2^64−1 |
integer | int |
float |
float | float |
str |
text | str |
bytes, bytearray, memoryview |
bytes | bytes |
datetime.datetime, holadb.Timestamp |
timestamp (microseconds, UTC) | holadb.Timestamp (.micros, .to_datetime()) |
dict, list, holadb.Json |
JSON | the parsed value |
A naive datetime is taken as UTC. An int outside the 64-bit range, or
a statement text over 1 MiB, raises ValueError before anything is sent;
another type (for example decimal.Decimal) raises TypeError.
Errors
All SDK errors are holadb.HolaDBError with .code (the server’s code,
None for an error raised by the SDK itself) and .code_name.
| Class | Codes | Meaning |
|---|---|---|
SqlError |
4 no_such_table, 16 sql |
syntax error, unknown table or column, unsupported SQL |
ConstraintError |
17 constraint |
primary key, unique index or NOT NULL violation |
TransactionError |
18 transaction |
transaction misuse, or a conflict detected at COMMIT: run the transaction again |
AuthError |
20 unauthorized, 21 forbidden, 22 auth_failed |
log in first (also sent to a plaintext client by a server that requires TLS); missing privilege; wrong user or password |
BusyError |
23 busy |
connection limit reached, or logins from this address are delayed after failed attempts: retry later |
UncertainOutcomeError |
24 uncertain_outcome |
the outcome of a write is unknown: do not retry blindly; the server refuses writes until it is restarted |
StatementTimeoutError |
25 timeout |
the statement ran longer than the server’s statement timeout and was cancelled; nothing of it was applied and the connection stays usable |
ConnectionError |
none | the connection could not be made (refused, unknown host, TLS failure, unreadable CA file), was lost, or is closed: open a new one |
TimeoutError |
none | a ConnectionError (and a builtin TimeoutError): no answer within the client’s timeout; the connection is closed |
HolaDBError |
any other | for example 3 too_large (a result over the 16 MiB frame limit: read it with db.cursor), 8 invalid_argument, 14 shutting_down, 19 cursor |
After a server error the connection stays usable. A ValueError or
TypeError for a parameter is raised before anything is sent. Inside
with db.transaction() the exception that ended the block is the one you
get, also when the connection was lost and the rollback could not be sent.
holadb.ERROR_CODES maps all 25 codes to their names; a code this SDK
version does not know has the name code_N. holadb.ConnectionError and
holadb.TimeoutError have the names of builtins on purpose: write
holadb.ConnectionError in except clauses.
API summary
holadb.connect(url, …) |
a Database, also a context manager that closes it; holadb.__version__ is the SDK version |
db.query(sql, params=None) |
a Result: iterable rows, .rows, .columns, .column_types, .tag, .affected, .one(), .first(), .scalar() |
db.execute(sql, params=None) |
the number of affected rows |
db.explain(sql, params=None) |
the plan as text |
db.table(name) |
insert, insert_many, get, update, delete, select, count, cursor |
db.transaction() |
a context manager: commit, or roll back on an exception; tx.commit(), tx.rollback() |
db.cursor(sql, params=None, batch=1000) |
iterable rows, .pages(), .close(), a context manager |
db.whoami(), db.ping(), db.authenticate(user, password) |
identity, liveness, login |
db.is_tls, db.is_closed, db.close() |
state; close() never raises |
db.raw |
the low-level holadb.protocol.Client, including the engine-level operations (admin only once users exist); its errors are holadb.protocol.HolaDBError, ProtocolError and OSError |
A Row is a dict by column name that also indexes by position
(row["name"], row[1]). A connection is not safe for use from several
threads at once: use one connection per thread.
Known limitations in this beta
- Parameters beyond the statement’s placeholders are ignored by the server without an error.
- No automatic paging: a result over 16 MiB fails with
too_large; read it withdb.cursor. - Tested with Python 3.11 on Linux x86-64.
Checks
In rust/clients/python: python3 unit_check.py (no server needed),
python3 sdk_check.py HOST PORT [--ca CA_PEM] [--user NAME] (the SDK
against a running server; the user must be allowed to create tables and
its password is read from HOLADB_PASSWORD), python3 e2e_check.py HOST PORT
(the low-level client; needs a scratch database without users).
python3 -m holadb HOST PORT pings a server that has no users and lists
its engine tables.