Skip to main content

A framework for Loko extensions

Project description

  Loko - Extensions


Loko Extensions helps in writing LoKo's custom components.

Docs | Tutorial | LoKo AI

Installation

   (.venv) $ pip install loko-extensions

Example

To create new components you have to define its inputs, outputs and arguments:

from loko_extensions.model.components import Arg, Input, Output, Component, save_extensions

n = Arg(name="n", type="number", label="n", helper='Number of # in the output', value=1)
input = Input(id='input', label='Input', service='myfirstservice', to='output')
input_f = Input(id='file', label='File', service='upload_file', to='output')
output = Output(id='output', label='Output')
comp1 = Component(name="My First Component", args=[n], inputs=[input, input_f], outputs=[output], group="Custom")
save_extensions([comp1])

And create your services:

import sanic
from loko_extensions.business.decorators import extract_value_args

app = sanic.Sanic('first_project')

@app.post('/myfirstservice')
@extract_value_args()
async def f(value, args):
    n = int(args.get('n'))
    return sanic.json(dict(msg=f"{'#'*n} {value} {'#'*n}"))

@app.post('/upload_file')
@extract_value_args(file=True)
async def f2(file, args):
    n = int(args.get('n'))
    return sanic.json(dict(msg=f"{'#'*n} File name: {file[0].name} {'#'*n}"))

app.run("0.0.0.0", port=8080)

Here is your new component in LoKo:

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

loko-extensions-0.0.3.tar.gz (8.5 kB view hashes)

Uploaded Source

Built Distribution

loko_extensions-0.0.3-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page