Skip to main content

Directory Python SDK

Overview

Dir Python SDK provides a simple way to interact with the Directory API. It allows developers to integrate and use Directory functionality from their Python applications with ease.

Features

The Directory Python SDK provides comprehensive access to all Directory APIs with a simple, intuitive interface:

Store API

  • Record Management: Push records to the store and pull them by reference
  • Metadata Operations: Look up record metadata without downloading full content
  • Data Lifecycle: Delete records permanently from the store
  • Referrer Support: Push and pull artifacts for existing records
  • Sync Management: Manage storage synchronization policies between Directory servers

Search API

  • Flexible Search: Search stored records using text, semantic, and structured queries
  • Advanced Filtering: Filter results by metadata, content type, and other criteria

Routing API

  • Network Publishing: Publish records to make them discoverable across the network
  • Content Discovery: List and query published records across the network
  • Network Management: Unpublish records to remove them from network discovery

Signing and Verification

  • Local Signing: Sign records locally using private keys or OIDC-based authentication. Requires dirctl binary to perform signing.
  • Remote Verification: Verify record signatures using the Directory gRPC API

Developer Experience

  • Type Safety: Full type hints for better IDE support and fewer runtime errors
  • Async Support: Non-blocking operations with streaming responses for large datasets
  • Error Handling: Comprehensive gRPC error handling with detailed error messages
  • Configuration: Flexible configuration via environment variables or direct instantiation

Installation

Install the SDK using uv

  1. Initialize the project:
uv init
  1. Add the SDK to your project:
uv add agntcy-dir --index https://buf.build/gen/python

Configuration

The SDK can be configured via environment variables or direct instantiation:

# Environment variables
export DIRECTORY_CLIENT_SERVER_ADDRESS="localhost:8888"
export DIRCTL_PATH="/path/to/dirctl"

# Or configure directly
from agntcy.dir_sdk.client import Config, Client

config = Config(
    server_address="localhost:8888",
    dirctl_path="/usr/local/bin/dirctl",
    spiffe_socket_path="/tmp/agent.sock" # Optional, used for SPIRE-based mTLS
)
client = Client(config)

Error Handling

The SDK primarily raises grpc.RpcError exceptions for gRPC communication issues and RuntimeError for configuration problems:

import grpc
from agntcy.dir_sdk.client import Client

try:
    client = Client()
    records = client.list(list_request)
except grpc.RpcError as e:
    # Handle gRPC errors
    if e.code() == grpc.StatusCode.NOT_FOUND:
        print("Resource not found")
    elif e.code() == grpc.StatusCode.UNAVAILABLE:
        print("Server unavailable")
    else:
        print(f"gRPC error: {e.details()}")
except RuntimeError as e:
    # Handle configuration or subprocess errors
    print(f"Runtime error: {e}")

Common gRPC status codes:

  • NOT_FOUND: Resource doesn't exist
  • ALREADY_EXISTS: Resource already exists
  • UNAVAILABLE: Server is down or unreachable
  • PERMISSION_DENIED: Authentication/authorization failure
  • INVALID_ARGUMENT: Invalid request parameters

Getting Started

Prerequisites

  • Python 3.10 or higher
  • uv - Package manager
  • dirctl - Directory CLI binary
  • Directory server instance (see setup below)

1. Server Setup

Option A: Local Development Server

# Clone the repository and start the server using Taskfile
task server:start

Option B: Custom Server

# Set your Directory server address
export DIRECTORY_CLIENT_SERVER_ADDRESS="your-server:8888"

2. SDK Installation

# Add the Directory SDK
uv add agntcy-dir --index https://buf.build/gen/python

Usage Examples

See the Example Python Project for a complete working example that demonstrates all SDK features.

uv sync
uv run example.py

Metadata

Release files for agntcy-dir 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agntcy-dir 0.3.0
File Size Uploaded
agntcy_dir-0.3.0.tar.gz 34.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agntcy-dir 0.3.0
File Interpreter ABI Platform
agntcy_dir-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.9 kB

Release files / agntcy_dir-0.3.0.tar.gz

Download URL agntcy_dir-0.3.0.tar.gz
Size 34.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2b17c0519c15872a18c02b3d5ca594ef1165d0250937edecc6923f8323026739
BLAKE2b-256 checksum
How to use checksums
a61ca9368a87450880ec51affa1cdc275b7320c5c637581f8a97c517dae6b782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.1

Release files / agntcy_dir-0.3.0-py3-none-any.whl

Download URL agntcy_dir-0.3.0-py3-none-any.whl
Size 43.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a62095a087e965aa7cd5d66154c411a8594ecf529ce7176eeeea252488748497
BLAKE2b-256 checksum
How to use checksums
1f3b433e88834786452199cc6f4c1d4b713ff2e32c114bc771b46a2df55b924a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page