Skip to main content

FLF

RabbitMQ server and client

Installation

To install execute command:

pip install FLF --ignore-installed

Or you can install from source:

python setup.py install

Documentation

Procedure

  • Constructor: Procedure(function, schema=None)
  • Functions: is_valid(data: Parameters) -> bool, call_function(data: Parameters) -> Parameters

Parameters

  • Constructor: Parameters(params=None, files=None)
  • Fields: params, files

RpcServer

Server-node for RabbitMQ

Parameters:

  • host: host of queue
  • port: port of queue
  • username: username of queue
  • password: password of queue
  • procedures: dictionary with server's procedures in format: { str: FLF.Parameters }.
    Each procedure has fields params (dict of parameters) and files (dict of binary objects) and
    returns data in same format (FLF.Parameters(params, files))
  • [ error_callback ]: callable with 3 arguments: exception_name, description and traceback.
    Being called on error happening. By default does nothing

Functions:

  • begin()

Example:

import io

from PIL import Image

import FLF


def add(params, files):
    result_params = {"success": True, "sum": params["a"] + params["b"]}
    result_files = dict()
    
    return result_params, result_files


def get_add_schema():
    return {
        "$schema": "http://json-schema.org/draft-04/schema",
        "id": "http://example.com/example.json",
        "type": "object",
        "required": [
            "a",
            "b"
        ],
        "properties": {
            "a": {
                "type": "integer"
            },
            "b": {
                "type": "integer"
            }
        },
        "additionalProperties": False
    }


def process_image(params, files):
    pil_image = Image.frombuffer("RGB", (params["width"], params["height"]), files["image"])
    image_gray = pil_image.convert("LA")
    
    buffer = io.BytesIO()
    image_gray.save(buffer, format='PNG')
    image_gray_bytes = buffer.getvalue()
    
    return {"success": True}, {"gray_image": image_gray_bytes}


def get_process_image_schema():
    return {
        "$schema": "http://json-schema.org/draft-04/schema",
        "id": "http://example.com/example.json",
        "type": "object",
        "required": [
            "width",
            "height"
        ],
        "properties": {
            "width": {
                "type": "integer"
            },
            "height": {
                "type": "integer"
            }
        },
        "additionalProperties": False
    }


def super_error_callback(exception_name, description, traceback):
    print("OH MY GOD, SOMETHING BAD HAPPENED!")
    print(exception_name, ":", description)
    print(traceback)


def main():
    app = FLF.RpcServer(host="google.com", port=12345, username="mister.robot", password="ecorp.zuck",
                        procedures={
                            "add": FLF.Procedure(add, get_add_schema()),
                            "process_image": FLF.Procedure(process_image, get_process_image_schema())
                        }, error_callback=super_error_callback)
    app.begin()


if __name__ == "__main__":
    main()

RpcConnector

Client-node for RabbitMQ

Parameters:

  • host: host of queue
  • port: port of queue
  • username: username of queue
  • password: password of queue
  • [ error_callback ]: callable with 3 arguments: exception_name, description and traceback.
    Being called on error happening

Functions:

  • begin()
  • call_procedure(name, data: Parameters) -> Parameters

Example:

import FLF


def super_error_callback(exception_name, description, traceback):
    print("OH MY GOD, SOMETHING BAD HAPPENED ON CLIENT!")
    print(exception_name, ":", description)
    print(traceback)


def main():
    app = FLF.RpcConnector(host="google.com", port=12345, username="mister.robot", password="ecorp.zuck",
                           error_callback=super_error_callback)
    app.begin()
    
    result: FLF.Parameters = app.call_procedure("add", FLF.Parameters({"a": 22, "b": 33}))
    print("Sum is:", result.params["sum"])
    
    with open("image.jpg", "rb") as f:
        image_bytes = f.read()
    result: FLF.Parameters = app.call_procedure("process_image", FLF.Parameters({"width": 500, "height": 500},
                                                                    {"image": image_bytes}))
    
    with open("image_gray.png", "wb+") as f:
        f.write(result.files["gray_image"])


if __name__ == "__main__":
    main()

Release files for FLF 1.2.5

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

Source distribution (sdist)

Source distribution for FLF 1.2.5
File Size Uploaded
FLF-1.2.5.tar.gz 6.2 kB Details

Release files / FLF-1.2.5.tar.gz

Download URL FLF-1.2.5.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
594841a093034feeca911863b996980468b7c8dbb1c377d1942c9da004ebf36d
BLAKE2b-256 checksum
How to use checksums
80c726acd5e3173b9fbbbe97cf7262d742806eaa14a74c933e34ec84f52b495b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

Release history Release notifications | RSS feed

This release

1.2.5 This release

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.1

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.6

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5

1 release file

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