The Context

Coding, running, monitoring and maintaining business workflows can be a real pain. At Zenaton, we are building a suite of tools allowing you to flawlessly run automated processes. All the infrastructure, persistence and configuration are handled for you. You can learn more here:

Marketing Automation Example

Let’s look at how to code a business workflow in Python with a marketing automation example.

Let’s say you are a local travel agency that wants to send an email campaign for a tropical destination. Of course, you’ll want to automatically send it at the right time to have the greatest possible impact.

For example, you might want to send it when the temperature in your clients’ hometown is below 40°F ⛸ for three days in a row, giving you a better chance that they’ll book a trip to the tropics🌴.


Let’s code it with Zenaton!

First, let’s code the two main tasks this workflow includes: checking the weather and sending the email campaign:

from zenaton.abstracts.task import Task
from zenaton.traits.zenatonable import Zenatonable

class TaskCheckTemperature(Task, Zenatonable):

    def handle(self):
        return get_temperature() # To be defined

class TaskSendEmailCampaign(Task, Zenatonable):

    def handle(self):
        send_status = send_email_campaign() # To be defined
        return send_status

To write a Zenaton Task, just subclass Task and Zenatonable. Then implement a handle method that contains the task’s required actions.

In this article we don’t show the full implementation of the tasks. Our objective here is only to show you Zenaton’s usage. You can find the full, working implementation of the example here! You will need an OpenWeatherMap account and a Gmail address to run the workflow.

So let’s write the actual workflow orchestration part, where the business logic is defined:

from zenaton.abstracts.workflow import Workflow
from zenaton.traits.zenatonable import Zenatonable
from zenaton.tasks.wait import Wait

class TemperatureCampaignWorkflow(Workflow, Zenatonable):

    def __init__(self, days, min_temp, min_rep):

    def handle(self):
        rep_count = 0
        for _ in range(self.days):
            # Checks the temperature
            if TaskCheckTemperature().execute() < self.min_temp:
                rep_count += 1
                rep_count = 0
            if rep_count == self.min_rep:
                # Sends email campaign, when conditions are met
            # Waits for one day
            # Send another campaign, when conditions are never met

To write a Zenaton workflow, just subclass Workflow and Zenatonable. Then implement a handle method that contains the workflow structure and calls the tasks you defined earlier.

The workflow will run for days (eg. 30) days, and trigger the email campaign if the temperature is below min_temp (eg. 40) °F for min_rep (eg. 3) days in a row.


You should have a server with a Zenaton Agent installed and configured with a boot file where you import your TemperatureCampaignWorkflow file (see our examples).

To launch this workflow, you then just execute this script:

TemperatureCampaignWorkflow(30, 40, 3).dispatch()

That’s it! Your automated marketing campaign is scheduled 💪.

At this stage, it’s important to emphasize a few points:

  • The code in TemperatureCampaignWorkflow seems to run for up to 30 days, but it’s not the case. Zenaton uses this code to orchestrate tasks (TaskCheckTemperature, TaskSendEmail and Wait) but it does not mean that a python thread is running on your workers for up to 30 days.
  • You do not have to (data)store any state, set up any cron, install any queuing system… it just works 😀

This is just a basic example. Zenaton provides you with tools to easily handle errors & retries, monitor tasks and much more! 🚀

Want that much more?

You can install Zenaton and start coding your own workflows now! We have a really 🔥 interactive tutorial, here.

You can also play around with the full implementation of this example and modify it to fit your needs.

Our library is also available in PHP, Node & Ruby!

And if you have any questions or comments, please send me an email at, chat with us here (lower right of the screen), or comment below 👇.