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.1.tar.gz (107.9 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.1-cp313-cp313-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.13Windows x86-64

agp_bindings-0.1.1-cp313-cp313-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.1-cp312-cp312-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.1-cp312-cp312-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.1-cp311-cp311-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.1-cp311-cp311-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.1-cp310-cp310-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.1-cp310-cp310-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.1-cp39-cp39-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.1-cp39-cp39-manylinux_2_38_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.1-cp39-cp39-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: agp_bindings-0.1.1.tar.gz
  • Upload date:
  • Size: 107.9 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.1.tar.gz
Algorithm Hash digest
SHA256 445446e8ac1c0b2af6dc613bbead5adbd5a4dfbfef8a6269f0eb6bee96f40697
MD5 a9d247e75a4c44872a1c428565dcd62c
BLAKE2b-256 f2ca34b208d80a91fdca41a00e4ba5a1c4ed3abfab56635a70133d9037b5d992

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9a7b1a6253760b26bb2c57a505d6133b30a10f81e391be685d2543f023898564
MD5 f64f63e0edce8566f32b06fac3e84ec6
BLAKE2b-256 dfcee9ecc451208586180e507c42245df5f9fc63d4facf7fd4bbc0bb70ccbdfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 db3507caeb5a51aff0c748d691b1ef5d78e32ad03253c11906f6b14989345f03
MD5 ee5da6506cb7e4a87dba1453e60bffdf
BLAKE2b-256 2a03d1cb10293e71abbe87caa71717173466db2759a232df04bab7584aaf60ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72bca35edb74d138cd1774c9568c0a69957171a4e66ca00dfe02707fea5615a9
MD5 c17ff9a5df2aef1cd8fcaaa449d722f4
BLAKE2b-256 10a7bccfd8bfee61df7bb4f788e35c667c69f1c342b6a9cf668c8d316738dbc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 52f5fe6afb2bb1d68645ad58c1edc20c919c1b6f0f743118313c5dc78e37ad10
MD5 b6179ac305cc8f00c1bdf6403817c613
BLAKE2b-256 7def0eee2055538be35d15aad4763c1bdc587c657b13af6dee9f6afd510204a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 2beaef20ef4e85c207c20d877a99f4790a3f34e96a645c916cc472fe1b0af31f
MD5 9513144dbfc26d0280432c64a1390462
BLAKE2b-256 48403d54e482511ab380ca3c7a5276a01bd16cf5a014ccab046a51d66837bfc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ed9f2f704380a373ee678b97286a59f308037662642960b9183965a3ec1acfaa
MD5 dc89d771051af95c03e3d742fe572e83
BLAKE2b-256 6834035e1e59f9c55ede9a19a034b832a08cf5ffdbf43397266f38dc9a44ae0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c98a5a09e21d9934acfb7a8465570be905e71bba3e5c47a12a0893ab3eb67246
MD5 f4313be20840c05170c6f7699fb904eb
BLAKE2b-256 acf2f313c66e4ad93d461657fbf4f73bd1a6209ba87de9b4aa5e4e13cc153451

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d9c9d0f50f2fae0248025aeece81cdd9bf057be78ec213cddeb79f1deede51f6
MD5 84452e16ff3622138ba57dc1aab8c56c
BLAKE2b-256 512176e744d0db6cd0139a5ca208a93d3fed8c1f1e6e5bf2cad4fb8cf3ae8bbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1193a574a14069cded4f8f2b11508d0281192ae53012d5960e3434ece2e22d37
MD5 59d6584305395d7bf919d5ece631722e
BLAKE2b-256 2645d2b6a2a6222a6f523d9d9657359a68a46ecdbd9f231a93ccc89789617a54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d106515c622b37a9aa5784282e81bf254029595d88c27732e2d5486027180af5
MD5 e357d5333dcc30c884c4d726d62597e1
BLAKE2b-256 a11413bb7c3dc34c26a7d1cc045c6587f42f1a2de2b89eb57a27b51c2aec2938

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 3e2394a0936f78618144bbf25300a398c5d0f80c0d9fbe5afc4869ab7e302774
MD5 92fa2aea1bd7cfdd4cc184b5d2767649
BLAKE2b-256 32d0a9de2900a6facbe5ccdf835f113b40eeb1ba762205000b475a72aee22f6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 854c0c66b544ee4541f499cccbb93c14f4119cdbedae849804c632f5d2dc163b
MD5 0c5d9e6ce30bfdb3028674351988fe9b
BLAKE2b-256 b1b53eafcb50fe5bfb2f1d85c659311973974b082ffc1fbe41b78f8a02b4118d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 3.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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 87dec80f66f614ea42787253977a959d81abc7f8c3422ee4f02f97281f9aa40e
MD5 6ca811c12d2bd7d1ba54d7f18270e39d
BLAKE2b-256 f7a0049d0f67ad652f594685bd9878af5dab29c6ebf68bcca0a1e7a8f90d38bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d62401944c17cdce4a24aefc27e979629a0925f44b967824be3acb611319bcd0
MD5 765ee55745f94d1a3f16d4fd5c01f08f
BLAKE2b-256 af7087f57560c4dc464075196c2e926663d452ae04a77a2fdb46e7e3a8ead1a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2cc5f3cc0e7e16b3f741d5c34e89f66f6d772ec2baf77af6ace23d3a8f284e0
MD5 c2b20fc82d3fe600cc647a0b838c8129
BLAKE2b-256 530f76d58064692452457eedcf58091b0367cf160c9b79abc3194c7a36b8568a

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