How to test opyrator in linux

Introduction

With opyrator you can create a web function from any python function, it used fastapi, streamlit and pydantic.

For this example i just wanted to test what is posible also using pydantic to change some input and output field

Setup

Start by creating your python virtual environment and activating it

python3 -m venv opyrator
cd opyrator
source bin/activate

After that you can install opyrator and what is more needed

pip3 install opyrator

Create a first test file using vim, if you get a powerline error run pip3 install powerline-status

"""Opyrator.

Testing opyator
Test with:

opyrator launch-ui test:testing
"""

from pydantic import BaseModel
from enum import Enum

class Gender(str, Enum):
    """Gender enum."""

    man = "man"
    vrouw = "vrouw"
    onbekend = "onbekend"

class Input(BaseModel):
    """Input BaseModel for testing function."""

    name: str
    age: int
    gender: Gender

class Output(BaseModel):
    """Output BaseModel for testing function."""

    message: str
    days: int
    lijst: list

def testing(input: Input) -> Output:
    """Testing testing."""
    proef = "Hallo %s, %d cool en zelf %s" % (input.name, input.age, input.gender.value)
    lijst=[]
    for jaar in range(input.age):
      lijst.append(jaar*365)

    return Output(message=proef, days=(input.age * 365),lijst=lijst)

You can after that start it up and connect to it with a browser

opyrator launch-ui test:testing

For more info see also github ml-tooling / opyrator