Skip to main content

AGP Rust bindings for Python

Project description

Gateway Python Bindings

Bindings to call the gateway APIs from a python program.

Installation

pip install agp-bindings

For Windows, see section below

Include as dependency

With pyproject.toml

[project]
name = "agw-example"
version = "0.1.0"
description = "Python program using AGW"
requires-python = ">=3.9"
dependencies = [
    "agp-bindings>=0.1.0"
]

With poetry project

[tool.poetry]
name = "agw-example"
version = "0.1.0"
description = "Python program using AGW"

[tool.poetry.dependencies]
python = ">=3.9,<3.14"
agp-bindings = ">=0.1.0"

Example programs

Server

# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0

import argparse
import asyncio
from signal import SIGINT

import agp_bindings

# Create a service
gateway = agp_bindings.Gateway()


async def run_server(address: str):
    # init tracing with debug
    agp_bindings.init_tracing(log_level="debug")

    # Run as server
    await gateway.serve(address, insecure=True)


async def main():
    parser = argparse.ArgumentParser(
        description="Command line client for gateway server."
    )
    parser.add_argument(
        "-g", "--gateway", type=str, help="Gateway address.", default="127.0.0.1:12345"
    )

    args = parser.parse_args()

    # Create an asyncio event to keep the loop running until interrupted
    stop_event = asyncio.Event()

    # Define a shutdown handler to set the event when interrupted
    def shutdown():
        print("\nShutting down...")
        stop_event.set()

    # Register the shutdown handler for SIGINT
    loop = asyncio.get_running_loop()
    loop.add_signal_handler(SIGINT, shutdown)

    # Run the client task
    client_task = asyncio.create_task(run_server(args.gateway))

    # Wait until the stop event is set
    await stop_event.wait()

    # Cancel the client task
    client_task.cancel()
    try:
        await client_task
    except asyncio.CancelledError:
        pass


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("Program terminated by user.")

Client

# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0

import argparse
import asyncio
import time

import agp_bindings


class color:
    PURPLE = "\033[95m"
    CYAN = "\033[96m"
    DARKCYAN = "\033[36m"
    BLUE = "\033[94m"
    GREEN = "\033[92m"
    YELLOW = "\033[93m"
    RED = "\033[91m"
    BOLD = "\033[1m"
    UNDERLINE = "\033[4m"
    END = "\033[0m"


def format_message(message1, message2):
    return f"{color.BOLD}{color.CYAN}{message1.capitalize()}{color.END}\t {message2}"


async def run_client(local_id, remote_id, message, address):
    # init tracing
    agp_bindings.init_tracing()

    # Split the IDs into their respective components
    try:
        local_organization, local_namespace, local_agent = local_id.split("/")
    except ValueError:
        print("Error: IDs must be in the format organization/namespace/agent.")
        return

    # Define the service based on the local agent
    gateway = agp_bindings.Gateway()

    # Connect to the gateway server
    local_agent_id = await gateway.create_agent(
        local_organization, local_namespace, local_agent
    )

    # Connect to the service and subscribe for the local name
    _ = await gateway.connect(address, insecure=True)
    await gateway.subscribe(
        local_organization, local_namespace, local_agent, local_agent_id
    )

    if message:
        # Split the IDs into their respective components
        try:
            remote_organization, remote_namespace, remote_agent = remote_id.split("/")
        except ValueError:
            print("Error: IDs must be in the format organization/namespace/agent.")
            return

        # Create a route to the remote ID
        await gateway.set_route(remote_organization, remote_namespace, remote_agent)

        # Send the message
        await gateway.publish(
            message.encode(), remote_organization, remote_namespace, remote_agent
        )
        print(format_message(f"{local_agent.capitalize()} sent:", message))

        # Wait for a reply
        src, msg = await gateway.receive()
        print(format_message(f"{local_agent.capitalize()} received:", msg.decode()))
    else:
        # Wait for a message and reply in a loop
        while True:
            src, msg = await gateway.receive()
            print(format_message(f"{local_agent.capitalize()} received:", msg.decode()))

            ret = f"Echo from {local_agent}: {msg.decode()}"

            await gateway.publish_to(ret.encode(), src)
            print(format_message(f"{local_agent.capitalize()} replies:", ret))


def main():
    parser = argparse.ArgumentParser(
        description="Command line client for message passing."
    )
    parser.add_argument(
        "-l",
        "--local",
        type=str,
        help="Local ID in the format organization/namespace/agent.",
    )
    parser.add_argument(
        "-r",
        "--remote",
        type=str,
        help="Remote ID in the format organization/namespace/agent.",
    )
    parser.add_argument("-m", "--message", type=str, help="Message to send.")
    parser.add_argument(
        "-g",
        "--gateway",
        type=str,
        help="Gateway address.",
        default="http://127.0.0.1:12345",
    )

    args = parser.parse_args()

    # Run the client with the specified local ID, remote ID, and optional message
    asyncio.run(run_client(args.local, args.remote, args.message, args.gateway))


if __name__ == "__main__":
    main()

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

agp_bindings-0.1.13.tar.gz (124.8 kB view details)

Uploaded Source

Built Distributions

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

agp_bindings-0.1.13-cp313-cp313-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.13Windows x86-64

agp_bindings-0.1.13-cp313-cp313-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.13-cp313-cp313-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.13-cp313-cp313-macosx_10_12_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

agp_bindings-0.1.13-cp312-cp312-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.13-cp312-cp312-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.13-cp312-cp312-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.13-cp312-cp312-macosx_10_12_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

agp_bindings-0.1.13-cp311-cp311-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.13-cp311-cp311-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.13-cp311-cp311-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.13-cp311-cp311-macosx_10_12_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

agp_bindings-0.1.13-cp310-cp310-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.13-cp310-cp310-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.13-cp310-cp310-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.13-cp310-cp310-macosx_10_12_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

agp_bindings-0.1.13-cp39-cp39-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.13-cp39-cp39-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.13-cp39-cp39-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

agp_bindings-0.1.13-cp39-cp39-macosx_10_12_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

File details

Details for the file agp_bindings-0.1.13.tar.gz.

File metadata

  • Download URL: agp_bindings-0.1.13.tar.gz
  • Upload date:
  • Size: 124.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agp_bindings-0.1.13.tar.gz
Algorithm Hash digest
SHA256 fcb0d6ed5cbdb9298dad38e7b97d9b1aa74d68bbd405b7d26ab86a4c8c212a85
MD5 e2b2a3e36c0c6f7da93f92abbcdc774f
BLAKE2b-256 ec21e6ac981e9bf18b39448e4eef0ce8cc3a6a3840fb449331e417628bc65189

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 40417da049b700a3334ce5c9743096224f52ef56cf536ee29119191bac87e4fc
MD5 c39192c6e0bfd30fbd463edf6935ad1b
BLAKE2b-256 430a8ab652fd274ce3343255ed2f6bf1fff839893df166cbbf581caf54a05901

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp313-cp313-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 77e75958c17ca7ba0e8e8b3a7c9653542b2d1ff3bd9eea509adfff27236c3e41
MD5 cd6ed0f21033daffc97e367b6873343b
BLAKE2b-256 3022a63bfe7f904b04821d89ef5d7ca4a7a364407e886de8a1a04e470b901d58

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1324d90f4e61cb0508b68b9928c0564f109a9b8f8c0e765db4482854552455a3
MD5 1b6f82bd23c781299468d0e8c91f5617
BLAKE2b-256 4bef9f3f5e9a96685154a4ffd5e7c636777ec824ef0b70faeae9aaef081bc0ce

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f5e798c58d35e487f7335e96f4247c7576ffb5fc4457718754a3ee8b0733a322
MD5 1e3a34a4d074a5bb6b71abc63055a216
BLAKE2b-256 9de6c39ae3656e99c3f20ef8f512bec3dd8b9d8f10fd66c03e2aeaf90984ff5c

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c30f0e1f14200e3b50f46ab5753ca712c76c08d967bbc1fa9adaa407c3adc469
MD5 4bab131d83242c5cf7c60c47a2f1f4de
BLAKE2b-256 8a51594639f11377b65a376255220c0b7887beaeccfdcd1c10d45a5c9d5f79ec

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d539a4615d5d7905830b354e55310d107951f505b8f3d6c604970f4ba47b8ef8
MD5 f22ffd90b9b692d0b9f99d6618036258
BLAKE2b-256 9b29ddf6d400724355fdf954d5a0e9dde634cd900ff0a4205031f8bcb5f994fb

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1689dcda171f7bc21e9ff4cca0c41f82a20557aadeb4610568daeba66a48518e
MD5 9896ec71e805418a3bc7d136d943c119
BLAKE2b-256 a233ca6f28dd573b7bab70a6f160f697a435d015b248465b11e90a0ae3ee6204

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 351a0b3670037e5b5ea2bf75e5c83ded3024f3e3cb9611945717d9a67d2d789e
MD5 9f4cd9378eb1f618b6afa89aeb99f9b1
BLAKE2b-256 504d7be7ccc7d7bcf368c660e7008b62e7b28beede4b0c122c364118f618cbde

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3dd68e03e5efaf189a3bd04fedeb2816c5f6b580cda12dc42e06202beea83901
MD5 4b831161d044c109c0a5d2c5b8cba2ac
BLAKE2b-256 645c53689d743bde4dc317efa16fa003702567b1cd913727810719ea23ad6b17

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp311-cp311-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 34588c1fee52e8f0dfd17bc2b1b0454da06f983cc368354dfd2248d53939da0e
MD5 b2589d6387c2864b09f8a82531c1eec6
BLAKE2b-256 a3329ec37cd7ab7f5f80ef9b846a308217c7fa6681c6a65163b3af4bfdf67d28

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 641f6edbd78229a621a9e7fb65b92a5129631121de390867994b65a7cce2ccd9
MD5 25cb21eacdee95d963196549f63962b0
BLAKE2b-256 12899211a57f8563869452db7ca48c3665d6a677d5c8c7e659d05d51fd18a0fd

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dee95a990161680a7437d27cd317aebdde2293f50ea02b3b3283760c91a197a0
MD5 5cccac5cab072698e34413617cfb0ca7
BLAKE2b-256 eec04962d3c024213f25ac98888da91685dfa1899b89d611d66950279c13e6fe

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7a3976c7fcb39da62c39222f75e26b33a10d0b6b9ef9a8b4deda5a9e4f52bbae
MD5 cb2dc100812ac83d59642a058e69ab23
BLAKE2b-256 171da332000b56d6f80661529606ed7ab83198d99c37956f6857226f4977dc58

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp310-cp310-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d1bc247bfb056b7f46c2263eec2e6eb79699888af6b67213cbfc590dcc0a6f41
MD5 c5fb052e9b4a0aac1738a3b031f05efd
BLAKE2b-256 7a9f81857b51037972fc1820ef70dfebd57a1aa2fa1e99708ab3e0dfadb038fa

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a470b5a2990e5a5347b15a4760a8b01ee6ae7606c019c8695e2151fa65bac42
MD5 eed5b2f8dc8a8779ecac9c710b59cd4d
BLAKE2b-256 fd6e162f6ce63ebaf824c2cd017072fd4c362d7d31adacd129d2a5691bdc9192

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9022ff79aad81f93a98abcd0753a1b1ca2bdec53087d0bd736f365024cae9572
MD5 d887e59e35d2bb3c1c86328309ea9e34
BLAKE2b-256 0b95d2e92892b8e39d1cdc7d3cc49f352cabc5ffbcc34368b16c28c311d1b69b

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2f2c8c1b4c9ff4b75ae36476a041dedc10bcca57defd1953c2958357f9655101
MD5 20aaa16bd6813ca06b91da8e0cbf5a45
BLAKE2b-256 9c177b2b1f9b141c8885408cc9abafe627f308848652e8e0698aed0a7fdf40cd

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp39-cp39-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 8efca0726c0c0380525293f91683a52e12d6abab09fd8c49802178a7ba55ee8c
MD5 7055e65a717391a39274f30bb87a7bd9
BLAKE2b-256 6936bbdcc2998e16914479d0236f98fd51912be97d5cfe2e8ac1b2c353b75993

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 22b1c88cda5ca972256f22856b29cbf574b3f6b4e8f713460f4cb8ee74abefd8
MD5 5fe5713a21d0cfdcfd24e8f6715950c8
BLAKE2b-256 90a3f89bc931e7c40c8d97964eead84cd427e06b8835342b637a39113e7b6271

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.13-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.13-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c764e27a044356f38356efa0d81c6a43ba579105a487c0eb90f668c0100c799
MD5 9781815b325e9cfc7c9c586aa91291dc
BLAKE2b-256 78aa9b3a5daa17fe0438472b60c367c660a0394c19e090be77dd2a11c5adfbbd

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