Unified SDK for Local AI Guardian
Project description
This README.md is designed to be the definitive guide for your team. It explains the "Why" and the "How," shifting the focus from manual configuration to a Foundation-first approach.
GuardianHub SDK (Foundation)
Welcome to the core backbone of the GuardianHub ecosystem. This SDK is designed to provide Zero-Config capabilities for all microservices. By using this library, your service automatically inherits our standards for configuration, logging, and observability.
🚀 The "One-Minute" Setup
The goal of this SDK is to allow you to focus on business logic. You no longer need to manage config.json files or manually set up OpenTelemetry.
1. Installation
pip install guardianhub-sdk
2. Implementation
In your microservice's main.py, simply call the initialization utility:
from fastapi import FastAPI
from guardianhub.utils.fastapi_utils import initialize_guardian_service
from guardianhub import settings
app = FastAPI(title="My Service")
# This single call configures:
# - Environment-aware settings (K8s vs Local)
# - JSON Logging
# - Prometheus Metrics (/metrics)
# - Health Checks (/health)
# - OpenTelemetry Tracing (to Langfuse & OTEL Collector)
initialize_guardian_service(app)
@app.get("/task")
async def do_work():
# Use the pre-configured LLM client
# It already knows the Aura-LLM endpoint based on the environment
from guardianhub.clients import LLMClient
client = LLMClient()
return await client.generate("Hello world")
🛠 Configuration Philosophy
We have moved away from local config.json files in every repository. The SDK now uses a Hierarchical Provider system:
- SDK Defaults: Hardcoded "safe" fallbacks (usually
localhost). - Bundled Profiles: The SDK contains
config_dev.jsonandconfig_kubernetes-dev.json. It detects yourENVIRONMENTvariable and loads the correct infrastructure URLs automatically. - Environment Overrides: Any setting can be overridden using the
GH_prefix.
- Example: To change the LLM temperature without code changes, set
GH_LLM__TEMPERATURE=0.7. - Example: To point to a specific Vector DB, set
GH_ENDPOINTS__VECTOR_SERVICE_URL=http://my-db:8005.
Standard Endpoints
Every service using initialize_guardian_service(app) exposes:
GET /health: Returns uptime, version, environment, and active request count.GET /metrics: Prometheus-compatible metrics.
📊 Observability & Tracing
The SDK automatically instruments both incoming FastAPI requests and outgoing HTTPX calls.
- Trace Propagation: Traces automatically flow from Service A to Service B via W3C headers.
- Langfuse Integration: Traces are sent to the centralized Langfuse instance for LLM monitoring.
- Excluded URLs: Health checks and metrics endpoints are automatically filtered out of your traces to keep them clean.
🛡️ Best Practices for the Team
- No Local Configs: Do not create
config.jsonin your service repo. If an endpoint is missing, update it in the SDK and bump the version. - Use the
settingsobject: Never useos.getenvdirectly for shared infra. Usefrom guardianhub import settings. - Secrets: Sensitive keys (Postgres passwords, API keys) should be injected via K8s Secrets into environment variables following the
GH_pattern.
To explain this to the team, you need to highlight that we’ve moved from "Hardcoded Configuration" to "Dynamic Parameters." The SDK now acts as a smart proxy. It doesn't just hold values; it resolves them based on where the code is running. Here is the detailed breakdown of how we manage parameters in the CoreSettings system.
1. The Parameter Hierarchy (The "Resolution Chain")
When a developer calls settings.endpoints.VECTOR_SERVICE_URL, the SDK looks for the value in this specific order. The first one it finds wins.
| Priority | Source | Use Case |
|---|---|---|
| 1 (Highest) | Environment Variables | Injecting Secrets (DB Passwords) or emergency overrides. |
| 2 | Direct Code Initialization | Used mostly in unit tests to mock behavior. |
| 3 | Bundled JSON Profiles | The Backbone. Defines where internal services live in K8s. |
| 4 (Lowest) | Python Class Defaults | The safety net. Usually points to localhost. |
2. Parameter Grouping (The "Pillars")
We don't have a flat list of 50 variables. We group parameters into Pillars so the team can find what they need via autocompletion.
A. The service Pillar
Defines "Who am I?"
settings.service.name: Used for Logging and Jaeger/OTEL traces.settings.service.port: The port the internal server listens on.
B. The endpoints Pillar
Defines "Where is everyone else?"
- These are strictly URL strings.
- Note: We use
extra="allow"here. If you addNEW_AI_SERVICE_URLto the JSON, it is immediately available viasettings.endpoints.get("NEW_AI_SERVICE_URL")without needing an SDK code update.
C. The llm Pillar
Defines "How do I think?"
- Standardizes AI behavior across the fleet. If we decide
temperatureshould be0.2instead of0.1for the whole company, we change it here once.
3. Naming Convention for Overrides
To override a nested parameter via the environment (e.g., in a Dockerfile or K8s Manifest), we use the Double Underscore (__) convention.
Pattern: GH_[PILLAR]__[PARAMETER]
- To change the LLM model:
export GH_LLM__MODEL_NAME="gpt-4o" - To change the Vector URL:
export GH_ENDPOINTS__VECTOR_SERVICE_URL="http://custom-vector-db:8005" - To change Logging Level:
export GH_LOGGING__LEVEL="DEBUG"
4. How We Manage Secrets
Rule: No passwords or API Keys are ever stored in the config_*.json files.
The SDK defines the field in the LLMSettings or ServiceEndpoints class, but we leave the value as a placeholder. The team must map K8s Secrets to the corresponding GH_ environment variable:
# Kubernetes Deployment Example
env:
- name: GH_LLM__API_KEY
valueFrom:
secretKeyRef:
name: llm-secrets
key: api_key
5. Maintenance: Adding a New Parameter
If a service needs a new configuration parameter (e.g., RETRY_COUNT):
- Does it apply to everyone? Add it to
src/guardianhub/config/config_dev.jsonandconfig_kubernetes-dev.json. - Is it a new "Pillar"? Add a new
BaseModelclass insettings.py. - Is it just a URL? Just add it to the
endpointssection of the JSON files.
🛡️ Summary for the Team
"The SDK is the Backbone. The JSON files are the Maps. The Environment Variables are the Keys."
By following this, we ensure that if we move our entire infrastructure from AWS to Azure, or from one K8s namespace to another, we only update the JSON files in the SDK, and every microservice "teleports" to the new location on its next restart.
Would you like me to create a "Configuration Cheat Sheet" table that lists all current standard parameters and their default values for the team to print out?
🏗️ Contributing to the SDK
If you need to add a new shared client (e.g., Redis, S3) or a new endpoint:
- Add the endpoint to
src/guardianhub/config/config_*.json. - (Optional) Add a Pydantic model in
settings.pyif you want strict typing. - Bump the version using
./scripts/bump_version.sh. - Publish the new wheel.
Would you like me to generate a bootstrap_service.py script now, which your team can run to instantly generate a folder with this exact structure for a new microservice?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file guardianhub-0.1.157.tar.gz.
File metadata
- Download URL: guardianhub-0.1.157.tar.gz
- Upload date:
- Size: 86.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a778d7dde4b6f166995575b0945bd30749c5325c6d8723a7cf9fb1f5467ea16
|
|
| MD5 |
19754a9e13571b7b71eb947bd4effe84
|
|
| BLAKE2b-256 |
caa3328af6bc140b6d146e837cdadbbe28b54862a1109091ff166cbf7edc163c
|
Provenance
The following attestation bundles were made for guardianhub-0.1.157.tar.gz:
Publisher:
publish.yml on yantramai/guardianhub-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
guardianhub-0.1.157.tar.gz -
Subject digest:
6a778d7dde4b6f166995575b0945bd30749c5325c6d8723a7cf9fb1f5467ea16 - Sigstore transparency entry: 853605059
- Sigstore integration time:
-
Permalink:
yantramai/guardianhub-sdk@bd3816963b34b0b71134d3d7b4f276f8ee24ac31 -
Branch / Tag:
refs/tags/v0.1.157 - Owner: https://github.com/yantramai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bd3816963b34b0b71134d3d7b4f276f8ee24ac31 -
Trigger Event:
push
-
Statement type:
File details
Details for the file guardianhub-0.1.157-py3-none-any.whl.
File metadata
- Download URL: guardianhub-0.1.157-py3-none-any.whl
- Upload date:
- Size: 116.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b052947c34cbf0b09d9d4f524e5e5a5a09bd00c2476f3e3bbf4e0c0a47cf7606
|
|
| MD5 |
48361cb619d6455f81f7dc3b5250fe5b
|
|
| BLAKE2b-256 |
76502065ff2102451d33d936178fe9eedff75f6f21160eb00e0c8e4a77a20040
|
Provenance
The following attestation bundles were made for guardianhub-0.1.157-py3-none-any.whl:
Publisher:
publish.yml on yantramai/guardianhub-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
guardianhub-0.1.157-py3-none-any.whl -
Subject digest:
b052947c34cbf0b09d9d4f524e5e5a5a09bd00c2476f3e3bbf4e0c0a47cf7606 - Sigstore transparency entry: 853605126
- Sigstore integration time:
-
Permalink:
yantramai/guardianhub-sdk@bd3816963b34b0b71134d3d7b4f276f8ee24ac31 -
Branch / Tag:
refs/tags/v0.1.157 - Owner: https://github.com/yantramai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bd3816963b34b0b71134d3d7b4f276f8ee24ac31 -
Trigger Event:
push
-
Statement type: