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

Uploaded CPython 3.13Windows x86-64

agp_bindings-0.1.11-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.11-cp313-cp313-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

agp_bindings-0.1.11-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.11-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.11.tar.gz.

File metadata

  • Download URL: agp_bindings-0.1.11.tar.gz
  • Upload date:
  • Size: 122.9 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.11.tar.gz
Algorithm Hash digest
SHA256 5f97a7e7d0f588f899bf611e6b9bb5261b5da7c7b20d227ee3c017ca6f756be1
MD5 2037d81e29e6ec16cbd219ef429f67f8
BLAKE2b-256 257549b88ec9a799f46d0378bd49864b9be2b02cb7e0c2cf51dc5690699cf440

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 258739b9330236ab495fd48334254ad7cb49bfbc8ac161e05c0e18b2fd0294f7
MD5 d1c1c769e9bdaeef2dd6e30716f6dbb1
BLAKE2b-256 936713482df6b7c1c8c5132e9efdccab6f59f8abd3dbabefe55d6c287355dd20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b729272b0a0c71dbba5da76f4828b95beb0a08f1e248369060eee9c68d347a3b
MD5 7e99c389d8ec1c94f471a489fc6da598
BLAKE2b-256 2f3e2798b590faa2f770d8cf1a906728eb9cec0853e6492a20bf319409f54177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc1942b170e12b8abd83747ec1c0515e294c0e0758cee686eaffe1a71c6b75a8
MD5 84270f923bc50c13e3b31cc1913eeda8
BLAKE2b-256 6ff0374690a9610c3244e5e151d6ab7b158ef80759b975239fa66f1936aea81a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c2fe6abfde40b04dceb3ab7ebb5d5b2c0225d41b504d24de738ace215d6a4c4a
MD5 3a1fd672806562aa00c1217456652b8d
BLAKE2b-256 040c7325c183654246023be5cc9c9964e8d3ff62fd47235ac4b74ba9f6e91ea2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 80df265c7d962508dd6b1218769d92e7c741bef5c17cf42f652dd2828dcfce89
MD5 33b0b8f9bd3f5569c2560ba0164d4ed0
BLAKE2b-256 80a243db15986f6f7aa2675910c22b16412cf1d0a83928c550cd691e63589fab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f771d01d85ad8778dca3559c74ca21de0e839e8cdfeaf4f5640563e5c8697cf
MD5 6e32b9ae3c18b4a1664ee39f9ae5acab
BLAKE2b-256 4d4391724450863d1c826a311d612c0d68243f36a9127f5e9cd9fb45b65149e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 45ddfaaa76a11820100fb1860812dc75b4267e31d805985a5b580c0fdc0147ab
MD5 72258c65213b6262e30401d0c772e54f
BLAKE2b-256 097a0ed4e7de04b3d8dcff25dfb05ed9db740f232930d6301d19c2c484b73264

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 049d75d6ac209375643263b83c2a7fff987f45c7dadf99ca0dd8034beac83381
MD5 d2cafce89574838f4ca4779cfb594581
BLAKE2b-256 f73c8915c6204a4f0fd8f4ddd3b096add902ddc544561db6c960bcc8fb3e597f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 418b31c04229f657be9904323c1fef3f96ddefb6be5d0ec0a30aea30215acaba
MD5 c88298c8302c1b1dedd16bdaf90f0c96
BLAKE2b-256 26a4e7309c88833fd99d046c3d3f584309c36463f833264cdd1e189948d7abc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 85185c753112581a702e97d2bccdb1e1f3028b7c01a6f011395c2ecc4a44edb3
MD5 7b0bb687948ff032e4a5c9a135298cbe
BLAKE2b-256 64724d91f57473c65dda5c4baae619282b093dbadc3827ba534911d1ac02234c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 8c2c20f7b0104b0c94a2b4c31130142d057a84ae694a060a372eeba23d6678e4
MD5 2b8ecc48ce6f464a64b0e7c961aa1620
BLAKE2b-256 9b7317cb45bcf5da65371fbabe08b02f8cb2f92dad034ab1c1aa996dcb46c290

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b99e03e14805de952d87167f146800b26c1a79f804832caf74503771be2db8c5
MD5 63f6cd0b811d6a297d0879104eb362b7
BLAKE2b-256 c7e527df421acd09175bbc75ceb01dd51d9e6a0769956e0474e5644fdf764a06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0798a33d93fbdae62f4aa3d961810cf96dbcc89be65ef3ce4b3c9b924c4c5359
MD5 480e1779d4136b82ad0f95c8661c22dd
BLAKE2b-256 48a1e424772c50348a65d74784e3ecc51de6d84441ccb2136388c6aa8013aa37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp39-cp39-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 43fd426298de89174aaedb04c00914cead43e13708fd31d68fffc01b7fdfb89f
MD5 99c555179f223dc6b778615566f0e90f
BLAKE2b-256 cb93739ff586828dca9b063d0ec294c801534d555e11e9900a4301dcebe1e58b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agp_bindings-0.1.11-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b186c0482e309b49b215a300331e5654542cea6f1ed59f0961c8f7988b4476d7
MD5 5912c0a72957692a72065d59579409bc
BLAKE2b-256 77bb71cf234e40492534af03846984c5b775b0a7f0d4f4beac387bceee0162bb

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