Netflix Conductor Python SDK
Project description
Netflix Conductor Client SDK
To find out more about Conductor visit: https://github.com/Netflix/conductor
conductor-python
repository provides the client SDKs to build Task Workers in Python
Setup Virtual Environment
$ virtualenv conductor
$ source conductor/bin/activate
Install conductor-python
package
$ python3 -m pip install conductor-python
Write a simple worker
from conductor.client.automator.task_handler import TaskHandler
from conductor.client.configuration.configuration import Configuration
from conductor.client.configuration.settings.authentication_settings import AuthenticationSettings
from conductor.client.http.models import Task, TaskResult
from conductor.client.http.models.task_result_status import TaskResultStatus
from conductor.client.worker.worker_interface import WorkerInterface
class SimplePythonWorker(WorkerInterface):
def execute(self, task: Task) -> TaskResult:
task_result = self.get_task_result_from_task(task)
task_result.add_output_data('key1', 'value')
task_result.add_output_data('key2', 42)
task_result.add_output_data('key3', False)
task_result.status = TaskResultStatus.COMPLETED
return task_result
def get_polling_interval_in_seconds(self) -> float:
return 1
def main():
# Point to the Conductor Server
configuration = Configuration(
server_api_url='https://play.orkes.io/api',
debug=True,
authentication_settings=AuthenticationSettings( # Optional if you are using a server that requires authentication
key_id='KEY',
key_secret='SECRET'
)
)
# Add three workers
workers = [
SimplePythonWorker('python_task_example'),
]
# Start the worker processes and wait for their completion
with TaskHandler(workers, configuration) as task_handler:
task_handler.start_processes()
task_handler.join_processes()
if __name__ == '__main__':
main()
Start polling for the work
python main.py
See Using Conductor Playground for more details on how to use Playground environment for testing.
Worker Configurations
Worker configuration is handled via Configuration
object passed when initializing TaskHandler
Server Configurations
- server_api_url : Conductor server address. e.g.
http://localhost:8000/api
if running locally - debug:
true
for verbose loggingfalse
to display only the errors - authentication_settings: see below
- metrics_settings: see below
Metrics
Conductor uses Prometheus to collect metrics.
- directory: Directory where to store the metrics
- file_name: File where the metrics are colleted. e.g.
metrics.log
- update_interval: Time interval in seconds at which to collect metrics into the file
Authentication
Use if your conductor server requires authentication
- key_id: Key
- key_secret: Secret for the Key
C/C++ Support
Python is great, but at times you need to call into native C/C++ code. Here is an example how you can do that with Conductor SDK.
1. Export your C++ functions as extern "C"
:
- C++ function example (sum two integers)
#include <iostream> extern "C" int32_t get_sum(const int32_t A, const int32_t B) { return A + B; }
2. Compile and share its library:
- C++ file name:
simple_cpp_lib.cpp
- Library output name goal:
lib.so
$ g++ -c -fPIC simple_cpp_lib.cpp -o simple_cpp_lib.o $ g++ -shared -Wl,-install_name,lib.so -o lib.so simple_cpp_lib.o
3. Use the C++ library in your python worker
You can use the Python library to call native code written in C++. Here is an example that calls native C++ library from the Python worker. See simple_cpp_lib.cpp and simple_cpp_worker.py for complete working example.
from conductor.client.http.models.task import Task
from conductor.client.http.models.task_result import TaskResult
from conductor.client.http.models.task_result_status import TaskResultStatus
from conductor.client.worker.worker_interface import WorkerInterface
from ctypes import cdll
class CppWrapper:
def __init__(self, file_path='./lib.so'):
self.cpp_lib = cdll.LoadLibrary(file_path)
def get_sum(self, X: int, Y: int) -> int:
return self.cpp_lib.get_sum(X, Y)
class SimpleCppWorker(WorkerInterface):
cpp_wrapper = CppWrapper()
def execute(self, task: Task) -> TaskResult:
execution_result = self.cpp_wrapper.get_sum(1, 2)
task_result = self.get_task_result_from_task(task)
task_result.add_output_data(
'sum', execution_result
)
task_result.status = TaskResultStatus.COMPLETED
return task_result
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
File details
Details for the file conductor-python-1.0.32.tar.gz
.
File metadata
- Download URL: conductor-python-1.0.32.tar.gz
- Upload date:
- Size: 62.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f503a522603f966f4bb1863dc2ef4fa57f524264e328f1645a615565a4051d3 |
|
MD5 | 504a9b81ab6323ddbb6f39699cfbc40e |
|
BLAKE2b-256 | 6a5c6103f355b39685d73e068bd1f54224d0b0f8b65d0a68fd4fa989e1fa1d7b |
File details
Details for the file conductor_python-1.0.32-py3-none-any.whl
.
File metadata
- Download URL: conductor_python-1.0.32-py3-none-any.whl
- Upload date:
- Size: 103.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08f604b39331ebbf477b548226194be80db96be0542b60310ee635ca7360a108 |
|
MD5 | 090a03f2bbdcf25ee40a8e22f12a9ced |
|
BLAKE2b-256 | 96f31937438fcbf84fa396b37c64166b9321eb3b9d2e8683852c1c5c4a410fa3 |