Skip to main content

Getting Started

Requirements

To get started, you will need Python 3.6 or later.

Setting up a Project

Installing

Install into an existing application is as simple as:

pip install cadence 

The only dependency of core Cadence is schedule, which is used to schedule tasks.

Creating a Sample Project

The Cadence package (i.e. the package installed using pip) is meant to be run inside of a Cadence application. Here is a minimal example of a Cadence application.

The core of Cadence is the Task object:

# task.py
from cadence import Task

class Test(Task):
def run(self):
print("Running test task")
# main.py
from cadence import bootstrap

from task import Test

if __name__ == "__main__":
bootstrap(tasks=[Test])

The bootstrap method registers start and exit events and runs the task pipeline. The pipeline is responsible for managing the lifecycle of a Cadence application. Multiple pipelines can be created and run in parallel without interfering.

Example Task

The Task class can utilize lifecycle methods to trigger methods at different points in a tasks lifecycle. Methods are similar to unit tests:

import schedule

from cadence import Task, before_all

class Test(Task):
id = "12345" # set a unique ID for this task
job = schedule.every(5).seconds # set how frequently this task runs

@before_all()
def configure(self):
print("Runs at the beginning of the task")

@step() # equivalent to defining a "run" method
def test_print(self):
print("Running test task")

Pipeline Lifecycle