consume the Forio Epicenter API in Python

Hello everyone,

I am trying to consume the Forio Epicenter API in Python, however, I have not succeeded, does anyone know how to make the connection, could you help me.

Thank you very much.

Hi,

To make effective use of Python models you must create your user interfaces in HTML-- we recommend using the Flow JS library. This let’s you bind HTML tags to model variables, and buttons to call model functions.

For example, here’s a trivial python model with a global variable and a function:


def double():
  global abc
  abc = abc*2
  return abc

Save this as a file model.py in the model folder.

Then create a file “index.html” in the “interface” folder

<html>

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
    <script src="//forio.com/tools/js-libs/2.9.1/epicenter.min.js"></script>
    <script src="//forio.com/tools/js-libs/flow/latest/flow.js"></script>

    <script>
        $(function() {
            Flow.initialize();
        });
    </script>
</head>

<body data-f-model="model.py">

    <p> The value of the variable 'abc' is: <span data-f-bind="abc"></span></p>.
    <p>Call the model function 'double' by clicking the button below.</p>
    <p><button data-f-on-click="double" />Double the Value</p>
</body>
</html>

When you run the sim, it looks like this:

image

Clicking the button calls the ‘double’ function

image

That’s the basics.

Some details on working with Python in Epicenter are here
https://forio.com/epicenter/docs/public/model_code/python/

FlowJs docs are here
https://forio.com/epicenter/docs/public/data_binding_flow_js/

Javascript APIs are also available for more sophisticated simulation behavior:
https://forio.com/epicenter/docs/public/api_adapters/

Good luck! Let us know if you have further questions!