Skip to main content

vrpc

Variadic Remote Procedure Calls for Python

vrpc is an asynchronous, event-driven Remote Procedure Call (RPC) framework for Python. It allows you to seamlessly expose standard Python classes and functions over an MQTT message broker, making them instantly callable from anywhere in the world.

By leveraging MQTT and Python's asyncio, vrpc bypasses NATs, firewalls, and complex networking setups, allowing for bi-directional communication, dynamic object instantiation, and remote continuous event streaming.

It is 100% protocol-compatible with the Node.js / JS vrpc implementation.

✨ Features

  • Zero Boilerplate: Register existing Python classes without modifying their code.
  • Fully Asynchronous: Built from the ground up on modern asyncio and aiomqtt.
  • Stateful Instances: Create, manage, and delete remote object instances dynamically. Shared instances can be interacted with by multiple clients simultaneously.
  • Remote Event Listeners: Pass Python callables as arguments to remote functions. VRPC automatically binds them to MQTT streams (perfect for real-time sensor data or status updates).
  • Batch Executions: Broadcast method calls to all instances of a class across multiple distributed agents in a single line of code (call_all).

📦 Installation

Since vrpc is modern Python package (PEP 621), you can install it directly via pip:

pip install vrpc

Requirements: Python 3.8+

🚀 Quick Start

To use VRPC, you need two components: an Agent (which hosts your code) and a Client (which remotely calls it). Both connect to a central MQTT broker.

1. The Agent (Server)

First, write a standard Python class. Let's create a Counter that maintains state and can emit continuous events via a callback.

# agent.py
import asyncio
from vrpc import VrpcAdapter, VrpcAgent

class Counter:
    def __init__(self, initial_value=0):
        self._count = initial_value
        self._callback = None

    def on_change(self, callback):
        """Registers a callback for continuous state updates."""
        self._callback = callback

    def increment(self, step=1):
        """Increments the counter and triggers the callback."""
        self._count += step
        if self._callback:
            self._callback(self._count)
        return self._count

# 1. Register the class so VRPC knows about it
VrpcAdapter.register(Counter)

async def main():
    # 2. Configure the Agent to connect to a broker
    agent = VrpcAgent(
        domain="my.custom.domain",
        agent="python-agent-1",
        broker="mqtt://broker.hivemq.com:1883" # Public test broker
    )

    print("Agent is starting...")
    await agent.serve()

if __name__ == "__main__":
    asyncio.run(main())

2. The Client

Now, from a completely different machine, process, or network, we can connect a client, create an instance of that Counter, and interact with it.

# client.py
import asyncio
from vrpc import VrpcClient

async def main():
    # 1. Connect to the same broker and domain
    client = VrpcClient(
        domain="my.custom.domain",
        broker="mqtt://broker.hivemq.com:1883"
    )
    await client.connect()

    # 2. Create a remote instance of the Counter
    print("Creating remote Counter instance...")
    counter = await client.create(
        agent="python-agent-1",
        class_name="Counter",
        instance="my-shared-counter",
        args=[10]  # Passes '10' to initial_value
    )

    # 3. Define a local function to handle remote events
    def handle_update(new_val):
        print(f" -> Continuous Event Received! Counter is now: {new_val}")

    # VRPC magically wires this Python function over MQTT
    await counter.on_change(handle_update)

    # 4. Call remote methods
    print("Calling increment(5)...")
    result = await counter.increment(5)
    print(f"RPC Returned: {result}")

    # Cleanup
    await client.end()

if __name__ == "__main__":
    asyncio.run(main())

🏗 Architecture Concepts

VRPC organizes remote execution using a specific hierarchy:

  • Domain: The highest level of isolation. Agents and Clients must share the same domain to see each other.
  • Agent: A physical process hosting VRPC code. A single domain can have hundreds of distributed agents.
  • Class: A registered Python class available for instantiation.
  • Instance: A specific, stateful object created from a Class. Instances can be Shared (visible to all clients) or Isolated (visible only to the client that created it).

🤝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the project.
  2. Install with test dependencies: pip install -e .[test]
  3. Run local adapter tests: pytest tests/adapter/test_adapter.py
  4. Run integration tests (requires Docker): cd tests/agent && ./test.sh

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for vrpc 3.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vrpc 3.0.3
File Size Uploaded Provenance
vrpc-3.0.3.tar.gz 20.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for vrpc 3.0.3
File Interpreter ABI Platform
vrpc-3.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / vrpc-3.0.3.tar.gz

Download URL vrpc-3.0.3.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
18f1e75389a7d9707796e444abd80eb228bf7d838e0a39ebb2d89a42b0083f97
BLAKE2b-256 checksum
How to use checksums
28f98050ab08007279e7cafede173fd174bbb9762df244b2550c223cf4363bde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / vrpc-3.0.3-py3-none-any.whl

Download URL vrpc-3.0.3-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca02706efb7626e42af4cb6318aa384d6844ac9a609bf1a9dc6bac3cd371257e
BLAKE2b-256 checksum
How to use checksums
ff8ecc91a25167b056554bb8d803d5aa1366dbc0bf8006e7bf6bb5a8b757e16d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for vrpc 3.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page