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.3.tar.gz (110.4 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.3-cp313-cp313-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.3-cp313-cp313-manylinux_2_38_aarch64.whl (7.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.3-cp312-cp312-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.3-cp312-cp312-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.3-cp312-cp312-manylinux_2_38_aarch64.whl (7.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.3-cp311-cp311-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.3-cp311-cp311-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.3-cp311-cp311-manylinux_2_38_aarch64.whl (7.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.3-cp310-cp310-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.3-cp310-cp310-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.3-cp310-cp310-manylinux_2_38_aarch64.whl (7.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.3-cp39-cp39-win_amd64.whl (8.9 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.3-cp39-cp39-manylinux_2_38_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.3-cp39-cp39-manylinux_2_38_aarch64.whl (7.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ ARM64

agp_bindings-0.1.3-cp39-cp39-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: agp_bindings-0.1.3.tar.gz
  • Upload date:
  • Size: 110.4 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.3.tar.gz
Algorithm Hash digest
SHA256 df9775e77fd023475079cf457375be9bcbdc54295a30309a016665fef8d2e24d
MD5 0219b4eff3ac1b07efd5bed12af984bd
BLAKE2b-256 3f6110f85cb9204877bd057d40276e502c3c20574a78e9e01f99403891e512ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 f536aa941035818b95f222c16d6d027ad7810acf7a37465055e66b06fe9f5960
MD5 6fc66307e86dc941ad3098df1b2ef6c0
BLAKE2b-256 83998dab3f573f8773861f2cb2d6796d24a2f779ac24951820994cd470137daf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp313-cp313-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 9f45160a49743fb3d16659433eb877b7fea41a05c956163497752b293c575256
MD5 043f5bc808e92db2e97cac360e3250eb
BLAKE2b-256 3b4193ac3dde711d7d679e0f259c3f173b1d9fafbc48f4b399a861ca647810c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fcd09ba76f63e49eab8fd746c94a6de8c0dfca0d0a81bd0e092569a3fa412e7
MD5 0dcc27b2be93f11f903528b7507c5220
BLAKE2b-256 c93821de7b92033947ef6183445490223cb3cfb1e8ec804cfbdebead06775076

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 31c274b4359b302725094a8ac425f980eae6345860dea8276db62f800d5060ee
MD5 631d8cfad451a8725be01a0c685696a2
BLAKE2b-256 54d6709eef98fb04e88f4908bb45e41843b4edd6b571520054b3ea191fdf3d2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 bd6e1554b17a32e37a4246cd8333137bb06467219198d83295b6b030e1987f26
MD5 fe5c99068a267f92383577ce6fca26b6
BLAKE2b-256 adc561dd6534c32e16c3260093d4316a3c8497d2b64cfe79eafedca565157c89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp312-cp312-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 fc139949613f904b30f2e33d839cd1057ed6b4aee00afebc03054813d92972e8
MD5 3f9a78eebe66e03d2c18cfdf452070d3
BLAKE2b-256 5d4c4cd7279d3b0909ff5cb595f56f7dbd7d8b8675a4ea95f9c2c6640ade1dbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 338ee8499d17175275b26dbc3db7e091e15e7ed7d287852b409438680a915db4
MD5 5129158a546d53db6f2cd9b45f73d14e
BLAKE2b-256 500277410e321addb926f97181935698a400c52937bb8adeb42e56d2c162436c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3c9fad618d9b6b9d01d02a9283213084ce5225b15ef7aa89b24ef1c89de8217b
MD5 f1cd89e2d4c4580741306d5a44a843a1
BLAKE2b-256 9d4de96cb7983240e7b47d04472952a0c7287524f3b374113aacda4dece13288

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 1c4d783a6e74e53d9695527c392438f12c16406cd35db6e76b215a301e5dc872
MD5 934dc831ccacecbaeb9a8c302eec358f
BLAKE2b-256 6d58ef9f18fe1cc2c059c1c84a189187a24f001a325c70e137a23382a106dbea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp311-cp311-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 1a3b993e1abb5eac59cd50ad5dccc6510e7605bb4b50ca4b067690dc13b61756
MD5 3fefbbdcdf87a5a8a3e5b2484417aae2
BLAKE2b-256 2886273cf13215c13c4091da6aab0926502fd18f78df7cd4ef51818606c977c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e6be040f3cd938a9d2168c4e308b438cc0e7ab587d4482b75dad91defb6b2ba
MD5 6ef22223051f136ec4c4a3fd4ffa8159
BLAKE2b-256 ca31c661df2a3549de3c38c3f03eddcdd9a5f45fa524ea5dbe3127fb1eeecbfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a039c02e362a6fc265ddc33fee7990107a96cde46ea900e697e8e24c44d3820c
MD5 3a91026ecbcbbcb1bc84fddd88c866ec
BLAKE2b-256 cfef16fedb1ccc21e05a4bc3d88236aa81506db308b2fba00a839ea81588b7dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 6b955aa51785ec68acbef5b0bc50ecfc0f5e9ac4c4cd6b3f5b82fc4c4a9b867b
MD5 b60c1fae416f87e09223449e86fb61aa
BLAKE2b-256 46b1fa5297439601f0cc32f350f879c0b6d423ffb32a68addbeb12d92f3bf744

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp310-cp310-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 536bcc4516b53549da7d607cca184dc83a23e025cb15d1afef742be9629ba91d
MD5 3fdcf41627719cab0f6de97ad2fac7c7
BLAKE2b-256 2ba41ef182cd4817835b068ef5137fd2bab1df96a97cd00ac9765ae00a4d240f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9baa12e08ed344b3a91510a684add2cdd0952d8e59801daf4354da883e97d2c7
MD5 123ee7aa727f8a9ed5ca49e6e6ef2a31
BLAKE2b-256 527e3f06f3c89f2e0f551fc05b3e726497bed9bce7668217d5d5a7aa6861471d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.9 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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9f44189a7ac2d821c8c0163606778450103d5a29d7c59527649087c40e5af9bd
MD5 a4cebff2a554b99c77babc647ef8539c
BLAKE2b-256 a63ff6e1910a9af5fcc3baddd21cd8a7ac42bee65513ea2a1a16bd4088ad2e27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 70661f18e4484bd4214bcbc464dd268da81213c4226be231badf08b3b251c520
MD5 5d79541e918894613b2ffe525bc401ce
BLAKE2b-256 02f013657179afd6caabfe8efca1ed58aee08198f9aa31a247a80d4f5e78b8bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp39-cp39-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 4cd6d6bbabcdebc179aaae77dba947dddf234a86f878b35a85695f54605ea3c3
MD5 802ab11ac0dc1cd22a7b98bd9efda19b
BLAKE2b-256 ecbbc9eb9e5dbbd7c8ad13f6a1bd506b2eaac9a3c0a89d4b2391585aced3114c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63dc1486437f7bb98902db275ffafe3ae3d780048f0e5f0c2bde46bdd9716da6
MD5 6dc6daa6b77213f5847a8fea04af9f44
BLAKE2b-256 6e605372d99be4253f65e9113e182561f351ee575054871ea3027eee1f50be01

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