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

For Windows, see section below

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"

Windows

In the case of Windows, agp_bindings will need to be compiled locally.

1. Build Requirements

  1. Rust Toolchain

  2. Python

    • Install a Python version (3.9–3.13).
    • Optional: Use pyenv-win or another Python version manager if you need multiple versions.
  3. Maturin

    • You can install Maturin via pip install maturin or cargo install maturin.
  4. Task/taskfile

    • If you’re using go-task or a similar tool, make sure it’s installed.
    • Alternatively, if task is just a script/alias in your project, ensure it’s executable.
  5. Install/verify you have "Desktop development with C++" in Visual Studio.

    In particular, make sure you have the following key items checked, which are most important for MSVC + CMake builds:

    • MSVC v143 – VS 2022 C++ x64/x86 build tools
    • C++ CMake Tools for Windows
    • Windows 11 SDKs

2. Run the Build Locally

Clone https://github.com/agntcy/agp and change to folder data-plane\python-bindings

Inside this folder (where the Taskfile is), you can run:

# List all available tasks
task

# Build Python bindings in debug mode:
task python-bindings:build

This will build the wheel under a temporary folder that will be removed immediately but serves to test if the toolchain is correctly setup.

You should see a similar output:

Built wheel for CPython 3.13 to C:\Users\dummy\AppData\Local\Temp\.tmpYMjkNn\agp_bindings-0.1.7-cp313-cp313-win_amd64.whl

Build Bindings to Dist Directory

  1. Disable any cloud data syncing programs, such as OneDrive or Dropbox, that may be monitoring the folder you are working on. Otherwise, the build will fail due to file locking issues.

  2. Execute maturin

    maturin build --release --out dist
    

    You should see a similar output:

    📦 Built wheel for CPython 3.13 to dist\agp_bindings-0.1.7-cp313-cp313-win_amd64.whl
    

3. Install Wheel and Verify the Installation

pip install .\dist\agp_bindings-0.1.7-cp313-cp313-win_amd64.whl

Verify

It is very important that the path displayed points to your virtual environment and not to the folder agp_bindings

cd agp\data-plane\
python -c "import agp_bindings; print(agp_bindings.__file__)"

That should show a path to the installed agp_bindings in your virtual environment’s Lib\site-packages. Example:

agp\data-plane\python-bindings\.venv\Lib\site-packages\agp_bindings\__init__.py

4. Troubleshooting on Windows

  • MSVC / cl.exe not found:
    Make sure you installed the "Desktop development with C++" workload in Visual Studio Installer and that you’re building in a Developer Command Prompt.

  • File Tracker (FTK1011) or Temp Directory errors:
    If you see warnings about building from Temp, try changing or shortening your Windows temp directory as discussed in previous steps.

  • There’s an Old _agp_bindings.pyd or a Naming Conflict

    Sometimes you can end up with two .pyd files or an out-of-date file in agp_bindings. This can confuse Python or Maturin. If you see multiple _agp_bindings.cpXYZ-win_amd64.pyd files, remove the duplicates.


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.10.tar.gz (122.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.10-cp313-cp313-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.13Windows x86-64

agp_bindings-0.1.10-cp313-cp313-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.10-cp313-cp313-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.10-cp312-cp312-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.10-cp312-cp312-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.10-cp312-cp312-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.10-cp311-cp311-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.10-cp311-cp311-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.10-cp311-cp311-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.10-cp310-cp310-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.10-cp310-cp310-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.10-cp310-cp310-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.10-cp39-cp39-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.10-cp39-cp39-manylinux_2_38_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.38+ x86-64

agp_bindings-0.1.10-cp39-cp39-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: agp_bindings-0.1.10.tar.gz
  • Upload date:
  • Size: 122.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agp_bindings-0.1.10.tar.gz
Algorithm Hash digest
SHA256 a542e65110a706cd3d0209fd02b86da6954ca8cad9ee734d99d48dcee2ca99bb
MD5 1f2dbf1c1d46c2e944bc5ba72fc38d66
BLAKE2b-256 3ce52b57049cb1f41ca520dbf7606e84fe1e0c0352f8c20298e1a93b67531888

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 545259817dea9f9dad29e8325023d919d585bbe7f3a7eb0e9764deeef49f824c
MD5 39b0434ef5f803cc50613a56f8559bce
BLAKE2b-256 880fa28ccbb2756bda3d5fbeed9ed74c4b4a9326bc02f7cb965832f14f13b2d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 259fb44e7cf67c07364dde3bcc3959f84bb178c1f02049e79773f8a2170a1f5c
MD5 360ef1ed718422a75e85b85a2715877c
BLAKE2b-256 0483002597ada6f0b4441addbe8c0dc7f8813e4687a805b1436c0338c3e2f9a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3efc4ffc537dec7a64f54edb7e26f64af97d238ebb9b91e509a4efd5ba177466
MD5 25cbf8925e119252f61a831e7e5a574c
BLAKE2b-256 f190ce9e7032024dfe0775fa53765dc235579e018828f443ac8999fe8830c844

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dda9e9599296aeb3ec9d28c88c697606117745d6eb21d40a924eb7dd71e54fcf
MD5 2ab719c9fdae5c7ee317019b9fd6a05b
BLAKE2b-256 081c9235541ba7284e5d9b20324eddd8786cb283f1d7d04f9fe7cfccf59eeb89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 023df72626b8b6da25249866c6a99e3ee43ad0147c0e9731aa28bde0b3924fdf
MD5 be46db5a53269bca2de8889966f54491
BLAKE2b-256 86a7bfb6814823fae6f1be7fd3d25502baf15f549c4a2f8f9646c9b15c4f1b73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 624239ff8a26f479b745a3acb3bb031272a5264efd9917b818d007604b6d7da6
MD5 7b27559c59545d864d50f9f8eccdf588
BLAKE2b-256 a8705d718a4100a2e572f68fef9fe843f854a54caae008c2f4b55f041ab195a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2d85bdeb75402088ea012f77608d92ca02aa3796a73c041904fdbb98b50b9286
MD5 2d902d7ab09fb1e885784895fd33ef66
BLAKE2b-256 c031e9b060c941c662ba01b3f95d5fcf216e44133a2c333212dc750c1f4f8e27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 9b436b6b6dc22dcdf22d7e1a4a878d7b8ad2f6f15324bfa41fea1830258d0e93
MD5 aaad032c2d1ec8eef0e9f306559ec152
BLAKE2b-256 12f46cedf47890443b987173a687403aa47f24146666bf472af72a620dfe9811

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 accb28adc47a92af2bc054dc2f34dc8a672b5d324e91485221e25b37d729f091
MD5 8bfc4fd402c21a6b2d253a47456a5c1e
BLAKE2b-256 227ac1d9676f0648795d8cbb0bac6817b53cc66a2d4b146c1f3ab8e091458a1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f61004c2a67ccc4f9958463fbb74807c51ee546ac58aa90a33fb62a081aee0f5
MD5 3a92beb8cb58eb8ef5901190d28f01ba
BLAKE2b-256 4e1e6b27ccfc04ab2433c1647fc30c013862dd5a5d784cd74f6304eaf6558546

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 c73c5dcfa469de9d128f9b68383733fdefea2e4aa9b8b701e07c1ec86d955762
MD5 324125f900c2181c07bae01fc0f46031
BLAKE2b-256 6dc4b7a099b99aca71eef16d3f45813ec1ea7d597c7e81faa3432cfd320dba64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 798659b5678863188a7c1329f03f122a0e2cda236e8794dc91c4a94d4690ffd9
MD5 4f4d351edd29e3cc6446839104174d0a
BLAKE2b-256 a9d4d518a511c0fb044d40f009ce9d4395446ab23d816ad917f1922d80bfd421

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8b7dbc330c66b9b7605214c15443bb12b7a4bce5b5af6e73dca204829ab43a4c
MD5 75df96e09d06a69defd7cbbcdeeba404
BLAKE2b-256 52955eb1066a761d21ed3030717ba80326993c2159f67d7f7753a7fa0332c60f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 a4ab0148b0e65128e20e90641c23acd542688cbada7d4292be9eeda1efa44f5a
MD5 f061272e844973d99cc5ae046827e686
BLAKE2b-256 6855e0a40c21092c20bbdfcd2438d04f3edaf12eae30c9c77a74b3550e768c74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.10-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b47439f9851b83a51f011702ebc5627fe78adcac09c93e8935a338ff33c41ae
MD5 ef04e7f7aab737244e2aa074d30cc039
BLAKE2b-256 b1b07c1c546c99a0b3bc1ff54d100d6e4f63790b2ffba1de363131d982fe4573

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