Netflix Conductor Python SDK
Project description
Conductor OSS Python SDK
Python SDK for working with https://github.com/conductor-oss/conductor
Conductor is an open source distributed, scalable and highly available orchestration platform that allows developers to build powerful distributed applications. You can find the documentation for Conductor here: Conductor Docs
⭐ Conductor OSS
Show support for the Conductor OSS. Please help spread the awareness by starring Conductor repo.
Content
- Install SDK
- Start Conductor Server
- Simple Hello World Application using Conductor
- Using Conductor in your application
Install SDK
Create a virtual environment to build your package
virtualenv conductor
source conductor/bin/activate
Get Conductor Python SDK
SDK needs Python 3.9+.
python3 -m pip install conductor-python
Setup SDK
Point the SDK to the Conductor Server API endpoint
export CONDUCTOR_SERVER_URL=http://localhost:8080/api
(Optionally) If you are using a Conductor server that requires authentication
How to obtain the key and secret from the conductor server
export CONDUCTOR_AUTH_KEY=your_key
export CONDUCTOR_AUTH_SECRET=your_key_secret
Start Conductor Server
docker run --init -p 8080:8080 -p 5000:5000 conductoross/conductor-standalone:3.15.0
After starting the server navigate to http://localhost:1234 to ensure the server has started successfully.
Simple Hello World Application using Conductor
In this section, we will create a simple "Hello World" application that uses Conductor.
Step 1: Create a Workflow
Use Code to create workflows
Create greetings_workflow.py with the following:
from conductor.client.workflow.conductor_workflow import ConductorWorkflow
from conductor.client.workflow.executor.workflow_executor import WorkflowExecutor
from greetings import greet
def greetings_workflow(workflow_executor: WorkflowExecutor) -> ConductorWorkflow:
name = 'hello'
workflow = ConductorWorkflow(name=name, executor=workflow_executor)
workflow.version = 1
workflow >> greet(task_ref_name='greet_ref', name=workflow.input('name'))
return workflow
(alternatively) Use JSON to create workflows
Create workflow.json with the following:
{
"name": "hello",
"description": "hello workflow",
"version": 1,
"tasks": [
{
"name": "greet",
"taskReferenceName": "greet_ref",
"type": "SIMPLE",
"inputParameters": {
"name": "${workflow.input.name}"
}
}
],
"timeoutPolicy": "TIME_OUT_WF",
"timeoutSeconds": 60
}
Now, register this workflow with the server:
curl -X POST -H "Content-Type:application/json" \
http://localhost:8080/api/metadata/workflow -d @workflow.json
Step 2: Write Worker
Create greetings.py with a simple worker and a workflow function.
[!note] A single workflow application can have workers written in different languages.
from conductor.client.worker.worker_task import worker_task
@worker_task(task_definition_name='greet')
def greet(name: str) -> str:
return f'Hello my friend {name}'
Step 3: Write your application
Let's add greetings_main.py with the main
method:
from conductor.client.automator.task_handler import TaskHandler
from conductor.client.configuration.configuration import Configuration
from conductor.client.workflow.conductor_workflow import ConductorWorkflow
from conductor.client.workflow.executor.workflow_executor import WorkflowExecutor
from greetings_workflow import greetings_workflow
def register_workflow(workflow_executor: WorkflowExecutor) -> ConductorWorkflow:
workflow = greetings_workflow(workflow_executor=workflow_executor)
workflow.register(True)
return workflow
def main():
# points to http://localhost:8080/api by default
api_config = Configuration()
workflow_executor = WorkflowExecutor(configuration=api_config)
# Needs to be done only when registering a workflow one-time
workflow = register_workflow(workflow_executor)
task_handler = TaskHandler(configuration=api_config)
task_handler.start_processes()
workflow_run = workflow_executor.execute(name=workflow.name, version=workflow.version,
workflow_input={'name': 'Orkes'})
print(f'\nworkflow result: {workflow_run.output["result"]}\n')
print(f'see the workflow execution here: {api_config.ui_host}/execution/{workflow_run.workflow_id}\n')
task_handler.stop_processes()
if __name__ == '__main__':
main()
[!NOTE] That's it - you just created your first distributed python app!
Using Conductor in your application
There are three main ways you will use Conductor when building durable, resilient, distributed applications.
- Write service workers that implements business logic to accomplish a specific goal - such as initiate payment transfer, get user information from database etc.
- Create Conductor workflows that implements application state - A typical workflow implements SAGA pattern
- Use Conductor SDK and APIs to manage workflows from your application.
In this guide, we will dive deeper into each of these topic.
Create and Run Conductor Workers
Create Conductor Workflows
Using Conductor in your Application
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.1.4.tar.gz
.
File metadata
- Download URL: conductor-python-1.1.4.tar.gz
- Upload date:
- Size: 131.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b79e12fd4a76d835d33f3ed878f5b976cf1d6392a92af6b9f53ba4a9391a4f9 |
|
MD5 | e2dcab103e926c30d32eef45ddff91de |
|
BLAKE2b-256 | 9aae73101bb786751f56daa19646b06465c6b56abaaa3231fe6805d50985913d |
File details
Details for the file conductor_python-1.1.4-py3-none-any.whl
.
File metadata
- Download URL: conductor_python-1.1.4-py3-none-any.whl
- Upload date:
- Size: 240.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04595f38686e146c4c3d9c16fbb1b19699b3288d26f563dabd8fed9637db3e58 |
|
MD5 | 59f6e5cb5b52a4e6fdf423c7d69104be |
|
BLAKE2b-256 | f56be97ec0bef2ac729cb1134f53d434a372099fd038beeed216b8d353ce9583 |