A framework for Loko extensions
Project description
Loko - Extensions
Loko Extensions helps in writing LoKo's custom components.
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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for loko_extensions-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f15e74c4d839fc6b082fc635c180945df46b9f6aecc0a3ce023ca74edc10eb6 |
|
MD5 | 07a7359e399f6d242ee223678be4a301 |
|
BLAKE2b-256 | 797d97c19fe6a71ff0b303e813f3bed637824845b7d632619c98664e768e551f |