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.4.tar.gz (113.3 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.4-cp313-cp313-manylinux_2_38_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.4-cp313-cp313-manylinux_2_38_aarch64.whl (9.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.4-cp312-cp312-win_amd64.whl (10.3 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.4-cp312-cp312-manylinux_2_38_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.4-cp312-cp312-manylinux_2_38_aarch64.whl (9.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.4-cp311-cp311-win_amd64.whl (10.3 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.4-cp311-cp311-manylinux_2_38_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.4-cp311-cp311-manylinux_2_38_aarch64.whl (9.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.4-cp310-cp310-win_amd64.whl (10.3 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.4-cp310-cp310-manylinux_2_38_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.4-cp310-cp310-manylinux_2_38_aarch64.whl (9.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.4-cp39-cp39-win_amd64.whl (10.3 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.4-cp39-cp39-manylinux_2_38_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.4-cp39-cp39-manylinux_2_38_aarch64.whl (9.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.4-cp39-cp39-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: agp_bindings-0.1.4.tar.gz
  • Upload date:
  • Size: 113.3 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.4.tar.gz
Algorithm Hash digest
SHA256 12d86ebdee14a9eaa974b81ac56d558887e7e97c3509858e9cb1426ca8547b19
MD5 741a7fb20e33fad7fa07eb4b5f42ad0c
BLAKE2b-256 8da8d273ad9bb895bd63ee20d80e50bd4b0db513b912ebd72e370fd14a09f64f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 4b0946d965e6f87137e0db0bde89c0f006a71803ebcc8279ede7b98744dfbbbf
MD5 f9e7e142fb0757a80a0c5a7f9296fb06
BLAKE2b-256 6e37287d09fd73e9aea192fcfe52e7fcb312189d3e833992b32025ace3d57465

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 3c4b8bb1ba9f02a5f4ef699f7210c94c5a2267121b7d146cda0b5548bd49ed4d
MD5 c6cf34694fd1d52ba7c45888610e6a98
BLAKE2b-256 37e4da3cf33f412b633810895a8a5c9e224423e1c46d9e74004da64901262365

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2520c42e54cdac383f03cd5ba6838dd1d9bfd3a80b58d91aa26b6f9c8827812f
MD5 41a5aed69cc5ffee5a99f5bde9269dbe
BLAKE2b-256 330ef28fcb14d0dde1cec8549b0ed47ba73abcd96b89c0f309a51fef402bdab5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c1ff0d373b4ef2852b4de6045dc165a1c40a367a4884108903d47df9ccfb1704
MD5 080119e23db5ed181035d294ee6ecddc
BLAKE2b-256 bee3835dd438cc278f282a7dde8cff9571e000e9b3b879ba49d3507b4648aa19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b1f218f451cd2471c120d64eefc217ff4e2a9797467021ed8b40c828290ff0d8
MD5 70de34318788750145b9ee6747489c2c
BLAKE2b-256 b7757f0febef58db90871013740cfe7a9822bb15277733a8459eab5d4a527077

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp312-cp312-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 e7a3c0abeeed5727a417053d5ef50e32c0a1dedb520178fec6e73f12faea8310
MD5 8afa65c9bf544e137a00c3534ce3cee5
BLAKE2b-256 59eb6a5b8230c3c38748ddbd0997e59bdad4ec9b864aaad7c716871747087206

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e776932ce7404598ed4ef0ca802cc6b62ab8b332291cf6a7e96da68347802863
MD5 1af499d0bb9cf202e17ad40534a45d6d
BLAKE2b-256 e742614cf770575939f40899cc974cdf34135983b229062798fe1a9ece35ab6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 303f03a9be0495912f41ad95519583cac0cd2301251fc6eda67993f72bcc2d50
MD5 a9a959cb774798a1d2c82daf23801964
BLAKE2b-256 6dd3aca80eb4fe6db5bde1d7b9764f00f291eec2246fe7bd03ca244e78135642

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 a9d10cccaaecaa9fd375fc8e1bfd2122980217312426fa4f73c6b4bf5033a8d0
MD5 fce957518cc9db89344a8de6f5c4b742
BLAKE2b-256 2c9020334646c463a659e6acc016b4a1d2f5ea0d9ec4e9c4c0b387a50b5660b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp311-cp311-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 088e54b53a5cddeeba9c1d296a6822bd5a203bc2dacb671584ebe5382776734c
MD5 3130482e1b89a86bb7645cacef028f68
BLAKE2b-256 20b2abda04bc068f69fd258b7bab7a46ce39a8f68209373f1f468b7202fbe57d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bff4052ef42f2ffd2d68a3442cbf4a7615bba1240f56b1c5a10691cb5c939114
MD5 b481656e865874cdd22d92453961a16e
BLAKE2b-256 e54ee821c474f8a6b5d561e8242e06c36907c695b2be84dca9e573ed27753cdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 51c43074c0755131e135056a9bdcbef153205b73891d1d44e512a7e754c0ae76
MD5 0830ca719bd0d2642986acb06572a3b8
BLAKE2b-256 a42744fb3dea117c3341593ff70fe22e42c439a626ed1e9be265ad5429aa5e54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 969baf16c6375803b2deda86f8fd36fc7b230616c5ec97eca27d8bd828e25cb9
MD5 9002ce0e3aa6d94134e2d53f84b1ebcf
BLAKE2b-256 061561746e4e35e17225abcdad0befdb1c15150fd4f7dd3ddde5f072ae851ccb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp310-cp310-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 1192f273f387849917f50848de224e0f63203ce32a847cbdabea96c38a3a789f
MD5 1dc08a27537587b8aa1fc701c9a739ef
BLAKE2b-256 9c4a4610132e151e8787b3332861a40134ca2caa0e62dfe9c20a5bd9f1b4b68c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f53f0e18a7c0da768e50343668ec3b58eb5e599753e9832854c4d4b636d3100
MD5 a0d53e6d82f658d742b0fdc30f7b678a
BLAKE2b-256 2f7704ddc4e1d14f292f6bedd8761edbf9dd2631fb42a666322154d52a42675e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 10.3 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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f732e0236974c118cbfa6404cd6c6698f8eaffe6445ce1bfb3ccbaa6702e8c1c
MD5 e6d73114f6cadbee752a35b9383e9e69
BLAKE2b-256 ee0ca6156de4b3ad74a9c5a8ae9710464d6acb141679572d615d908f8493f0cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 97cc3f0e5efb58a9c4686baec2d4f6a0d197ccdd0eb58fcf5879352ff2ac3384
MD5 35d0ad6f53e73c5e447d4b96148030a4
BLAKE2b-256 63260436954564433b974b0da42a60fafe5e00cc5277c8b547f25a70f0725915

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp39-cp39-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 e94307d30aef9e1e7c5332a7d393b5117a046322fe5dfeacb56345dde6297ce7
MD5 d4cce5135fee10db4a7baebf883e6715
BLAKE2b-256 cb86af6b19a59d9188d28bd23185839e8629624754970f9625487656ce17c9b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84a969c6fc57aa9f38fe372c567e934f9b055bf5c940822ab96e9f629e733575
MD5 235154db2228d5a328c9d3cd28a98e3d
BLAKE2b-256 a8d3501280471faf72773ee97af37628146ceb50d7224f01eba96f1828e82ace

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