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.v1alpha1 import object_pb2, agent_pb2, skill_pb2, extension_pb2
from routing.v1alpha1 import routing_service_pb2 as routingtypes
# 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 = routingtypes.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
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 agntcy_dir_sdk-0.1.2.tar.gz.
File metadata
- Download URL: agntcy_dir_sdk-0.1.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aff432a57badb0801f397d1a30db1ad0fad4dbf85ae158135201f1615da34b7
|
|
| MD5 |
e8ede1a42f52b56c80df878dd8268914
|
|
| BLAKE2b-256 |
1036db9dbd0a1d6ddfe470d896108c1c84bb85966c48e388bfe705279f9a88e3
|
File details
Details for the file agntcy_dir_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: agntcy_dir_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a575ce7b3c405accc944d73e55af83c0b7d1976cc9c622f85ce14bb5b1e09dc
|
|
| MD5 |
174ba9b633db51fb683bfddd3aca217b
|
|
| BLAKE2b-256 |
ba40715701d995252804f3d7637b55124f1136c4b94cb8e1db45602cf4cd3c00
|