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.5.tar.gz (113.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.5-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.5-cp313-cp313-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.5-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.5-cp312-cp312-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.5-cp311-cp311-win_amd64.whl (8.5 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.5-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.5-cp311-cp311-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.5-cp310-cp310-win_amd64.whl (8.5 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.5-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.5-cp310-cp310-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.5-cp39-cp39-win_amd64.whl (8.5 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.5-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.5-cp39-cp39-manylinux_2_38_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.5-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.5.tar.gz.

File metadata

  • Download URL: agp_bindings-0.1.5.tar.gz
  • Upload date:
  • Size: 113.8 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.5.tar.gz
Algorithm Hash digest
SHA256 c315cddba3b283f566372cfe15491aa8f7b6e68cb6503e14b3360b562d851ea1
MD5 5a462437cba24f809496097c7d04f784
BLAKE2b-256 a1cb7c7a05698c5f2ab3b752e8f7c9698b4bf2d1a43b2765167751722e9ce5a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 175d2f0ec7af8fe4fc1a4706a7054fe4c0abeee2cd78b41496891a3d8548ca4a
MD5 a6ba7a5e55b84cdd0ebcd3072d0b8dfd
BLAKE2b-256 25d2211b572046af4c114cc5cbb2c2bd85aacf78e86926b7ec429af0c9fb222b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 95df2dd84d815365a27cd8d0445e3d47fb77ab81a9570b59927260abd71def87
MD5 c8f603d827e23003b2d53cdc9d4b44c6
BLAKE2b-256 5d50aee179061ed3f186fe9e7549600e66ee747acd84a1a4a0092f4786e46b85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1fa6d35bb3d3dcf6531f014b962f561c74ca89007d2d5a9d58df09bc86f1b17b
MD5 88f59eb43af480120982ad05e00544b1
BLAKE2b-256 8b54c96b19d028d5503e78aa8647642826f3981222eb0ba5f1a0c7764020e7b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6b9869702984d0d65c24037ad517dfabae31265b7cb773dcaf628b118a512b81
MD5 750096079b910dc052b74a7e884c960c
BLAKE2b-256 9db4cc0a5db9437e6ce4ae62e1829942e4330180467f184bb5f678f55a30cfea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 3d41548372598039478bcf6b84201118ac7c255c0019e7511f872797303ba3e9
MD5 ef3d78d25aeb73ac9b9c930f2255799e
BLAKE2b-256 17dbd30c6afda4b5cec49ae3c74484a6ac75a1de9acd772d70fc61dea87a577e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp312-cp312-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 7370aa1b56c5d5f38ac71a5af1f6c2bf6c68a611c099667856f357ba5f9ef789
MD5 8de0aa62e7d4e0265047e9f6f9f54c86
BLAKE2b-256 ea2439c4f60c27c1179cac82631549d3cfe4de579ac2a4f3f60206bb3cd52230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89b3e52f5081c57af8a36be6bb19b24b5f56047d23e7c82c6cedb11f8612efc9
MD5 7b6208d36b9e8037097955614c51a8a3
BLAKE2b-256 44a988d02db363407bce4b5191a6e1112718d6d6aa99c7b5c61f680f68528fd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 32e6ecb09b2c112cbe6c791bf569a9b7b2cb5d1396022b50b60a8f0289e2845f
MD5 f028212c5c5f06f3710648bbafd2b3b8
BLAKE2b-256 7bb42c165272611750b6487ceaa02b55062327a80c30bc7c357b23d197441539

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 71a62ef9a7264aad884d8374e48ae9681b408f0848251dc1c9694bf83fab0265
MD5 70467b89c1a505b81c8d25faad5c1266
BLAKE2b-256 4af25ea4d5e70ef562f97a2e67621e332fbf562c770218d66f188794235b6343

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp311-cp311-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 37bcc5cfebbf7268f2c92c49923e479f668707fdb3a0dee9c58f6c9542707745
MD5 7a6ce682c31cf81d8656ec367cdf13c1
BLAKE2b-256 3a8a32473ff5d0337ebaba9ea5faf5668cdf51a6ea843d74c8161eeb34ba32b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ea3a10bfbfef872a7c8384e381d8ee4c888459936eb83389bebc0a00afcfeb5
MD5 1d5d95d8c07da6eb619539867ecce7a9
BLAKE2b-256 21aa025261ff8c295d0cd522c5fedaa20438bda3d321241e752413eb0dc79760

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3a29044dd2f551f3474f2548df68b3eb539c4d53f43efba936cba3422fa88b21
MD5 298d2e8e6041e339e31b0706cbb87690
BLAKE2b-256 30986c0d34360e82b165ad569719a6a2fd42d0ad4cf4799d4eb6aea6b0b63a08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 6698b98aa68d14ca4b1a94e5a50b789897a8da66e62a690cdc97d51d48391821
MD5 b09402197040923de5fe3d0bddf47ff8
BLAKE2b-256 5b468cb6f591156fc9eeb97122ea88b2cd44af5c831a36a752688a8056736797

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp310-cp310-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 a7edc53f2e8fb0ebb379f5c89ab76d38241d9598b938c8428b135afee1535714
MD5 9ff9c84de5bc86217d05485ff0a2e44a
BLAKE2b-256 105626eb8dced18ab6c152f7258c71943bf00695cf350d009bf2420f10ab732e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1bb4e5f21f4e7a15d4aa07f49da53aab0a896f093575271893e39f1e75e0346b
MD5 76ae5d46208c2951fc211a3b1da247cd
BLAKE2b-256 5bd6c1f8060778a8dcb93dad43af263ce8260d44e32b678bb402d8d84fef0c4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.5 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.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 307ca30355482f54a460ed29edc38775d422fd07191ba0c0b5ae142250bcaedf
MD5 099d9122cac32f765882f970d38319dd
BLAKE2b-256 efd0ec5ac934483aa789a436c55f7fdbfaa640462a4c9a63eca189f7a23da13a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 cc989658fa40481af4ad7f2c3492ace51442a1a370d37c7926ca93e9d62547e5
MD5 f35e0acf0a84ab057b49d0cbe2a5504a
BLAKE2b-256 c7dbc86a2195966af6fbd238ed80cd9867a4cedff2d9f46cc5c962a04e8572c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp39-cp39-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 f369477f89a950085e16759567e1be0fa9490f4f57ca930818d309fe0dc0e734
MD5 1d140394e8396cb545342a36b416cc73
BLAKE2b-256 73aafe91042dc2ef970dbe2373a2ae0a5ffc1ace568e29ba9c9efdb6e7b4998f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e70984740dec3106ffc5f912bb95b7073ad74a1587a9b3af696e8017cf749480
MD5 d3629e3aa6251098748011104bb0d133
BLAKE2b-256 c6f0e5d494074d4d24741d476792912e8d48edecc628f594bd114a5869ef65b5

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