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

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
    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.2.tar.gz (109.6 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.2-cp313-cp313-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.2-cp312-cp312-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.2-cp312-cp312-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.2-cp311-cp311-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.2-cp311-cp311-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.2-cp310-cp310-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.2-cp310-cp310-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.2-cp39-cp39-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.2-cp39-cp39-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.2-cp39-cp39-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for agp_bindings-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a909db479ae57b24d5cf4c72c404c8f53b8e94598efa53a52874d2b97b5d4701
MD5 f0fd799bef6f2d6e5a59ca28e75e411b
BLAKE2b-256 5219dd83d185edc14e4b831e6ebc81c801bf37841ec2cfbae4ea37630514b654

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b6bfbd76db7b6813ef2fdda8b9b52f9a4b59483ae9d17880a1186c9d0b5c3aa9
MD5 7b6498a3789cb8e3fc73532662c3fb66
BLAKE2b-256 12bbbbe296bd7b815924fe028914ed203644238adc2996dbe449403d15db4d90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c04718475d49e5bdc225597cf3021f673bc3721ec73822a96da29499fb6ea95
MD5 09cfb567359fcbb0c537578eaee6f5bb
BLAKE2b-256 5088e8ba1da1ad2b0d752e082dd52b6e9f90f242c70292826f6c4d4df1c679c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4e046f50d4697afaacbc4c5089380e371e396c9a8dff0c1d9a9f6289bd2afe14
MD5 a06a72e04d54caf9dccd2407cc666a9a
BLAKE2b-256 20b49541c87707de4807d1f79267f1cc5c09eb3d7ff0c670fdeb0ebbfcd1ffe3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 e93d673d7652b6c9cd4b3dfac83811159d29f0b1c0832ad0b65dfd12ebf8e2b9
MD5 fd5b7a029b9dcc7cfa01209488d27c2d
BLAKE2b-256 ec6d2c783007a03eab8d4919d5439cdac781f9446119eff5b1a305b27c269a04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a71d89f312be619953fa665c88e4d56a2366eeb4a910b9ec09af6b084f54a63
MD5 482d0f595c68543c4241ecaa499c747b
BLAKE2b-256 6b7974d97e1f413863ff2b3e3e15ce4c0f7b681b32bb9c0fff0c84b28f16a5fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1bb7bfbaec019031c801688087428985c35213c5375f89594261ad82b34b080f
MD5 ce56ab2743b0d5a859a05c4418609fe9
BLAKE2b-256 e516598b38327420d9b24c3a5b872c9f443ef030f1bf7997bb50e41c847f35be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d159b1a93e314dec61ee5772157d79a0d3fc816be383fe3e82a126fd73d5ad90
MD5 7d1e6b59cb202f4354225667fcde3d01
BLAKE2b-256 894b2e756c5969ba74b0851102604adb05cf8269147586c48aeb21fed7382bf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3168f9c74da4ece997a891409401029734df1007744944398d8f7202ceb2c5d
MD5 9d210d6f6af645aadc3ce8ae3b873c39
BLAKE2b-256 d85250badfac3ce8190d6d70f3e3b8b73741da2ec040dedcb5b023645fbd7bea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ccf1862067cd1ba7c7a734b8295580d7fd9531ad1219867368830950f2ade91d
MD5 fa6d3bd0760f1898c84ac98d82dcbb14
BLAKE2b-256 8cb6717dfa880f93bf21e6a67f1e553823d3831b4e5e6619423890f49abd0ab6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 14ff7f229c6c0f729b706b815fc1984139890a07f1beec13f37eb024640738c7
MD5 bb44c4db9a59d2b2f7d2c4282d480f33
BLAKE2b-256 0fd74f5806463dda03ea9818c6588706692139e010a01c7af82f4675c1fd2f93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51c05eada688b8389f7f3f77f980f7d0d1ddecc0f3e994a0bc8380dade79b149
MD5 c1dd9c4098bed12f5f9bc8494bf3a903
BLAKE2b-256 a3aa98e298d25ab56fb3baa5dcdd6cf5db5298072b36d663a21e03a670a2a79c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for agp_bindings-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e29f0d1435a2aaaf8f2e07d91438208ee68d887b1a1e5825552b2b2605d1972a
MD5 8aa46e02a64bf88c485c8ba4fa20a2de
BLAKE2b-256 6f634399f9c9ae64451eb809e14114f167d2a6c93362629f5bc9a966df56935f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 2ea75b71f9b64566d880a0b46d813379e0002e3d2f5836d062e42e6b6f91eac0
MD5 9a447d10fb41ff2237a85c82253d252c
BLAKE2b-256 3b622702a957ff4416cbd1e3b1082fc894efe7e6a24ce9b2b86cf7f64a1736c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a0f754d35e59d3758644554782d76ffc088653cf9c1becbe3c2f948d1ee69c13
MD5 065623f7391cfed90a675896daea6e05
BLAKE2b-256 41f301cab2a38060e7ef28517cbfb84159d8575863e680832f812e6857eb0b5c

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