Skip to main content

Directory client SDK

Project description

directory API python SDK

Overview

The directory API python SDK provides a simple and efficient way to interact with the directory API. It allows developers to integrate directory functionality into their Python applications with ease.

Features

  • Store API: The SDK includes a store API that allows developers to push the agent data model to the store and retrieve it from the store.
  • Routing API: The SDK provides a routing API that allows developers to publish and retrieve agents to and from the network.

Installation

Install the SDK using uv

init the project:

uv init

add the SDK to your project:

uv add agntcy-dir-sdk --index https://buf.build/gen/Python

Usage

Starting the Directory Server

To start the Directory server, you can deploy your instance or use Taskfile as below.

task server:start

Initializing the Client

import io
import hashlib
import json
from google.protobuf.json_format import MessageToDict
from client.client import Client, Config
from core.v1 import object_pb2, agent_pb2, skill_pb2, extension_pb2
from routing.v1 import routing_service_pb2 as routingv1

# Initialize the client
client = Client(Config())

Creating and Pushing an Agent Object

# Create an agent object
agent = agent_pb2.Agent(
    name="example-agent",
    version="v1",
    skills=[
        skill_pb2.Skill(
            category_name="Natural Language Processing",
            category_uid="1",
            class_name="Text Completion",
            class_uid="10201",
        ),
    ],
    extensions=[
        extension_pb2.Extension(
            name="schema.oasf.agntcy.org/domains/domain-1",
            version="v1",
        )
    ]
)

agent_dict = MessageToDict(agent, preserving_proto_field_name=True)

# Convert the agent object to a JSON string
agent_json = json.dumps(agent_dict).encode('utf-8')
print(agent_json)

# Create a reference for the object
ref = object_pb2.ObjectRef(
    digest="sha256:" + hashlib.sha256(agent_json).hexdigest(),
    type=object_pb2.ObjectType.Name(object_pb2.ObjectType.OBJECT_TYPE_AGENT),
    size=len(agent_json),
    annotations=agent.annotations,
)

# Push the object to the store
data_stream = io.BytesIO(agent_json)
response = client.push(ref, data_stream)
print("Pushed object:", response)

Pulling the Object

# Pull the object from the store
data_stream = client.pull(ref)

# Deserialize the data
pulled_agent_json = data_stream.getvalue().decode('utf-8')
print("Pulled object data:", pulled_agent_json)

Looking Up the Object

# Lookup the object
metadata = client.lookup(ref)
print("Object metadata:", metadata)

Publishing the Object

# Publish the object
client.publish(ref, network=False)
print("Object published.")

Listing Objects in the Store

# List objects in the store
list_request = routingv1.ListRequest(
    labels=["/skills/Natural Language Processing/Text Completion"]
)
objects = list(client.list(list_request))
print("Listed objects:", objects)

Unpublishing the Object

# Unpublish the object
client.unpublish(ref, network=False)
print("Object unpublished.")

Deleting the Object

# Delete the object
client.delete(ref)
print("Object deleted.")

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

agntcy_dir_sdk-0.1.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

agntcy_dir_sdk-0.1.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file agntcy_dir_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: agntcy_dir_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.1

File hashes

Hashes for agntcy_dir_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 dea90a2dfdc5a7f8416be113a59f78b7329bf4c3052330afe28e70c542ca4a82
MD5 07745eaba76cb599ceb4663ad8830f44
BLAKE2b-256 49f57a4e55a3618c9074bde65e509d6bd630e46fa4d721838ee6c3b6a62f9630

See more details on using hashes here.

File details

Details for the file agntcy_dir_sdk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for agntcy_dir_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 35d56d0f81efd7b8013e2696e35adb0ecb110262669dfa3d4d3effdfa3ba3b2c
MD5 89b2896403d24d9afe059454dcfb1e37
BLAKE2b-256 b61365ec77136f4cd5af5459096bdaf40ae344ec8e5dd7c9b0905d0d01b762e2

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