Skip to main content

Konnektr Graph SDK for Python

A powerful, Python SDK for Konnektr Graph, fully compatible with the Azure Digital Twins API but optimized for the Konnektr ecosystem.

Features

  • Azure-Free: No dependencies on Azure libraries.
  • Synchronous & Asynchronous: High-performance clients for both threaded and async workflows.
  • Modular Auth: Supports OAuth 2.0 Client Credentials, Device Code Flow, and Static Tokens.
  • Auto-Pagination: Seamlessly iterate through large query results and resource lists.
  • Data Models: Typed dataclasses for Digital Twins, Models, Relationships, and Jobs.

Installation

pip install konnektr-graph

Quick Start

Synchronous Client

from konnektr_graph import KonnektrGraphClient
from konnektr_graph.auth import ClientSecretCredential

# Authenticate
cred = ClientSecretCredential(
    domain="auth.konnektr.io",
    audience="https://graph.konnektr.io",
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET"
)

# Initialize Client
client = KonnektrGraphClient("https://your-graph-endpoint.konnektr.io", cred)

# Get a Digital Twin
twin = client.get_digital_twin("my-twin-id")
print(twin)

# Query Twins with auto-pagination (Cypher)
query = "MATCH (t:Twin) RETURN t"
for twin in client.query_twins(query):
    print(twin)

# Query with parameters (Cypher + `$name` placeholders, forwarded to the
# server's `parameters` field; only Cypher supports query parameters)
params = {"model": "dtmi:com:example:Room;1", "minTemp": 20}
query = "MATCH (t:Twin) WHERE t.`$metadata`.`$model` = $model AND temperature > $minTemp RETURN t"
for twin in client.query_twins(query, query_parameters=params):
    print(twin)

Asynchronous Client

import asyncio
from konnektr_graph.aio import KonnektrGraphClient
from konnektr_graph.auth import AsyncClientSecretCredential

async def main():
    cred = AsyncClientSecretCredential(
        domain="auth.konnektr.io",
        audience="https://graph.konnektr.io",
        client_id="...",
        client_secret="..."
    )

    async with KonnektrGraphClient("https://your-graph-endpoint.konnektr.io", cred) as client:
        twin = await client.get_digital_twin("my-twin-id")
        print(twin)

asyncio.run(main())
# Environment/user/privacy scoping is enforced SERVER-SIDE: scope predicates
# (model allow-list, property equality filters, related-twin predicate) are
# applied in the database *before* nearest-neighbour ranking and LIMIT, so the
# ranking never sees out-of-scope records. Never filter broad search results
# locally for authorization — use this dedicated endpoint instead.
results = client.search_memory(
    vector=[0.11, -0.02, 0.58],
    limit=5,
    model_ids=["dtmi:example:MemoryRecord;1"],
    property_filters={"environmentId": "env-1", "userId": "user-9"},
    related_twin_id="session-9",
)
for record in results:
    print(record.id, record.distance, record.excerpt)

# Probe pgvector availability, and create the HNSW index (idempotent) once:
capability = client.get_memory_search_capability()
if capability.vector_search_available:
    client.ensure_memory_search_index(dimension=3)

The async client (konnektr_graph.aio.KonnektrGraphClient) exposes the same three methods (search_memory, ensure_memory_search_index, get_memory_search_capability) with identical signatures and typed results (MemorySearchResult, MemorySearchIndex, MemorySearchCapability).

Error mapping: authorization failures raise AuthenticationError (401/403), server-side validation failures raise ValidationError (400), a missing pgvector extension raises ServiceUnavailableError (503), and transport failures raise HttpResponseError.

Authentication Options

  • ClientSecretCredential / AsyncClientSecretCredential: Ideal for server-to-server scenarios.
  • DeviceCodeCredential / AsyncDeviceCodeCredential: Best for interactive CLI tools.
  • StaticTokenCredential: Use when you already have a valid access token.
  • DefaultAzureCredentialAdapter / AsyncDefaultAzureCredentialAdapter: Use Azure Identity credentials through the SDK auth protocol.

Using Azure Identity (DefaultAzureCredential)

If your backend validates Azure AD tokens (e.g., ADT-compatible audience https://digitaltwins.azure.net/), you can adapt DefaultAzureCredential to this SDK's TokenProvider interface.

Install Azure Identity in your app:

pip install "konnektr-graph[azure]"

Or install azure-identity directly if you prefer:

pip install azure-identity

Sync

from azure.identity import DefaultAzureCredential
from konnektr_graph import KonnektrGraphClient
from konnektr_graph.auth import DefaultAzureCredentialAdapter

endpoint = "https://your-graph-endpoint"

azure_cred = DefaultAzureCredential()
cred = DefaultAzureCredentialAdapter(
    azure_cred,
    scope="https://digitaltwins.azure.net/.default",
)

client = KonnektrGraphClient(endpoint, cred)
twin = client.get_digital_twin("my-twin-id")
print(twin)

Async

import asyncio
from azure.identity.aio import DefaultAzureCredential
from konnektr_graph.aio import KonnektrGraphClient
from konnektr_graph.auth import AsyncDefaultAzureCredentialAdapter

async def main():
    endpoint = "https://your-graph-endpoint"

    azure_cred = DefaultAzureCredential()
    cred = AsyncDefaultAzureCredentialAdapter(
        azure_cred,
        scope="https://digitaltwins.azure.net/.default",
    )

    async with KonnektrGraphClient(endpoint, cred) as client:
        twin = await client.get_digital_twin("my-twin-id")
        print(twin)

    await azure_cred.close()

asyncio.run(main())

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for konnektr-graph 0.3.9

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

Source distribution (sdist)

Source distribution for konnektr-graph 0.3.9
File Size Uploaded
konnektr_graph-0.3.9.tar.gz 44.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for konnektr-graph 0.3.9
File Interpreter ABI Platform
konnektr_graph-0.3.9-py3-none-any.whl Python 3 none any Details

Total release size: 83.6 kB

Release files / konnektr_graph-0.3.9.tar.gz

Download URL konnektr_graph-0.3.9.tar.gz
Size 44.9 kB
Tags Source
SHA-256 checksum
How to use checksums
234a155eec68ccc4a25d09d8b0c615f5a1124c1d7da8c92b6c37d28e4f324485
BLAKE2b-256 checksum
How to use checksums
186da99736e105cb97ada05bf931a80203b3d0b9c8b6e807fa81491d2c74babb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release files / konnektr_graph-0.3.9-py3-none-any.whl

Download URL konnektr_graph-0.3.9-py3-none-any.whl
Size 38.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c34889956cccefc963b804fbcd6bc4d58f5632882df73ae789295c79a1ed80e
BLAKE2b-256 checksum
How to use checksums
f3059c2531435f077f21ba28b7353d54b93cf93ad909aaa6d5c6bf269db8d262
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.9 This release

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.2

2 release files

0.3.0

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.9

2 release files

0.2.7

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

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