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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file loko-extensions-0.0.3.tar.gz.

File metadata

  • Download URL: loko-extensions-0.0.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for loko-extensions-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bc018126103882e16d9721d4a34e706b32e248cc61dcf0d7f607cda8ec2288cb
MD5 5e54225e680d2d6036be7d8f07bdeaa6
BLAKE2b-256 b79b59c1c1041f1f888700b94052cdd5f7fb4e5d691fbd89ede1eb5a9617f4e1

See more details on using hashes here.

File details

Details for the file loko_extensions-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for loko_extensions-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6f15e74c4d839fc6b082fc635c180945df46b9f6aecc0a3ce023ca74edc10eb6
MD5 07a7359e399f6d242ee223678be4a301
BLAKE2b-256 797d97c19fe6a71ff0b303e813f3bed637824845b7d632619c98664e768e551f

See more details on using hashes here.

Supported by

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