Skip to main content

Generic Python SDK for TreeDX.

Project description

TreeDX Python SDK

treedx is the generic Python SDK for TreeDX. It implements the shared packages/sdk-spec architecture, follows docs/api/openapi.yaml, and does not encode TreeSeed product semantics. packages/trsd-sdk is a downstream TreeSeed consumer/reference only.

The current sdk-manifest.yaml reports modules, capabilities, and test roots as implemented. The SDK exposes all 113 /api/v1 OpenAPI operations through first-class module methods and a validated raw operation fallback.

Install

python -m pip install treedx

Configure Client

from treedx import TreeDxClient, TreeDxApiError

client = TreeDxClient(
    base_url="http://localhost:4000",
    token="...",
)

The client also accepts an auth provider, custom transport, default headers, and timeout settings.

Authenticate

Bearer authentication uses the Authorization: Bearer <token> header. Tokens may come from token or an auth provider. The SDK must not place production identity in request JSON and must not log bearer tokens.

Basic Health Call

health = client.health()
version = client.version()

Repository Query

Repository-scoped query helpers live under client.query:

results = client.query.search_files(
    "repo_demo",
    {"query": "release provenance", "paths": ["docs/**"]},
)

file = client.query.read_file(
    "repo_demo",
    {"ref": "refs/heads/main", "path": "docs/index.md"},
)

Workspace File Lifecycle

Workspace-scoped file helpers live under client.workspaces and client.files:

workspace = client.workspaces.create("repo_demo", {"ref": "refs/heads/main"})

client.files.write("workspace_123", {"path": "docs/new.md", "content": "# New"})
client.files.patch("workspace_123", {"path": "docs/new.md", "patch": "..."})
client.files.commit("workspace_123", {"message": "Update docs"})
client.workspaces.close("workspace_123")

Blob Upload And Download

Binary helpers preserve byte payloads and reject strings as binary input.

client.blobs.upload("workspace_123", b"\x01\x02\x03")
blob = client.blobs.download("workspace_123", {"path": "asset.bin"})

Multipart helpers expose create, part upload, complete, and abort:

upload = client.blobs.create_multipart_upload("workspace_123", {"path": "large.bin"})
client.blobs.upload_part("workspace_123", upload["uploadId"], 1, b"\x01")
client.blobs.complete_multipart_upload(
    "workspace_123",
    upload["uploadId"],
    {"parts": [{"partNumber": 1}]},
)

Graph And Context Query

client.graph.refresh("repo_demo")
graph = client.graph.query("repo_demo", {"query": "MATCH ..."})
context = client.context.build("repo_demo", {"query": "ctx docs"})
parsed = client.context.parse("repo_demo", {"source": "ctx docs"})

Federated Query

Federation helpers use portfolio/global TreeDX routes rather than a single configured repository:

plan = client.federation.plan({"query": "release provenance"})
results = client.federation.search({"query": "release provenance"})

Scoped Admin And Internal Modules

Full OpenAPI coverage includes sensitive scoped modules: Admin, Audit, Policy, SearchIndex, and FederationInternal. These APIs require appropriate TreeDX credentials and should be used carefully against production systems. They remain generic TreeDX APIs and do not encode TreeSeed product semantics.

The raw operation fallback validates method/path pairs against generated OpenAPI metadata before dispatch.

Error Handling

Non-2xx responses and network failures raise TreeDxApiError. The error keeps status, code, message, details, and payload available. Network failures use status=0 and code="network_error".

try:
    client.whoami()
except TreeDxApiError as error:
    print(error.status, error.code, error.message)

Pagination

TreeDxPage and TreeDxCursor model opaque server-owned cursor pagination. Helpers preserve cursor metadata and do not decode cursor internals.

Binary And Multipart

Binary helpers accept bytes, bytearray, memoryview, and binary streams. Multipart helper metadata is represented by MultipartUpload.

Conformance

The conformance adapter loads Phase 7 scenario records and reports live or configured until executable live dispatch is wired. It must not fake conformance success.

python -m pytest tests/conformance

Integration

Integration tests call a live TreeDX server only when TREEDX_BASE_URL is set. Without that environment variable, they skip cleanly.

python -m pytest tests/integration

Development Commands

python -m pip install -e ".[dev]"
python scripts/check_treedx_generated_types.py
python -m build
python -m pytest tests/conformance
python -m pytest tests/integration
python -m pytest

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

treedx-0.2.34.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

treedx-0.2.34-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file treedx-0.2.34.tar.gz.

File metadata

  • Download URL: treedx-0.2.34.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for treedx-0.2.34.tar.gz
Algorithm Hash digest
SHA256 a2ecf33aa70f1855e0587d4d1ce4e1e3e863f6e7181a35a0e7a11d4ed4f3f5dd
MD5 3c20e2497149c3dae63ed08b5d35e792
BLAKE2b-256 d009614640d705c19db0d5ba28647ebeb24b149b298cd0a693a2d2a52b488e71

See more details on using hashes here.

File details

Details for the file treedx-0.2.34-py3-none-any.whl.

File metadata

  • Download URL: treedx-0.2.34-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for treedx-0.2.34-py3-none-any.whl
Algorithm Hash digest
SHA256 4e02f643b4cc60c216684527410c787d75a20175e67a1b6d036da76fdaab7652
MD5 b4f8c2f48d82a74c473060772c15b82c
BLAKE2b-256 5129c0733e8c16f625933569d6215dc927f24e0b29f0b295178c285ac054ddd8

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