Skip to main content

Official Python SDK for the Intelligence Builder API

Project description

Intelligence Builder SDK

Official Python SDK for the Intelligence Builder API. This SDK provides a fully-featured async client for building knowledge graphs, semantic search, and AI-powered query capabilities.

Installation

pip install intelligence-builder-sdk

Quick Start

import asyncio
from intelligence_builder_sdk import IntelligenceBuilderClient, ClientConfig

async def main():
    # Configure the client
    config = ClientConfig(
        base_url="http://localhost:8100",
        api_key="your-api-key",  # pragma: allowlist secret
        timeout=30,
        max_retries=3,
    )

    # Create and connect the client
    client = IntelligenceBuilderClient(config)
    await client.connect()

    try:
        # Create an entity
        entity = await client.create_entity({
            "entity_type": "aws_resource",
            "name": "prod-ec2-instance",
            "description": "Production EC2 instance",
            "metadata": {
                "region": "us-east-1",
                "instance_type": "t3.large",
            },
            "tags": ["aws", "ec2", "production"],
        })
        print(f"Created entity: {entity.entity_id}")

        # Query the knowledge graph
        response = await client.query(
            query="What are the dependencies for my production EC2 instance?",
            context={"domain": "cloud_optimizer"},
        )
        print(f"Answer: {response.answer}")

    finally:
        await client.disconnect()

asyncio.run(main())

Features

Authentication

  • API key-based authentication with automatic JWT token management
  • Token refresh on expiry

Entity Management

  • create_entity() - Create a new entity in the knowledge graph
  • create_entities_batch() - Batch create multiple entities
  • get_entity() - Retrieve an entity by ID
  • list_entities() - List entities with pagination and filtering
  • search_entities() - Semantic search across entities

Relationship Management

  • create_relationship() - Create relationships between entities
  • create_relationships_batch() - Batch create relationships
  • get_relationship() - Retrieve a relationship by ID
  • list_relationships() - List relationships with filtering
  • get_entity_relationships() - Get all relationships for an entity

Graph Operations

  • traverse_graph() - Traverse the knowledge graph from a starting entity
  • find_shortest_path() - Find the shortest path between two entities
  • find_all_paths() - Find all paths between entities
  • get_subgraph() - Extract a subgraph around an entity
  • get_entity_neighbors() - Get immediate neighbors of an entity

Query & Search

  • query() - Intelligent queries with context awareness
  • search_graph() - Semantic search across the knowledge graph

Document Ingestion

  • ingest_document() - Ingest documents for knowledge extraction

Reliability Features

  • Circuit Breaker: Automatic failure detection and recovery
  • Retry Logic: Configurable retry with exponential backoff
  • Response Caching: Memory, Redis, or file-based caching
  • Rate Limiting: Handles rate limit responses with retry-after

Configuration

from intelligence_builder_sdk import ClientConfig

config = ClientConfig(
    # Required
    base_url="http://localhost:8100",
    api_key="your-api-key",  # pragma: allowlist secret

    # Timeouts
    timeout=30,  # Request timeout in seconds

    # Retry Configuration
    max_retries=3,  # Maximum retry attempts

    # Caching
    enable_caching=True,
    cache_ttl=300,  # Cache TTL in seconds
    cache_backend="memory",  # Options: memory, redis, file
    redis_url="redis://localhost:6379/0",  # Required if cache_backend="redis"

    # Circuit Breaker
    enable_circuit_breaker=True,
    circuit_breaker_threshold=5,  # Failures before opening
    circuit_breaker_timeout=60,  # Timeout before attempting recovery
)

Exception Handling

from intelligence_builder_sdk import (
    IntelligenceBuilderError,
    AuthenticationError,
    RateLimitError,
    ServiceUnavailableError,
    ValidationError,
    CircuitBreakerOpenError,
)

try:
    response = await client.query("my query")
except AuthenticationError:
    print("Invalid API key or token expired")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except ServiceUnavailableError:
    print("Service temporarily unavailable")
except ValidationError:
    print("Invalid request parameters")
except CircuitBreakerOpenError:
    print("Circuit breaker is open - too many failures")
except IntelligenceBuilderError:
    print("General SDK error")

Context Manager Support

async with IntelligenceBuilderClient(config) as client:
    entity = await client.create_entity({...})

Models

Entity

from intelligence_builder_sdk import Entity

entity: Entity
print(entity.entity_id)  # UUID
print(entity.name)
print(entity.entity_type)
print(entity.description)
print(entity.metadata)  # Dict[str, Any]
print(entity.tags)  # List[str]
print(entity.created_at)  # datetime

Relationship

from intelligence_builder_sdk import Relationship

rel: Relationship
print(rel.relationship_id)  # UUID
print(rel.from_entity_id)
print(rel.to_entity_id)
print(rel.relationship_type)
print(rel.weight)  # float 0.0-1.0
print(rel.confidence)  # float 0.0-1.0
print(rel.properties)  # Dict[str, Any]

GraphPath

from intelligence_builder_sdk import GraphPath

path: GraphPath
print(path.entities)  # List[UUID]
print(path.relationships)  # List[UUID]
print(path.total_weight)  # float
print(path.length)  # int

Requirements

  • Python 3.9+
  • httpx
  • pydantic
  • pybreaker
  • cachetools

License

MIT License - Copyright 2025 Intelligence Builder

Links

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

intelligence_builder_sdk-1.0.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

intelligence_builder_sdk-1.0.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file intelligence_builder_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: intelligence_builder_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for intelligence_builder_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 becea08012a14af05d5675e5c0d59366f36f91f6c485be2b732b48e94d6f6be3
MD5 4728aabe7bd48580e55a9564ef9b0db1
BLAKE2b-256 5048817fb6d9356c0577222d6c2caf6394ccd9f84242536a58c852136ad892a9

See more details on using hashes here.

File details

Details for the file intelligence_builder_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for intelligence_builder_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53b4e6cc026cabd73c9c8d0a0dddcafd03a7d490c1bd2b11f56b2dee4f52247e
MD5 ce45e28d66eaf99913913f21d9327454
BLAKE2b-256 6510fc009d65f0fbfea627f985e945c755c94ce4bb7aea59d86fa47659773ece

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