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.9.tar.gz (122.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.9-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.9-cp313-cp313-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

agp_bindings-0.1.9-cp312-cp312-win_amd64.whl (8.8 MB view details)

Uploaded CPython 3.12Windows x86-64

agp_bindings-0.1.9-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.9-cp312-cp312-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agp_bindings-0.1.9-cp311-cp311-win_amd64.whl (8.8 MB view details)

Uploaded CPython 3.11Windows x86-64

agp_bindings-0.1.9-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.9-cp311-cp311-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

agp_bindings-0.1.9-cp310-cp310-win_amd64.whl (8.8 MB view details)

Uploaded CPython 3.10Windows x86-64

agp_bindings-0.1.9-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.9-cp310-cp310-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

agp_bindings-0.1.9-cp39-cp39-win_amd64.whl (8.8 MB view details)

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.9-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.9-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.9.tar.gz.

File metadata

  • Download URL: agp_bindings-0.1.9.tar.gz
  • Upload date:
  • Size: 122.5 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.9.tar.gz
Algorithm Hash digest
SHA256 438d010c07a86bb7cb1f9428c037777d05d3227c59061609fa552e0bea4d28a4
MD5 7f65bfda802e615451d31d89badb6b20
BLAKE2b-256 b979347e51e8b3ecd206c8ab1274b7fdc3b2b3988d5e03f3bc3dd3e3e48f8515

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 7225c3df1795a65fdd438bf6c1b15d2c1cec30d98f13aea9457f11fc8e3ef4b2
MD5 cc8c5970a589cf68cc38b39721b2fefe
BLAKE2b-256 a00c1251f44e1059ae6f26d103c1dd5787fcec5bcf6046d3333fc8c87c4b54b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4e7e2867b458c37fcf88502ed9851e9f5ee61d1784be8341f9892e6de2a0120
MD5 590cdf7b5677b2ab02a7882c8df2b477
BLAKE2b-256 ab57560b870ad928dae18da453e1574b80ef226b0ce3ae4e906c26882c814161

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6ca56fa0a157f4aec443a7c880558d2d5fcb72527c3a43d0434d9b0b19cb55c4
MD5 55d1e436927dd459ddeffe307a136ecb
BLAKE2b-256 97db443167e19c6d1e35614ba8ca9acb45b579f52cf6bc5a8e64f53cb5c5ffb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 056b100c613174a8da68c584a8671f302ec63bba304e7535f68497c17ef15fdd
MD5 840b9779924ae56736fa407b1320d9f0
BLAKE2b-256 06e2a55b3243a14c95f3a9ccc212cbdbfd7eb75146fb81bd92f1b19e81b55763

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7bb43bb89e2390cefe78ad50ffc2eb3407e196da1f7a7d17028803ea422fad7
MD5 8ef53bbb8ab14da02f35f91b638e3e41
BLAKE2b-256 20dffa5550fa9673ef69582d3fd05e0dc152b9b55bb212ea1fa517e09cbbfc39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 71894e47e78000798782c3ca98a6086a3bac66b72f64feff000a2a868abd330c
MD5 7e10d0c1cf83aa0841a2acdd5444f8a3
BLAKE2b-256 76031a0b649c1876be3f7a72d0354ce4eb87e0428f6f979dfb5561c3a3f18c59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 9963e64518dea670d469cca9f1c49447dacc6b01e28bf394de3ce01759ec1423
MD5 594ed4fa170cdca6eff3a105b6b48336
BLAKE2b-256 4cb126bafd1a9c4cbfc891fcbc02f0cbff77c57477fc83cb49ddfcd42949bccb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b40e0b254ba00f9c311f54fd05fb504f3b8a7a410575f78a1510b51eaa850344
MD5 f552692bea2d6e1d0148d1a574e966c9
BLAKE2b-256 e9f26f6d88c9278eba0b3f9b4769376b36906e9f54be20e1fb74538bc5225729

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 33e1cd77028c99292325f294d9a945362de04b1208a1ef4ac830b589f477ff19
MD5 35dba9543374124712556dbed5395dd9
BLAKE2b-256 fadd4c05619e39b546cd0a136f07a8a54f1b127c73d85fce4ee4260c3f4bcc5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b24182c5604f338efa188523472502a3c9e553b30ad2b87adf3420c9c8d9fc0f
MD5 80b6c39c53827fd2618b8831237b4d50
BLAKE2b-256 057061c4ecda991f8add66b33cc3b60fe366f688d00d37ccd4fabc21b2bf0681

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df317dd59940c504acd9b58d705f7e3925a6c1f6129fec9329f474a39cd0b51e
MD5 81af733a0b4cafa00f03f0232c946ca6
BLAKE2b-256 124a0cfd4f659a3522c2b7418ea628b491b8cafe203c1c3b17e7b9c7528de6eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agp_bindings-0.1.9-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agp_bindings-0.1.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 197df20af0f804154bcea1f2050384e6ba2048b3cc4094cfc1e8f7c5a2bfffb9
MD5 e14d796caeb860b441248ad8f2901be9
BLAKE2b-256 a81a98d6967f2ee68cf33cccf5cea58bbc23179fdc419926f01f0162cac6363e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b6a8ad81c4e68bb3a8e7b2eb1f7f70c8120c407c2fb83b18f3b4feb7a12957dc
MD5 0a97a2df1ad3b71bf928ced79d1f7396
BLAKE2b-256 c22c831ecca20578d23f8ffd3a90cdf0ccd83f68b3c4a6691c7a45307023cc5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.9-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6fa8b2ebd28aea8c05962f055d97306d5da00e4130f0481ea158b88ccf871ae
MD5 87d19a635076fdf12e559700d4d563db
BLAKE2b-256 69d1c9ebba32bb4ad697de01aa202ee11e16456ffb42f38d7e4e5f2940d261f1

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