Skip to main content

remote-functions provides type enforced remotely run Python functions

Project description

remote-functions


Remote-functions provides type enforced remotely run Python functions. Using remote-functions, developers can run Python functions from any device with any programming language.

Key Features

  • Fast: Built on top of FastAPI.
  • Easy: Designed to be easy to use and learn.
  • Type Checking: Built-in type checking for function arguments.

Requirements

Python 3.8+

Installation

$ pip install remote-functions

Example

Server side

  • Create a file server.py with:
from remote_functions import remote, start


@remote(enforce_types=True)
def add(a: int, b: int):
    return a + b

if __name__ == '__main__':   
    start()

Client side

  • Create a file client.py with:
from remote_functions import Executor

api_url = "http://127.0.0.1:8000"
ex = Executor(api_url)

resp = ex.execute("add", a=2, b=3)
if resp.exit_code == 0:
    # function executed successfully
    print(resp.response)  # 5
elif resp.exit_code == 1:
    # function arguments were malformed
    print(resp.response)
elif resp.exit_code == 2:
    # function had an exception during execution
    print(resp.response)  # gives us the full traceback for easy debugging
Add authentication

If you want to protect your application from unauthorized access, you can enable key based authentication.

To enable authentication change your server.py file to:

from remote_functions import remote, start, Settings

settings = Settings()
settings.authorization = "super_secret_key"


@remote(enforce_types=True, settings=settings)
def add(a: int, b: int):
    return a + b


if __name__ == '__main__':
    start()

Then in client.py add the authorization argument

from remote_functions import Executor

api_url = "http://127.0.0.1:8000"
ex = Executor(api_url, authorization="super_secret_key")

resp = ex.execute("add", a=2, b=3)
if resp.exit_code == 0:
    # function executed successfully
    print(resp.response)  # 5
elif resp.exit_code == 1:
    # function arguments were malformed
    print(resp.response)
elif resp.exit_code == 2:
    # function had an exception during execution
    print(resp.response)  # gives us the full traceback for easy debugging

Run it

First start the server with:

$ python server.py

Then run client.py to test your remote function

$ python client.py
Deploy in production

To deploy your application for production you just have to slightly modify your server.py file by changing the host and port

from remote_functions import remote, start


@remote(enforce_types=True)
def add(a: int, b: int):
    return a + b


if __name__ == '__main__':
    start(host="0.0.0.0", port=80)

License

This project is licensed under the terms of the MIT license.

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

remote-functions-1.0.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

remote_functions-1.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file remote-functions-1.0.1.tar.gz.

File metadata

  • Download URL: remote-functions-1.0.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.0

File hashes

Hashes for remote-functions-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b8a7e429f16c07721fcd4709839216d97dfa4eff48292d15e1dbe121f5d93742
MD5 2391e78987535bae7507a88e8f1d417b
BLAKE2b-256 fb3a231cb5b346abe0781a453c35ca97fccc946507fdf7a84deef54d2176528d

See more details on using hashes here.

File details

Details for the file remote_functions-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: remote_functions-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.0

File hashes

Hashes for remote_functions-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2ac56aed26b88eb57975c99236b8296dc842add1f598b26874f144054ee71fb
MD5 a81f64b90a40a912a25d45287e762cb4
BLAKE2b-256 2210c68760b70b41c959f9f7911ad6708ebc66797f66e816a2dc08b70a8bd9f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page