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.pywith:
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.pywith:
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)
| File | Size | Uploaded | |
|---|---|---|---|
| remote-functions-1.0.1.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|