Skip to main content

Allows you to seemingly call a server function directly from the client.

Project description

forthright

forthright is a wrapper around Flask that allows you to (seemingly) directly call functions on the server from the client. It saves you the hassle of needing to pack your arguments into a json and unpack them on the server.

A simple example

# backend.py
from forthright import forthright_server
from flask import Flask

app = Flask(__name__)
frs = forthright_server(app)

def add_and_sub(numA, numB):
    return numA + numB, numA - numB

frs.export_functions(add_and_sub)

if __name__ == '__main__':
    app.run(port=8000)
# client.py
from forthright import forthright_client

url = 'http://127.0.0.1:8000'
frc = forthright_client(url)
frc.import_functions('add_and_sub')

sum, diff = frc.add_and_sub(8, 2)
print('%d %d' %(sum, diff)) # -> 10 6

Installation

pip install -i https://test.pypi.org/simple/ forthright

Limitations

You can only pass arguments by value, not by reference. For example, if an argument is a list, the server function will receive a copy of that list.

If an argument is a custom object, the class definition must be present in both the client code and the server code.

Warning: By default, this code deserializes pickled data on the server which is unsafe. There is an optional Safe Mode to instead send data with json, but this will prevent you from sending custom objects. To turn on Safe Mode, set safe_mode=True when instantiating both forthright_server and forthright_client:

frs = forthright_server(app, safe_mode=True)

frc = forthright_client(url, safe_mode=True)

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

forthright-0.0.5.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

forthright-0.0.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file forthright-0.0.5.tar.gz.

File metadata

  • Download URL: forthright-0.0.5.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.1

File hashes

Hashes for forthright-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f1d064e8e4b7a47eb1a3cf7c84ca3d37bbfc4a4315de2bf6f2c6b26fe7bc48ae
MD5 8a5d1642e80f0dee2305593f7adcaf27
BLAKE2b-256 e2e5763620561fe512f8b360b39d978b1f05c75c1a0f800fb3bf703c4436fbc0

See more details on using hashes here.

File details

Details for the file forthright-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: forthright-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.1

File hashes

Hashes for forthright-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c7ce8518287825ec2482b026000ebd354c48f374d1e64c3bf9d29c49be233a78
MD5 2357d07e58bda83790bfcb53c632b823
BLAKE2b-256 8a2af10d6c43a75339e23d37961f1c2a2c815c2a6e6f592972355f8a026b39b4

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