Skip to main content

Konnektr Graph SDK for Python

Project description

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
for twin in client.query_twins("SELECT * FROM digitaltwins"):
    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())

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.

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

konnektr_graph-0.3.0.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

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

konnektr_graph-0.3.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file konnektr_graph-0.3.0.tar.gz.

File metadata

  • Download URL: konnektr_graph-0.3.0.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for konnektr_graph-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5450ce3fb52d642a4aa411421c5aca80b4de141d49995d411c0e27e849bbfe78
MD5 a780b6d32eea42c161e1c91bfdc20ef6
BLAKE2b-256 5a712c49b1ba6ddeaa2b90997342ee27147dc02bb090c626f40c0421afbf61a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for konnektr_graph-0.3.0.tar.gz:

Publisher: pypi-publish.yml on konnektr-io/graph-client-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file konnektr_graph-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: konnektr_graph-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for konnektr_graph-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c7ae4ebbc398a67a046038d5944e06ae33ab2f6f32261a8e32f359381a972e
MD5 ec4f8efae52f9340a1cded7b0b5111f9
BLAKE2b-256 2d55fba206759c74f4192cb64b464fd1fa0c4378796c8063fca4f95ae4c6e59a

See more details on using hashes here.

Provenance

The following attestation bundles were made for konnektr_graph-0.3.0-py3-none-any.whl:

Publisher: pypi-publish.yml on konnektr-io/graph-client-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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