Skip to main content

PyEasyEmbed

PyEasyEmbed is a Python implementation of EasyEmbed, a collection of tools to integrate python code into other applications using shell commands. Instead of multiple arguments, a EasyEmbed app expects one JSON-Object to deal with..

Installation

You can install the lastest release of PyEasyEmbed from Pypi:

pip install PyEasyEmbed

Otherwise you can also install it from source:

git clone https://github.com/swip3798/PyEasyEmbed.git
cd PyEasyEmbed
python setup.py install

Usage

PyEasyEmbed implements all CommandServer types of EasyEmbed. Both are mainly used the same way, the major difference lies in the execute function.
CliCommandServer example:

# When using the CliCommandServer, import is as directly as possible to avoid additional overhead
from EasyEmbed.command_server import CliCommandServer

# The version number is the number of your application which can be used by your main app to determine if the embedded app is compatible
ser = CliCommandServer(version = "0.1")

# A command responder which returns the input JSON Object, the name of the command is determined by the name of the function
@ser.command
def echo(data):
    return data

# Call the execute function to dispatch the input to the available commands
ser.execute()

HttpCommandServer example:

from EasyEmbed import HttpCommandServer

# The version number is the number of your application which can be used by your main app to determine if the embedded app is compatible
ser = HttpCommandServer(version = "0.1")

# A command responder which returns the input JSON Object, the name of the command is determined by the name of the function
@ser.command
def echo(data):
    return data

# Call the execute function to startup the HTTP Server, starting on the default port 43512
ser.execute(debug=True, port = 43512)
# If you want to use a different server backend, use the server paramenter (here: Tornado)
ser.execute(debug=True, port = 43512, server = "tornado")

The HTTP server is implemented using bottlepy. This allows you to use any server backend which is compatible with bottle. This is highly recommended because it speeds up the response time by a lot (e.g. when switching to tornado, the response time decreases from 200ms to 10 ms). The full list of available server backends can be found in the Bottle docs.

CliCommand structure

A PyEasyEmbed command has always one or two arguments. The first is the name of the called command, the second is a JSON-Object which is parsed and deliverd as a parameter to the command function. Depending on your shell interface you may need to escape quotes. If no JSON-Object is provided, the data paramter will be None.

Example call

python example.py echo "{\"hello\":\"world\"}"

The command server has a standard info command which prints the version number of your app, the python version running etc.

Response structure

To the command call from above the response would be the following:

{
    "status": 0,
    "response": {"hello":"world"}
}

In case an exception occured during the command function, the following is returned:

{
    "status": 1,
    "message": "Exception occured while executing command!",
    "exception": Traceback String
}

In case the command is not defined:

{
    "status": -1,
    "message": "Command does not exist!"
}

In case the JSON-Object could not be parsed:

{
    "status": -3,
    "message": "JSON data could not be parsed!"
}

Release files for PyEasyEmbed 0.2.1

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

Built distribution (wheel)

Table of built distributions (wheels) for PyEasyEmbed 0.2.1
File Interpreter ABI Platform
PyEasyEmbed-0.2.1-py3-none-any.whl Python 3 none any Details

Release files / PyEasyEmbed-0.2.1-py3-none-any.whl

Download URL PyEasyEmbed-0.2.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08954558fdfa437ca2adaa03c445b2e71857194fad8347746e731c72e4d6cb5a
BLAKE2b-256 checksum
How to use checksums
5a8c69af34c2b993923dc2747229cca3a08a90c31611ff2fcbcf0b6dd84342ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.2.0

1 release file

0.1.2

2 release files

0.1.0

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