Skip to main content

No project description provided

Project description

Preemo Worker SDK

PyPi Version License

This subrepo contains the python implementation of the Preemo Worker SDK.

Installation

pip install preemo-worker-sdk

Usage

Register Function

In order to register a function with Preemo workers, you can use register to decorate your functions.

from preemo.worker import register

@register(name="some_name", namespace="dev")
def do_something(params: bytes):
    ...

Both parameters, name and namespace, are optional. If the name isn't specified, it will default to the name of the function. If the namespace isn't specified, it will default to a global namespace.

@register
def do_something(params: str):
    # registers with name do_something in the global namespace
    ...

At the moment, only functions that take 0 or 1 bytes arguments will work. These functions should also either return None or bytes.

Execute Function

In order to execute a function that you have previously registered with Preemo workers, you can use get_function.

from preemo.worker import get_function

do_something = get_function(name="some_name", namespace="dev")
result = do_something(b"params")
...

The second parameter, namespace, is optional. If the namespace isn't specified, it will default to a global namespace.

# gets the function named do_something in the global namespace
do_something = get_function("do_something")
result = do_something(b"params")
...

Parallel Function Execution

In order to execute a function with multiple parameters at the same time, you can use parallel.

from preemo.worker import get_function, parallel

do_something = get_function(name="some_name", namespace="dev")
results = parallel(
    do_something,
    params=[
        b"params1",
        b"params2",
        ...
    ]
)
...

If your function doesn't take a parameter and you'd like to run multiple instances of it in parallel, you can use the count parameter.

do_something = get_function(name="some_name", namespace="dev")
results = parallel(
    do_something,
    count=10
)
...

Results

In order to view the result of an executed function, you can call .get().

from preemo.worker import get_function

do_something = get_function(name="some_name", namespace="dev")
result = do_something(b"params")
value = result.get()
...

Contributing

Contribution guidelines for this project

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

preemo_worker_sdk-0.5.1.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

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

preemo_worker_sdk-0.5.1-py3-none-any.whl (51.0 kB view details)

Uploaded Python 3

File details

Details for the file preemo_worker_sdk-0.5.1.tar.gz.

File metadata

  • Download URL: preemo_worker_sdk-0.5.1.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for preemo_worker_sdk-0.5.1.tar.gz
Algorithm Hash digest
SHA256 6ba625d20a8bb62e67c6e9f570cd03137fe2f8123d235cd215e4c806d320b106
MD5 ea759029c21c43f9993854b688f1c95d
BLAKE2b-256 646d216c6a44553cf2a1ddd74510f289b1afd60eb27ab4e95dbf110ed787132e

See more details on using hashes here.

File details

Details for the file preemo_worker_sdk-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for preemo_worker_sdk-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62d1851cc4d51618a20e16bb7a5dde0cb833749503cb07adad7f8d0a153ee794
MD5 3df5c838d1b24fe9ed5a50dd2bf2d49d
BLAKE2b-256 b5b7984cde51eca3fd4ae2c19262e9d933a3add61b52d14761e4f746283209e1

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