Working with Django¶
Bonobo provides a lightweight integration with django, to allow to include ETL pipelines in your django management commands.
To write a django management command that runs Bonobo job(s), just extend
django.core.management.base.BaseCommand, and override the
import bonobo from bonobo.contrib.django import ETLCommand class Command(ETLCommand): def get_graph(self, **options): graph = bonobo.Graph() graph.add_chain(...) return graph
You can override
ETLCommand.get_services() to provide your service implementations.
One common recipe to do so is to import it from somewhere else and override it as a
import bonobo from bonobo.contrib.django import ETLCommand from myproject.services import get_services class Command(ETLCommand): get_services = staticmethod(get_services) def get_graph(...): ...
ETLCommand.get_graph() method can also be implemented as a generator. In this case, each element yielded must
be a graph, and each graph will be executed in order:
import bonobo from bonobo.contrib.django import ETLCommand class Command(ETLCommand): def get_graph(self, **options): yield bonobo.Graph(...) yield bonobo.Graph(...) yield bonobo.Graph(...)
This is especially helpful in two major cases:
You must ensure that one job is finished before the next is run, and thus you can’t add both graph’s nodes in the same graph.
You want to change which graph is run depending on command line arguments.
Command line arguments¶
Like with regular django management commands, you can add arguments to the argument parser by overriding
The only difference with django is that the provided argument parser will already have arguments added to handle environment.