Skip to main content

Connor's Remote Events (RE) is a simple library that allows the end-user to call python functions from another server.

Project description

Connor's Remote Events (RE)

Connor's Remote Events (RE) is a simple library that allows the end-user to call python functions from another server. This is highly powerful if you are coding an application that offloads processes to another server.

If you want to offload automation tasks to another device, this is the package to use. It is extremely reliable and robust for minimum-effort python automation.

To install: pip install remote-events

First example

Example main.py

"""
Main Example Script for RemoteFunctions

This script demonstrates remote function execution over HTTP using the RemoteFunctions class.
It operates in two modes:
    1. Server mode: Registers functions and starts a Flask server to handle remote calls.
    2. Client mode: Connects to the server, retrieves available functions, and invokes them remotely.

All communications are serialized with pickle for reliable data exchange.

Usage:
    To run as a server:
        python main.py server
    To run as a client:
        python main.py client

Note: Ensure the server is running before starting the client.
"""

from remote_functions import RemoteFunctions
import sys
from typing import Any

# Initialize RemoteFunctions with password authentication.
# set is_queue=True for a queue-based call system, to act similarly as a mutex
rf = RemoteFunctions(password="Whoop!-", is_queue=False) 

@rf.as_remote()
def a(b: Any) -> Any:
    """Return the input value."""
    return b

@rf.as_remote()
def add(x: float, y: float) -> float:
    """Return the sum of x and y."""
    return x + y

if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "server":
        # Start the server (blocking call) on 0.0.0.0:5000.
        rf.start_server(host="0.0.0.0", port=5001)

    elif len(sys.argv) > 1 and sys.argv[1] == "client":
        # Connect to the server running on localhost:5000.
        rf.connect_to_server("localhost", 5001)

        print("Invoking function 'a' with argument 'Hello World!'")
        result = a("Hello World!")
        print("Result:", result)

        print("Invoking function 'add' with arguments 1 and 3")
        result = add(1, 3)
        print("Result:", result)
    else:
        print("Usage: python main.py [server|client]")

In two terminals:

  1. First terminal, run the server with python main.py server

  2. Second terminal, run the client with python main.py client

Second example

The purpose is for you to create your own script, like my_functions.py and replicate the python script to the server and client.

For example:

my_functions.py

from remote_functions import RemoteFunctions
import sys
from typing import Any

# Initialize RemoteFunctions with password authentication.
# set is_queue=True for a queue-based call system, to act similarly as a mutex
rf = RemoteFunctions(is_queue=False) 

@rf.as_remote()
def a(b: Any) -> Any:
    """Return the input value."""
    return b

@rf.as_remote()
def add(x: float, y: float) -> float:
    """Return the sum of x and y."""
    return x + y

server.py

You will run this on the server-side:

import my_functions

my_functions.rf.set_password("Whoop!-")
my_functions.start_server(host="0.0.0.0", port=5001)

client.py

You will run this on your local device:

import my_functions

my_functions.rf.set_password("Whoop!-")
my_functions.connect_to_server("localhost", 5001)

print("Invoking function 'a' with argument 'Hello World!'")
result = my_functions.a("Hello World!")
print("Result:", result)

print("Invoking function 'add' with arguments 1 and 3")
result = my_functions.add(1, 3)
print("Result:", result)

In two terminals:

  1. First terminal, run the server with python server.py

  2. Second terminal, run the client with python client.py

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remote_events-0.2.38.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remote_events-0.2.38-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file remote_events-0.2.38.tar.gz.

File metadata

  • Download URL: remote_events-0.2.38.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for remote_events-0.2.38.tar.gz
Algorithm Hash digest
SHA256 bce8d3ee68ca3091868ecb786a1609de189a3dba089cbd3f9de2c7f3bbbe8cfc
MD5 a97f0686a57593d1e3262dd58d691598
BLAKE2b-256 62bad6071479751bf2c93142027eb86f9f7b75833e7b59ef1ec3d830ee02f647

See more details on using hashes here.

File details

Details for the file remote_events-0.2.38-py3-none-any.whl.

File metadata

  • Download URL: remote_events-0.2.38-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for remote_events-0.2.38-py3-none-any.whl
Algorithm Hash digest
SHA256 9b3dcfbd0116470ee76dafbe9a02158fb9cf08aa675e39f952a3d65252c74496
MD5 b68a0b76d4756957900691160a093a55
BLAKE2b-256 59543046aad25f7d36d801a01e93c95c6a46cf8cad71bfc5ac163fd99acfa7c0

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