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",
)

Atomic idempotent patches

Read the branch data version immediately before proposing a write, then use it when applying a mixed patch. TerminusDB rejects the patch if the branch changed since that version. The patch operations share one WOQL transaction and one commit. An operation marker containing a canonical patch hash is included in the commit message, so retrying after a lost response returns the original commit. Reusing an operation ID for different content raises ValueError.

version = await db.get_data_version()
commit = await db.apply_atomic_patch(
    "workflow-123-operation-4",
    inserts=[{"@type": "Discipline", "@id": "Discipline/MATH-01", "name": "Math"}],
    updates=[],
    deletes=[],
    author="ordoedu-agent",
    message="Import a discipline",
    last_data_version=version,
)

get_commit_log() exposes the branch log used for recovery and audit.

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.2.1

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.2.1
File Size Uploaded Provenance Actions
terminusdb_async-0.2.1.tar.gz 21.5 kB Without provenance Details for terminusdb_async-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 32.6 kB

Release files / terminusdb_async-0.2.1.tar.gz

Download URL terminusdb_async-0.2.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7c535533e75b76d3715a3a4ca36831355a5c64d1a36f0b57682f9f6be3d53d59
BLAKE2b-256 checksum
How to use checksums
2bb9c44f43ec33eab1609ff4f4e30d372972258e8744320f16864c2af444243e
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.2.1-py3-none-any.whl

Download URL terminusdb_async-0.2.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
641ca743207dde8729d09058f5d52951682b4488953e38ba49d9852d58dd3f3d
BLAKE2b-256 checksum
How to use checksums
13d147fca300694a7edeeb4f3c7759be6a34f6004e967e289648c977e9e03968
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}

Security for terminusdb-async 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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