Skip to main content

terminusdb-async

PyPI Python

A small native async Python client for the TerminusDB HTTP API, built on HTTPX.

terminusdb-async is intended for asyncio applications that want direct, typed-ish access to TerminusDB document, schema, migration, and GraphQL endpoints without putting a synchronous SDK behind a thread pool.

Status: early-stage / pre-1.0. The public API may still evolve between 0.x releases.

Project status: this is a community package and is not an official TerminusDB client.

Installation

With uv:

uv add terminusdb-async

With pip:

python -m pip install terminusdb-async

Python 3.11+ is supported.

Quick start

import asyncio

from terminusdb_async import AsyncTerminusClient


async def main() -> None:
    async with AsyncTerminusClient(
        "http://localhost:6363",
        organization="admin",
        database="edtech",
        username="admin",
        password="root",
    ) as db:
        document = await db.get_document("Discipline/MATH-01")
        print(document)


asyncio.run(main())

The client owns its underlying httpx.AsyncClient by default and closes it when the async context manager exits.

Authentication

Basic authentication

client = AsyncTerminusClient(
    "http://localhost:6363",
    organization="admin",
    database="edtech",
    username="admin",
    password="root",
)

TerminusDB token

client = AsyncTerminusClient(
    "https://terminus.example.com",
    organization="acme",
    database="catalog",
    token="...",
)

Token authentication and basic authentication are mutually exclusive.

Database and branch management

Create an application database without dropping to raw HTTP:

await db.create_database(
    label="ordoedu",
    comment="OrdoEdu knowledge graph",
    exists_ok=True,
)

await db.create_branch(
    "import-123",
    origin="admin/ordoedu/local/branch/main",
    exists_ok=True,
)

Test and administrative code may remove a database explicitly with delete_database(missing_ok=True).

Document API

Read one document

doc = await db.get_document("Discipline/MATH-01")

Read documents

docs = await db.get_documents(
    document_type="Discipline",
    count=100,
)

You can also request explicit IDs:

docs = await db.get_documents(
    ids=["Discipline/MATH-01", "Discipline/PHYS-01"],
)

Insert documents

ids = await db.insert_documents(
    {
        "@type": "Discipline",
        "@id": "Discipline/MATH-01",
        "name": "Calculus",
    },
    author="application",
    message="Add Calculus",
)

A sequence of JSON-like mappings can be inserted in the same request.

overwrite=True forwards the server's existing-ID insertion option. It does not remove old property values. Use replace_documents() to update an existing document.

Replace documents

await db.replace_documents(
    {
        "@type": "Discipline",
        "@id": "Discipline/MATH-01",
        "name": "Mathematical Analysis",
    },
    author="application",
    message="Rename discipline",
)

Delete documents

await db.delete_documents(
    "Discipline/MATH-01",
    author="application",
    message="Remove discipline",
)

Query documents

docs = await db.query_documents(
    {"name": "Calculus"},
    document_type="Discipline",
)

Schema API

Schema documents use the same Document API with graph_type="schema".

schema = await db.get_schema_documents()

await db.insert_schema_documents(
    [
        {
            "@type": "Class",
            "@id": "Discipline",
            "name": "xsd:string",
        }
    ],
    author="schema-bot",
    message="Add Discipline",
)

For initial schema loading, bootstrap_schema() performs a schema insert with full replacement enabled.

Migration API

The client exposes TerminusDB migration operations directly:

result = await db.migrate(
    [
        {
            "@type": "CreateClassProperty",
            "class": "Discipline",
            "property": "description",
            "type": {
                "@type": "Optional",
                "@class": "xsd:string",
            },
        }
    ],
    author="schema-bot",
    message="Add optional description",
    dry_run=True,
)

For automatic migration planning from Pydantic models, see terminusdb-migrations.

GraphQL

result = await db.graphql(
    """
    query {
      Discipline {
        _id
        name
      }
    }
    """
)

Variables can be passed with the variables= argument.

Server health and metadata

await db.ok()
await db.info()

Error handling

HTTP failures are converted to TerminusDBError:

from terminusdb_async import TerminusDBError

try:
    await db.get_document("Discipline/missing")
except TerminusDBError as exc:
    print(exc.status_code)
    print(exc.body)

The exception keeps the HTTP status code and the decoded error response when available.

Using an existing HTTPX client

You can inject an existing httpx.AsyncClient when connection pooling, transport customization, tracing, or application-wide lifecycle management is handled elsewhere:

import httpx

from terminusdb_async import AsyncTerminusClient

http = httpx.AsyncClient(base_url="http://localhost:6363")

db = AsyncTerminusClient(
    "http://localhost:6363",
    organization="admin",
    database="edtech",
    http_client=http,
)

An injected client is not closed by AsyncTerminusClient.

Resource paths and branches

The default branch is main. Requests target:

<organization>/<database>/local/branch/<branch>

Choose another TerminusDB branch explicitly:

db = AsyncTerminusClient(
    "http://localhost:6363",
    organization="admin",
    database="edtech",
    branch="feature-schema",
)

Scope

The package intentionally stays small. It currently focuses on:

  • async HTTP transport;
  • document CRUD and document queries;
  • schema document access;
  • native migration operations;
  • GraphQL requests;
  • Basic and TerminusDB token authentication.

It is not an ORM and it does not try to reproduce the full official TerminusDB Python SDK.

For model/schema integration, use terminusdb-pydantic.

Package family

Package Purpose
terminusdb-async Async TerminusDB HTTP client
terminusdb-pydantic Pydantic v2 ↔ JSON-LD and schema generation
terminusdb-migrations Schema diff and migration planning

All packages are pre-1.0 and are versioned independently.

Development

The project uses uv for dependency management, environments, building, and publishing.

uv sync --group dev
uv run pytest -q
uv build --no-sources

Unit tests run without a server. To run the integration suite against an isolated local server:

docker compose -f compose.test.yml up -d
uv run pytest -q --run-integration
docker compose -f compose.test.yml down -v

To choose the other tested version, prefix the up command with TERMINUSDB_VERSION=v12.0.6. For an existing test server, set TERMINUSDB_TEST_URL, TERMINUSDB_TEST_USERNAME, TERMINUSDB_TEST_PASSWORD, and TERMINUSDB_TEST_ORGANIZATION as needed (defaults: localhost:6363, admin/root, organization admin). Each test creates a unique database and deletes it afterwards. The suite waits up to 120 seconds for readiness; once enabled, an unavailable server fails the tests rather than skipping them.

GitLab CI runs unit tests on Python 3.11, 3.12, and 3.13, plus the full integration suite for every combination of those Python versions and TerminusDB v12.0.6 / v12.0.7. The service uses Basic authentication. Integration coverage includes schema bootstrap/read/write, document CRUD, batch operations, filters, pagination, server errors, invalid authentication, migration dry-run/apply, GraphQL variables, branch isolation, and concurrent reads. JUnit reports are available in the pipeline. All tests must succeed before building and publishing a release. Other server versions are not currently verified by CI.

Development follows GitHub Flow on GitLab: short-lived branches are merged into main through Merge Requests. See CONTRIBUTING.md for the repository workflow.

Versioning

While the project is pre-1.0, consumers that want compatible updates should use a bounded dependency such as:

terminusdb-async = ">=0.1.2,<1.0.0"

Breaking changes may still occur in 0.x; review release notes before upgrading across minor versions.

See CHANGELOG.md for release notes.

License

MIT License. See LICENSE for the full text.

Metadata

Release files for terminusdb-async 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for terminusdb-async 0.1.4
File Size Uploaded
terminusdb_async-0.1.4.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for terminusdb-async 0.1.4
File Interpreter ABI Platform
terminusdb_async-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / terminusdb_async-0.1.4.tar.gz

Download URL terminusdb_async-0.1.4.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e9a46a8791fb5a1852149a3f21e2574a57894c699ec276cc974004582ade49dc
BLAKE2b-256 checksum
How to use checksums
4c570b3bf99121bb62147fd54fe5640a99c2a9222a75bcfec1b03ebd630ec456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / terminusdb_async-0.1.4-py3-none-any.whl

Download URL terminusdb_async-0.1.4-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49f49abd095da300c0c67f50678c427f3fe04380b61f21b84886598d0ffc8124
BLAKE2b-256 checksum
How to use checksums
72720a19cda942f66c6dff7e61728561c09f0b7d60e1147490188240cecda615
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page