No project description provided
Project description
Preemo Worker SDK
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file preemo_worker_sdk-0.2.2.tar.gz.
File metadata
- Download URL: preemo_worker_sdk-0.2.2.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3961f1a547b39feefb10398e5900b0182727c45747790c8dcea9d69aafbbcb1c
|
|
| MD5 |
b72509e312a6dd1290ce068d75e3df1d
|
|
| BLAKE2b-256 |
dda968e321667d3785fef223c3e7c73bb3d0f8b058ecc89cdbfaeb3296ea1fd0
|
File details
Details for the file preemo_worker_sdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: preemo_worker_sdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
266892c34509365634948c27f23610d32cfdd53a68cd8ad4cc10b769dce01397
|
|
| MD5 |
29d639b812cbc86ab56025b5fa1777b3
|
|
| BLAKE2b-256 |
6849e01cb1aeca4b3f5d1bd5e581f315e0a86b55be6ca58713de0af2bdf71809
|