Skip to main content

Netflix Conductor Python SDK

Project description

Conductor Python

Software Development Kit for Netflix Conductor, written on and providing support for Python.

Quick Guide

  1. Create a virtual environment

    $ virtualenv conductor
    $ source conductor/bin/activate
    $ python3 -m pip list
    Package    Version
    ---------- -------
    pip        22.0.3
    setuptools 60.6.0
    wheel      0.37.1
    
  2. Install latest version of conductor-python from pypi

    $ python3 -m pip install conductor-python
    Collecting conductor-python
    Collecting certifi>=14.05.14
    Collecting urllib3>=1.15.1
    Requirement already satisfied: setuptools>=21.0.0 in ./conductor/lib/python3.8/site-packages (from conductor-python) (60.6.0)
    Collecting six>=1.10
    Installing collected packages: certifi, urllib3, six, conductor-python
    Successfully installed certifi-2021.10.8 conductor-python-1.0.7 six-1.16.0 urllib3-1.26.8
    
  3. Create a worker capable of executing a Task. Example:

    from conductor.client.worker.worker_interface import WorkerInterface
    
    
    class SimplePythonWorker(WorkerInterface):
        def execute(self, task):
            task_result = self.get_task_result_from_task(task)
            task_result.add_output_data('key', 'value')
            task_result.status = 'COMPLETED'
            return task_result
    
    • The add_output_data is the most relevant part, since you can store information in a dictionary, which will be sent within TaskResult as your execution response to Conductor
  4. Create a main method to start polling tasks to execute with your worker. Example:

    from conductor.client.automator.task_handler import TaskHandler
    from conductor.client.configuration.configuration import Configuration
    from conductor.client.worker.sample.faulty_execution_worker import FaultyExecutionWorker
    from conductor.client.worker.sample.simple_python_worker import SimplePythonWorker
    
    
    def main():
        configuration = Configuration(debug=True)
        task_definition_name = 'python_example_task'
        workers = [
            SimplePythonWorker(task_definition_name),
            FaultyExecutionWorker(task_definition_name)
        ]
        with TaskHandler(workers, configuration) as task_handler:
            task_handler.start()
    
    
    if __name__ == '__main__':
        main()
    
    • This example contains two workers, each with a different execution method, capable of running the same task_definition_name
  5. Now that you have implemented the example, you can start the Conductor server locally:

    1. Clone Netflix Conductor repository:
      $ git clone https://github.com/Netflix/conductor.git
      $ cd conductor/
      
    2. Start the Conductor server:
      /conductor$ ./gradlew bootRun
      
    3. Start Conductor UI:
      /conductor$ cd ui/
      /conductor/ui$ yarn install
      /conductor/ui$ yarn run start
      

    You should be able to access:

  6. Create a Task within Conductor. Example:

    $ curl -X 'POST' \
        'http://localhost:8080/api/metadata/taskdefs' \
        -H 'accept: */*' \
        -H 'Content-Type: application/json' \
        -d '[
        {
          "name": "python_task_example",
          "description": "Python task example",
          "retryCount": 3,
          "retryLogic": "FIXED",
          "retryDelaySeconds": 10,
          "timeoutSeconds": 300,
          "timeoutPolicy": "TIME_OUT_WF",
          "responseTimeoutSeconds": 180,
          "ownerEmail": "example@example.com"
        }
      ]'
    
  7. Create a Workerflow within Conductor. Example:

    $ curl -X 'POST' \
        'http://localhost:8080/api/metadata/workflow' \
        -H 'accept: */*' \
        -H 'Content-Type: application/json' \
        -d '{
        "createTime": 1634021619147,
        "updateTime": 1630694890267,
        "name": "workflow_with_python_task_example",
        "description": "Workflow with Python Task example",
        "version": 1,
        "tasks": [
          {
            "name": "python_task_example",
            "taskReferenceName": "python_task_example_ref_1",
            "inputParameters": {},
            "type": "SIMPLE"
          }
        ],
        "inputParameters": [],
        "outputParameters": {
          "workerOutput": "${python_task_example_ref_1.output}"
        },
        "schemaVersion": 2,
        "restartable": true,
        "ownerEmail": "example@example.com",
        "timeoutPolicy": "ALERT_ONLY",
        "timeoutSeconds": 0
      }'
    
  8. Start a new workflow:

    $ curl -X 'POST' \
        'http://localhost:8080/api/workflow/workflow_with_python_task_example' \
        -H 'accept: text/plain' \
        -H 'Content-Type: application/json' \
        -d '{}'
    

    You should receive a Workflow ID at the Response body

    • Workflow ID example: 8ff0bc06-4413-4c94-b27a-b3210412a914

    Now you must be able to see its execution through the UI.

    • Example: http://localhost:5000/execution/8ff0bc06-4413-4c94-b27a-b3210412a914
  9. Run your Python file with the main method

Unit Tests

Simple validation

/conductor-python/src$ python3 -m unittest -v
test_execute_task (tst.automator.test_task_runner.TestTaskRunner) ... ok
test_execute_task_with_faulty_execution_worker (tst.automator.test_task_runner.TestTaskRunner) ... ok
test_execute_task_with_invalid_task (tst.automator.test_task_runner.TestTaskRunner) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK

Run with code coverage

/conductor-python/src$ python3 -m coverage run --source=conductor/ -m unittest

Report:

/conductor-python/src$ python3 -m coverage report

Visual coverage results:

/conductor-python/src$ python3 -m coverage html

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

conductor-python-1.0.9.tar.gz (59.1 kB view details)

Uploaded Source

Built Distribution

conductor_python-1.0.9-py3-none-any.whl (97.0 kB view details)

Uploaded Python 3

File details

Details for the file conductor-python-1.0.9.tar.gz.

File metadata

  • Download URL: conductor-python-1.0.9.tar.gz
  • Upload date:
  • Size: 59.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for conductor-python-1.0.9.tar.gz
Algorithm Hash digest
SHA256 715d007c82ecc3005e69361e740d5d0c121bfd0f3c1d06431744fd8e26d265d5
MD5 e421b04bfa477bc0fec4117650cd3aa6
BLAKE2b-256 4c3775ceb98fa0a897a9ef3956c769a3653e5e884e10d1f0f2a847a40ec765a8

See more details on using hashes here.

File details

Details for the file conductor_python-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: conductor_python-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 97.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for conductor_python-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 95f3e5c0e2bc3911316fea51c352fa109a97b1b000a32ec36a4d4f0e3be0fe7b
MD5 94d7de15feeb3b1e6e3dd5f0e40cd51d
BLAKE2b-256 a433bd5e09462011b275762b6d6d53e77c8f21a4e7c6dbbd9d2c850b616045d5

See more details on using hashes here.

Supported by

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