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

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.38+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.6-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.6.tar.gz.

File metadata

  • Download URL: agp_bindings-0.1.6.tar.gz
  • Upload date:
  • Size: 113.5 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.6.tar.gz
Algorithm Hash digest
SHA256 7ac18784ee581ce516ca63db0a0da62b525e307361ac333ee1cc297d0b4764d1
MD5 e6c27acced02a05395be1bcad3b95e7c
BLAKE2b-256 81865aae5bd1db36ae0dcc5eb8615972c735f56646ff2a048745a583de8a9fe2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 5a7f1b585ce29a5501d4e6946424739dcb67ef6dc2a6d8542713abf2dbc9230f
MD5 011617008e9785b3954faa4d6413dc31
BLAKE2b-256 ffb544415a4adf14c7b0f659e761549823e176589a4468db188603cefcdfdf14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 167ce02797eb6a66b7b70db4389e36b8590fc19798970e3a274eb2fe4774c896
MD5 cdba4ff070cb9f0a02158137445c1f58
BLAKE2b-256 d1b24c2e6cb4de8dc998ef350d24f5119f9091c09d31d7bbe4e6eb988c0acbf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f049346ecd1f69ae04ad243685ae1631235032ddd39bc88e11ce16ce471f05a6
MD5 940accdc62ac12383623811b56368939
BLAKE2b-256 c03fa596ef166907ba0239ab04758375e2d71d5d36486444d057af1e369078b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6cf8ad22e4f3fc415a22fe51ff7128cd4e60f89d2334fa3f87362074e5ec90db
MD5 16a8778610165d2f60ff2c27a0cace20
BLAKE2b-256 8bf4e666211b3fceb1f39f61a9df8f248159ecb8025d446857008914de91f99e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 eb361e6ac72f1b10b8cb00cbb8f21546f3196264f150e85a7c23359c34322da6
MD5 cff63fff25e9b85ee7e267cb1a4e2003
BLAKE2b-256 4397c434a8ad31b96f04480ae74b4c4c31762592e895a36a19b398c6b4109503

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp312-cp312-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 dd07f84a6a31a2e91addafffd8042276bc2856239268b0ef2a64b3579c794e9d
MD5 16f1208351c1fef553d47c02efdfc5ca
BLAKE2b-256 127a9ec88770c97c293d0c64e73740adc71073a2c3a92fc63cac4f51d0fccdbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 618524617627427f5f021bc1ff261a7dcd6ca004bdde4a77624a2a654c1a1ad7
MD5 c1cd24055e84512f16c19e0443ce1f96
BLAKE2b-256 6d4f7d270443658a80dfe38624653c76a3ebc0608895ca8d18b0e34bb6912e6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 af3770d86f9e7722a041c9f3c45073ac5929df06afd454b1e18a62a180cc2d3c
MD5 eac3cd4868afe738c55e6db6c5671249
BLAKE2b-256 0a60e62ca580fd85b49c3bef2ca591eb026dfaabe07c85a6ac18739555834314

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d0d32f0e4a224c6bdbb777b99007acbabaf03a176d6e6870a23a844dccf03309
MD5 e57b354ee42d7db69c286ffb94e6866b
BLAKE2b-256 94e3acfb5157e19cf2d4069c1febe440b33f41041a498b9b28bcc2498c1745ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp311-cp311-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 2a6ba28aad39b4a598d1d1674cfd1de4a8233325df22e1516e573bf7305f1c28
MD5 3867a8ef1d780854024ea7e0cabd6970
BLAKE2b-256 2b16030d9d972bce928f7f69ae5d43ed173440a64b58bbf65646a026455a3193

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd389b66f7049fd74f889a0e3f7227ead2d28f227d8647e7c2a6c6e534aa9649
MD5 7fbbb3646817e73de214a55c6eb35ad3
BLAKE2b-256 6245d323efee3048c75074df5ed00b0745dbadaee8ab04d50403798fcb317966

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a74bb893984f517d42763433ff3b8cff3b30063beadd5890b16f38f0db6f14d6
MD5 33e75375c941e534d2824b1b4e7afc95
BLAKE2b-256 30ef990c62e5ec5cc5fa0d9bf04d4a7d3cc7e62db8c7215d42b54ed9880ace90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 15353dd8d2e6095b71ae9fddb6674e1a3f2d3f9ce6e834e5129fa7c26cf77308
MD5 bb77c9de2761c7ddc5600644347a21de
BLAKE2b-256 6b93a9d273107423b00986b5ece63aee993b4d91b7e1849c25976bcfa0135a17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp310-cp310-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 e2e4065d6c51ae29b96b991415c13e1160c2edb88953999a88cecbbbfbadc895
MD5 0441b70ce5b3b7b83693a67c07731ad6
BLAKE2b-256 01612e618a5b3b71900bedfc9dc8ddfd752d922b56a1dabf99f45943c2ca1c83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a28cb4826455551cc3e0017b47e27c09e838201ab5cdd2e704cdaa67afc61584
MD5 696ee61cd29d943acfc4f1283b8810c4
BLAKE2b-256 32969abf08f2e0ce776e55d28c809fd97d5e2270f104cc103dea588c11c4c366

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.6-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.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ba195bcdb5c40e2d1a9027a6f8cbe89f15e76d65d1f79e0cc808b4bb07489387
MD5 c32a4f34b666636f8344555297f18c3b
BLAKE2b-256 c88a2e19c786262debecfe140f8a8eb024b27427d1b1d8392e80b3bcb4cfe0b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 498edaba9f25a72aa33025a73afcb7fc51f1e547413f6a0531f0eed41321fa0a
MD5 e5886998db7350fa51080323d8200ad1
BLAKE2b-256 9263c8ed67da2cadeee578e34e5df40020e26190627aa56a5c15b8e5e7583cc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp39-cp39-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 d33a5d31b17876feb26ef3361383457ce5ce471ba4939108b34d2397f87858df
MD5 4f25694351cdb94cddef09655867dab4
BLAKE2b-256 77829356b4fc5cc7600a6306a6a2fd30d7b01aa788d47cccdb7fcc37cb985ab0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7bb9fd780871dd90bfa226c859491761dafe9a88f55993b6e43822ab42d83efb
MD5 a694170c2e23e8704ba007fa90d60324
BLAKE2b-256 604da3789752195682b5b68e22df3a4294fa915a8119c07a293f9a4f1a9e6c08

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