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.1.tar.gz (19.8 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.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gdg_bu_kg-0.1.1.tar.gz
  • Upload date:
  • Size: 19.8 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.1.tar.gz
Algorithm Hash digest
SHA256 5f8bd800c443b3671d4ffc62f4a7d915ce35ce7d427dcd09d77e17f69a8baf65
MD5 ec7a7904248def72dff968dadf818c7b
BLAKE2b-256 4e9f43fc6c02fddc9a46ab5200fd5a884b6b854421d112c8b4667a5aa4768224

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gdg_bu_kg-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4e866f6e2fde31244bd92107cac42bbd5fe6dd121b94ad177de35928a598332
MD5 3239c1e2c6dafb18d42ecf82f395ce08
BLAKE2b-256 1578391ebff519d6c9682bf70c6e0cdd494680c20b5b09f58a8d9f0eacd6fd13

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