Skip to main content

Python SDK for the Babcock University Knowledge Graph API

Project description

gdg_bu_kg: Babcock Knowledge Graph Python SDK

A lightweight, production-ready Python SDK for interacting with the Babcock University Knowledge Graph platform.

Features

  • Dual-Mode Querying:
    • client.query(): LLM-as-a-Service with built-in Babcock knowledge.
    • client.graph_query(): Extract raw contextual graph data (nodes & edges).
  • LLM Control: Full control over system_prompt, temperature, max_tokens, and top_p.
  • Developer-Friendly:
    • Sync and Async clients (httpx-based).
    • Strongly typed Pydantic v2 models.
    • Rich HTML display in Jupyter Notebooks.
    • Automatic retries with exponential backoff on transient errors.
  • Minimal Dependencies: Only httpx, pydantic, and tenacity.

Installation

pip install gdg-bu-kg

Quick Start (Sync)

from gdg_bu_kg import KnowledgeGraphClient, AuthenticationError

# 1. Initialize with your API key
client = KnowledgeGraphClient(api_key="your_platform_api_key_here")

try:
    # 2. AI Query: LLM + Knowledge Graph
    response = client.query(
        "Who is the current Vice Chancellor of Babcock University?",
        system_prompt="You are a helpful university administrator.",
        temperature=0.7
    )
    
    # Access the AI text response
    print("AI Answer:", response.data.text_response)
    
    # Access supporting graph data
    for node in response.data.graph.nodes:
        print(f"Verified Entity: {node.label}")

    # 3. Raw Graph Data Query
    graph_resp = client.graph_query("List all departments in the School of Computing")
    print("Context:", graph_resp.data.context)
    
except AuthenticationError:
    print("Invalid API Key. Please regenerate it in the SaaS Dashboard.")
finally:
    client.close()

Async Usage

import asyncio
from kg_client import AsyncKnowledgeGraphClient

async def main():
    async with AsyncKnowledgeGraphClient(api_key="your_key") as client:
        response = await client.query("Tell me about the history of Babcock.")
        print(response.data.text_response)

if __name__ == "__main__":
    asyncio.run(main())

Jupyter Notebook Support

The SDK models render beautifully in Jupyter:

# In a Jupyter cell:
response = client.query("What is the School of Computing?")
response  # Automatically renders as a formatted HTML view

Error Handling

The SDK provides a rich exception hierarchy:

  • AuthenticationError (401)
  • ForbiddenError (403)
  • InvalidQueryError (400)
  • RateLimitExceededError (429)
  • BackendServiceError (5xx)
  • ConnectionError (Network issues)

All inherit from KnowledgeGraphError.

License

MIT

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

gdg_bu_kg-0.1.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

gdg_bu_kg-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file gdg_bu_kg-0.1.0.tar.gz.

File metadata

  • Download URL: gdg_bu_kg-0.1.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for gdg_bu_kg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94c3d262a290cfaf51d87cd5e1c24ae3cab0593eb842623bb8e4027872aeff06
MD5 4797051d8b5a919980ce80cca2a919c9
BLAKE2b-256 384aad192691fc23fa204d91841b38a744709aff2ab9ad22c511a7b8f3e26880

See more details on using hashes here.

File details

Details for the file gdg_bu_kg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gdg_bu_kg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for gdg_bu_kg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d77e1f40c63de2e4c302f674a31a1b56585f505917c9e73e357b44799c05c1f4
MD5 382a901b4d7a09b389702946719ee0d5
BLAKE2b-256 e467e820f2e0654ed1bb95dbd0cde74134a65834617be83b3a32193419f3a4da

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