Skip to main content

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.

Metadata

Release files for remote-functions 1.0.1

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

Source distribution (sdist)

Source distribution for remote-functions 1.0.1
File Size Uploaded
remote-functions-1.0.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for remote-functions 1.0.1
File Interpreter ABI Platform
remote_functions-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / remote-functions-1.0.1.tar.gz

Download URL remote-functions-1.0.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b8a7e429f16c07721fcd4709839216d97dfa4eff48292d15e1dbe121f5d93742
BLAKE2b-256 checksum
How to use checksums
fb3a231cb5b346abe0781a453c35ca97fccc946507fdf7a84deef54d2176528d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / remote_functions-1.0.1-py3-none-any.whl

Download URL remote_functions-1.0.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2ac56aed26b88eb57975c99236b8296dc842add1f598b26874f144054ee71fb
BLAKE2b-256 checksum
How to use checksums
2210c68760b70b41c959f9f7911ad6708ebc66797f66e816a2dc08b70a8bd9f9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

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