Skip to main content

treetl: Running ETL tasks with tree-like dependencies

Pipelines of batch jobs don’t need to be linear. Sometimes there are shared intermediate transformations that can feed future steps in the process. treetl manages and runs collections of dependent ETL jobs by storing and registering them as a polytree.

This package was put together with Spark jobs in mind, so caching intermediate and carrying results forward is top of mind. Due to this, one of the main benefits of treetl is that partial job results can be shared in memory.

Example

The following set of jobs will all run exactly once and pass their transformed data (or some reference to it) to the jobs dependent upon them.

from treetl import (
  Job, JobRunner, JOB_STATUS
)

class JobA(Job):
  def transform(self, **kwargs):
    self.transformed_data = 1
    return self

# JobB.transform can take a kwarg named
# a_param that corresponds to JobA().transformed_data
@Job.dependency(a_param=JobA)
class JobB(Job):
  def transform(self, a_param=None, **kwargs):
    self.transformed_data = a_param + 1
    return self

  def load(self, **kwargs):
    # could save intermediate result self.transformed_data here
    pass

@Job.dependency(some_b_param=JobB)
class JobC(Job):
  pass

@Job.dependency(input_param=JobA)
class JobD(Job):
  def transform(self, input_param=None, **kwargs):
    self.transformed_data = input_param + 1
    return self

@Job.dependency(in_one=JobB, in_two=JobD)
class JobE(Job):
  def transform(self, in_one=None, in_two=None, **kwargs):
    # do stuff with in_one.transformed_data and in_two.transformed_data
    self.transformed_data = in_one + in_two

# order submitted doesn't matter
jobs = [ JobD(), JobC(), JobA(), JobB(), JobE() ]
job_runner = JobRunner(jobs)
if job_runner.run().status == JOB_STATUS.FAILED:
  # to see this section in action add the following to
  # def transform(self): raise ValueError()
  # to the definition of JobD
  print('Jobs failed')
  print('Root jobs that caused the failure : {}'.format(job_runner.failed_job_roots()))
  print('Paths to sources of failure       : {}'.format(job_runner.failed_job_root_paths()))
else:
  print('Success!')
  print('JobE transformed data: {}'.format(jobs[4].transformed_data))

TODO

  • Set parameters common to multiple jobs via the top level JobRunner

  • Set/pass state parameters to job methods

  • Support submitting a JobRunner as a job for nested job dependency graphs.

  • Run from a specific point in the tree. Allow for parents of starting point to retrieve last loaded data instead of recomputing the whole set of dependencies.

  • Ability to pass job attributes to component functions used in the decorator based definition of a job

Metadata

Release files for treetl 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treetl 1.3.0
File Size Uploaded
treetl-1.3.0.tar.gz 14.6 kB Details

Release files / treetl-1.3.0.tar.gz

Download URL treetl-1.3.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
59300ed8c9b9a31d7622524b7ee7925b54e89c4c0b02b31df82f50990b69d520
BLAKE2b-256 checksum
How to use checksums
d238a3c9c2c4c40c2f34c36252c6e9d04b0a8ce1452262c6c5d9a15a2f9557a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.3.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page