What’s new in Conductor Python SDK?
Tags: microservices, orchestration, python, distributedapps
Published: 2024-02-12 06:20:36

The Conductor Python SDK has undergone a major update, including new feature additions. 🎉

If you want to try it out quickly, pip install with the following:

```
python3 -m pip install conductor-python
```
The SDK needs Python 3.9+ to work with.

Here’s the quick link to Python SDK - https://github.com/conductor-sdk/conductor-python. 

If you are curious to explore the new enhancements in the Python SDK, read on!

## Key Highlights

### Support for AI Orchestration with language models, prompt templates and vector databases

Recently, we introduced support for building Gen AI applications by integrating with popular AI/LLM models and vector databases, & prompt templates to work with Orkes AI Agents. These features are now available in Conductor Python SDK. 

Check out the AI SDKs [here](https://github.com/conductor-sdk/conductor-python/tree/main/src/conductor/client/ai). 

For example, here’s a snippet from an AI example:

```
@worker_task(task_definition_name='get_friends_name')
def get_friend_name():
    name = os.getlogin()
    if name is None:
        return 'anonymous'
    else:
        return name


def start_workers(api_config):
    task_handler = TaskHandler(
        workers=[],
        configuration=api_config,
        scan_for_annotated_workers=True,
    )
    task_handler.start_processes()
    return task_handler
```
Get the [complete code here](https://github.com/conductor-sdk/conductor-python/blob/d00e61bf85dc7edd01935cc379f37e1ff5c412a8/examples/orkes/open_ai_helloworld.py). 

We currently support integrations with LLM providers such as OpenAI, Azure OpenAI, Vertex AI & Hugging Face, and vector DB’s such as Pinecone & Weaviate.

This is just the beginning. Orkes team is working on adding integrations with more LLM providers & vector DBs. So, keep an eye out for our [upcoming announcements](https://orkes.io/blog/). 

### Improved way to create dynamic workflows in Python

By using the improved ConductorWorkflow class and its associated methods, you can easily create complex workflows for specific use cases, enhancing the scalability of Python-based automation projects.

```
from conductor.client.worker.worker_task import worker_task


@worker_task(task_definition_name='get_user_email')
def get_user_email(userid: str) -> str:
    return f'{userid}@example.com'


@worker_task(task_definition_name='send_email')
def send_email(email: str, subject: str, body: str):
    print(f'sending email to {email} with subject {subject} and body {body}')
```
Get the complete [code here](https://github.com/conductor-sdk/conductor-python/blob/main/examples/dynamic_workflow.py). 

### Support to Unit Test Workflows & Replay Workflows

Introduced support for unit testing workflows, ensuring reliability and robustness throughout the development process and enhancing the SDK's quality and stability.

Also, enabled the ability to replay workflows, facilitating debugging, analysis, and optimization, providing you with greater visibility and control over the workflows.

[Check out here.](https://github.com/conductor-sdk/conductor-python/blob/main/docs/testing/README.md)

### Quality of Life Improvements

We have incorporated numerous quality-of-life improvements, such as dedicated clients for various resource types, worker configuration flexibility, enhanced documentation, performance optimizations, and out-of-box examples, enhancing the overall developer experience.

## Out-of-Box Examples

We have made it easier by adding many ready to use examples, which you can test here.👇

[Python SDK Examples](https://github.com/conductor-sdk/conductor-python/tree/main/examples)

Try it out & feel free to contribute more to [Conductor OSS](https://github.com/conductor-oss/conductor). 

## Get Started with Python SDK 

If you want to get started with Python SDK, check out these steps: 

1. Install SDK - Create a virtual environment to build your package:

```
virtualenv conductor
source conductor/bin/activate
```

2. Get Conductor Python SDK - If you want to try it out quickly, pip install with the following:

```
python3 -m pip install conductor-python
```
The SDK needs Python 3.9+ to work with.

3. 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. [Obtain the key and secret from the conductor server.](https://orkes.io/content/access-control-and-security/applications)

```
export CONDUCTOR_AUTH_KEY=your_key
export CONDUCTOR_AUTH_SECRET=your_key_secret
```

4. 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:5000 to ensure the server has started successfully.

Happy Coding! 🎉

Meanwhile, don’t forget to follow the [Conductor OSS - the open-source project](https://github.com/conductor-oss/conductor) & support us by giving a ⭐. 

[Join our community Slack if you have any queries. ](https://join.slack.com/t/orkes-conductor/shared_invite/zt-xyxqyseb-YZ3hwwAgHJH97bsrYRnSZg)