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.

Example main.py

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

####################################################################################
#
# About: A top-down view of what is going on
#
####################################################################################
"""
This example script demonstrates how to use the RemoteFunctions class to perform remote function
execution over HTTP. It operates in two modes:
    1. Server mode: Registers functions and starts a Flask server that listens for remote calls.
    2. Client mode: Connects to the remote server, retrieves the available function names, and
       invokes remote functions by sending their arguments as pickled data.
All data exchanges between the client and server are serialized using pickle to ensure reliable communication.
"""

####################################################################################
#
# How To Run
#
####################################################################################
"""
To run the script as a server:
    python main.py server
This command starts the Flask server on 0.0.0.0:5000 and registers example functions for remote invocation.

To run the script as a client:
    python main.py client
Make sure the server is running before executing the client. The client connects to the server (assumed
to be running on localhost:5000), retrieves the list of available functions, and then calls some of them,
printing the results.
"""

from remote_functions import RemoteFunctions
import sys

if __name__ == "__main__":

    if len(sys.argv) > 1 and sys.argv[1] == "server":
        rf = RemoteFunctions()

        # Example functions to be registered on the server.
        def a(b):
            """Return the input value."""
            return b

        def add(x, y):
            """Return the sum of x and y."""
            return x + y

        # Add functions to the registry.
        rf.add_function(a)
        rf.add_function(add)

        # Start the server (blocking call).
        rf.start_server(host="0.0.0.0", port=5000)

    elif len(sys.argv) > 1 and sys.argv[1] == "client":
        rf = RemoteFunctions()

        # Run as client. Assumes server is running on localhost:5000.
        rf.connect_to_server("localhost", 5000)
        try:
            funcs = rf.get_functions()
            print("Remote functions available:", funcs)
            result_add = rf.call_remote_function("add", 10, 20)
            print("Result of add(10, 20):", result_add)
            result_a = rf.call_remote_function("a", "Hello, Remote!")
            print("Result of a('Hello, Remote!'):", result_a)
        except Exception as e:
            print("An error occurred:", e)
    else:
        print("Usage: python main.py [server|client]")

Project details


Release history Release notifications | RSS feed

This version

0.1.8

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.1.8.tar.gz (7.1 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.1.8-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: remote_events-0.1.8.tar.gz
  • Upload date:
  • Size: 7.1 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.1.8.tar.gz
Algorithm Hash digest
SHA256 47d2ba129fc1a4e9a4ab2cf3fa390ab10e6a01513fc2473f4b283e70962ef832
MD5 069c80b5b69f5f880db6ffb58a41bd6a
BLAKE2b-256 302a776023e402d84d10f3d61c98c5779bd7688a171a7711ed4f68c027604308

See more details on using hashes here.

File details

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

File metadata

  • Download URL: remote_events-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 34686b8a3ef3dfa4213bedde3e05c3ec26d6044ad4c54c92bfa2795b29dba4b8
MD5 75a47953eb51f0f7b0f96fd86637363e
BLAKE2b-256 0d6e0e6825295c1d709cdbc80f451b770f758b2139fb592d40f893ca3955c774

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