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: str):
    ...

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 string arguments will work. These functions should also either return None or a string.

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("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("params")
...

Parallelize Function Execution

In order to execute a function with multiple parameters in parallel, you can use parallelize.

from preemo.worker import parallelize

do_something = get_function(name="some_name", namespace="dev")
results = parallelize(
    do_something,
    params=[
        "params1",
        "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 = parallelize(
    do_something,
    count=10
)
...

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.2.0.tar.gz (17.8 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.2.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for preemo_worker_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ffdd4b17ae1f81aa944c4403fc3c85e422689c47b37391bc10d48c4971c2cfcf
MD5 aa7af148a26015246406e4b09844002e
BLAKE2b-256 aa755e203fb90cc0e3c7cfe8e986109b4ec3ea04863eb18260b3602db5e8a22e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for preemo_worker_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7cfe53c42c2ba2e02979e670e96f14bf9d4e388dc2c2860e238ffe6a73f65f07
MD5 c8f529b715c3f85b14c469f3220e6213
BLAKE2b-256 d916634ea7fbfe49640c3a0c4a22be87637c0d9fb095a2f5ce7b5914302e6875

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