SDKs
VaultDB has a TypeScript client and a Python client. Each is a single source file that you download from the API and add to your project. They are not published to npm or PyPI.
Downloading needs an API key with the Databases permission.
TypeScript
curl -o vaultdb-client.ts https://api.vaultdb.io/api/sdk/typescript \
-H "Authorization: Bearer $VAULTDB_API_KEY"
The client uses the global fetch, so it runs in Node.js 18 or later, Deno, Bun and other runtimes that have fetch.
import { VaultDB, VaultDBError } from './vaultdb-client'
const vault = new VaultDB({
apiKey: process.env.VAULTDB_API_KEY!,
baseUrl: 'https://api.vaultdb.io'
})
const shop = vault.database('shop')
await shop.table('orders').insert({ customer: 'ada', total: 120.5 })
const { data, pagination } = await shop.table('orders').get({
where: { customer: 'ada' },
orderBy: 'total',
orderDirection: 'DESC',
limit: 20
})
// The next page starts at pagination.nextOffset (null after the last row).
try {
await shop.query('SELECT COUNT(*) AS n FROM orders')
} catch (err) {
if (err instanceof VaultDBError) console.error(err.status, err.message)
}
Python
curl -o vaultdb_client.py https://api.vaultdb.io/api/sdk/python \
-H "Authorization: Bearer $VAULTDB_API_KEY"
The client needs the requests package (pip install requests).
import os
from vaultdb_client import VaultDB, VaultDBError
vault = VaultDB(api_key=os.environ["VAULTDB_API_KEY"], base_url="https://api.vaultdb.io")
shop = vault.database("shop")
shop.table("orders").insert({"customer": "ada", "total": 120.5})
rows = shop.table("orders").get(where={"customer": "ada"}, order_by="total", order_direction="DESC", limit=20)
try:
shop.query("SELECT COUNT(*) AS n FROM orders")
except VaultDBError as err:
print(err.status, err.message)
What the clients cover
Both clients have the same methods. TypeScript names are shown; Python uses the same names in snake_case (createTable is create_table).
| Object | Methods |
|---|---|
VaultDB |
database(dbid), createDatabase(name, displayName?), listDatabases(), billingStatus() |
database(dbid) |
table(name), createTable(name, columns), listTables(), info(), query(sql, params?), graphql(query), graphqlSchema(), branch(name), listBranches(), createSnapshot(), listSnapshots(), restoreSnapshot(id), deleteSnapshot(id), listPolicies(), createPolicy(policy), listWebhooks(), createWebhook(webhook), listSchedules(), createSchedule(schedule), delete() |
table(name) |
get(options?), insert(rowOrRows), update(data, where), delete(where), schema(), search(options), exportCsv(), exportJson(), importCsv(csv), drop() |
Each method calls the endpoint described in these docs and returns the API's response. An error response raises VaultDBError, which carries the HTTP status and the API's message.
In Python, create_policy, create_webhook and create_schedule take the request fields as keyword arguments, for example shop.create_webhook(url="https://example.com/hook").
The clients do not cover the realtime stream, or deleting a webhook, policy or schedule. Call those endpoints directly.
OpenAPI
GET /api/openapi returns an OpenAPI 3.0 document for the API, generated from the API's route table. You can feed it to a client generator. It needs the Databases permission. The same document is shown on the API reference page.
curl -o vaultdb-openapi.json https://api.vaultdb.io/api/openapi \
-H "Authorization: Bearer $VAULTDB_API_KEY"