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 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.7.tar.gz (114.0 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.7-cp313-cp313-manylinux_2_38_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.7-cp313-cp313-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.7-cp313-cp313-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.7-cp312-cp312-win_amd64.whl (8.6 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.7-cp312-cp312-manylinux_2_38_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.7-cp312-cp312-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.7-cp312-cp312-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.7-cp311-cp311-win_amd64.whl (8.6 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.7-cp311-cp311-manylinux_2_38_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.7-cp311-cp311-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.7-cp311-cp311-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.7-cp310-cp310-win_amd64.whl (8.6 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.7-cp310-cp310-manylinux_2_38_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.7-cp310-cp310-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.7-cp310-cp310-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.7-cp39-cp39-win_amd64.whl (8.6 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.7-cp39-cp39-manylinux_2_38_x86_64.whl (5.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.7-cp39-cp39-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.7-cp39-cp39-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: agp_bindings-0.1.7.tar.gz
  • Upload date:
  • Size: 114.0 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.7.tar.gz
Algorithm Hash digest
SHA256 9db99c81821f0b267113fa84ed659508f6f16a823922acfe2e4f67395c3bd3b7
MD5 6967d655bbfa1138c668ce5d5fe26cd2
BLAKE2b-256 6c9f083ce6d8bcf45041652ed4af9d9758c45c7dcc756339bbc6ea2f796b9cff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 3367fa4d56105a1cdda2fbfb923f098801bdedff1bf99a9921623deed366707f
MD5 51933597c14f6b18e9a4989cdd0bf158
BLAKE2b-256 e66e0fed73a4dc7cc0feef915567dcf78d320e1588cc21d3d7c92cccc8e1880c

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.7-cp313-cp313-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 e128b08d46aa91a416162c8cb54fb2d748a220f488e4cad6bd8caa366881d64c
MD5 a5ccac8e61dd499c00675790f21a1c31
BLAKE2b-256 22e276041a1802370427258e12d4dfb2648574d53a19fc149c356deb7416c28b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b0c05266ef412877e6f3b4553d7efa69cd7d856bcb2c694ba415b51c1020155
MD5 82f59492f3d8d3a49c6ccb6c69ec37c4
BLAKE2b-256 69f486903a617e718b9907c001578ec6a003fc51ad9dfc7efc4de496d69eb9af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2325351968690e511875c418be751b9affad7a1d98bfcbde51af0852a0cfdd37
MD5 b0751977c9e5d617f27bcef07182c0fa
BLAKE2b-256 e7abcb84313acf241e33a0498f2447359a71afa96db064748892af8c56a338df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 5fc38cdf4a35ceb3dca24dd875b249b490ddb4271b792b76cf419b4c1b4f421f
MD5 9747132f9d4870b2779880133f7ca4a3
BLAKE2b-256 e4b0ceca714828c9ac445e237fb565a53cb4bd89d1bff1e5fa120d13abddf9bf

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.7-cp312-cp312-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp312-cp312-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 ace357af1a5054f67801c22a26658effdb639e9ed8061d6a1a31eb82321e3fdf
MD5 d118fec7874be053e9b2e08982d43e4d
BLAKE2b-256 90a0bb34844c0492aea08f67a9a119a37ddd6ec2cfc283a1fa1247215d3b7597

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac379fc6462e40bfd7ea4257de08de301bf6ee2f2ae066cce3d940747b4f6878
MD5 6b7f780154edc7c8f0c9b956b325eb90
BLAKE2b-256 dfc42654955db1bf53fd30f5e767a8d444298c9091789795ef607683c8be27e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 81527fb56192d1c8fbbd2e9e33f833459bcbdd7c9ec2305315d011f4e30ddb2c
MD5 cd0e0e57c7a3ec524c74149f69f4854e
BLAKE2b-256 f241945e51cbd7e9578de6e97d2c19aed61a63d4cc79a49d9bbc51c1b9662e72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 c75bd6b885ec9ca8afc71f22a2816cee70e848283bf77891ec58545b3561d523
MD5 52cbd216d8045ab39cf38e754c232337
BLAKE2b-256 01a9df55069f04b2f0e345014a4aa11513accc12cdf897776ec46584dc3a4fb7

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.7-cp311-cp311-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp311-cp311-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 52f196a88840add40adb27e749d6a2bc74144a75719f4fd936f7b9fc5c33bdca
MD5 22b3eb9983cd4eb9e9451d580021da06
BLAKE2b-256 67bb46b9d0b04aedd829852493fdd0c25cc188081d30a8c98b50189ec414b7a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1586c335fe052e5f527d5f248cb0e2808082869ccfb5e30f1588a5fab4e21e22
MD5 1c2613c2db27327f043215ff3f79bcb3
BLAKE2b-256 fa3dcb570af4d618fd26c379a651a077ed07e243d8a46709a22c9c27f18bd4a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2838c481cb21b87c9655f230005f92d34effc089d7db59cc0c4b028b2bbd2804
MD5 99ff9000b1170c79b9d1b96bd480658f
BLAKE2b-256 cb1474252cbc04cec6c41c2723f9115c2896d6d9264f60e9f1e0e6859196d18d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 4d6a8eacc4b0300cbddda62a9078d75f5a6d1e27470b6e93620e7983c43b3da4
MD5 b3ad8e9b3ab9228dcb629efbc9ba6da4
BLAKE2b-256 f383afd41997d3baf29d362694b95cf6bda556bfb30ca252287236d57979a02d

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.7-cp310-cp310-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp310-cp310-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 b41900c86b28eaf0041949491570464b304628a5a7cebac7ff129e15c415b4bf
MD5 cb15a830c8f48f7c087596530c42c889
BLAKE2b-256 45ad4a766d6eda3a7346faebdb32e6dfc11940a2305740eab0fd5980ae0b2427

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 645667a05619be6211ce3fd2010ccfcd309f0389503473077bb4746cfd8cf56d
MD5 a23581783b4d505edffedfb217a318d9
BLAKE2b-256 4e97f50f3663f3f5eae0af5d847e901fdb8b841206ec1cf8c56669774d2f8966

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.7-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.6 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.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b112c98e9cb2f8d6af95fc41833a23a9f4fb0f676cf7370111b9c28d847a98b5
MD5 919315c00eda1886d262ec5fc4c69fa9
BLAKE2b-256 ef2ac75622c6c3a5d1609925c5194a3625af6f8103fde6cfb6f394404e8874bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 3d0329b6ee1794053be608b90e7a36ed3fee7023c750331b8f11bc707240e23a
MD5 9b78be59e69611d294014e9cb12aea40
BLAKE2b-256 ee0bf1d0a3fd9b2f8d3d403c47854a38b8eac5bc1940dc96d9593e963c75c357

See more details on using hashes here.

File details

Details for the file agp_bindings-0.1.7-cp39-cp39-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp39-cp39-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 11588d68dde300a53c2e9fc438c485bebb2c7ecab4abf24ac8cdb8cb05114548
MD5 1e140334dfe48b65dfb6bff147d63d9b
BLAKE2b-256 ab5101f90aadee966c6480612ea274faacef3a2efbf466763a994b2d6d265c83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9df2b586f2b10325d46854791ee4c1b203fc807ff1609069de9fac4f6acdd83
MD5 905a35732614f6044f90ac9bad00c6e9
BLAKE2b-256 c85d063341582b9fb23f0629033d84ee6f59bb85f9ea758a648e9353019b338b

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