Skip to main content

Library for parsing and analyzing Kettle XML files

Project description

https://travis-ci.org/graphiq-data/KettleParser.svg?branch=master https://badge.fury.io/py/KettleParser.svg

About

KettleParser is a python library that parses Kettle XML files (.ktr and .kjb) for quick analysis. It takes in the XML metadata of a transformation or job and parses it so that you can easily access various attributes without the. You can get information on steps, hops, connections, and turn your transformation or job into a python graph object for structural analysis.

Usage

All metadata for steps, hops, and connections can be accessed by calling the get_attribute method. Refer to following transformation and read through the examples below for more information.

https://github.com/graphiq-data/KettleParser/blob/master/tests/transformation_1/transformation_1.png?raw=true

Parsing

For now, KettleParser only supports parsing complete Kettle files that are saved locally and not strings of raw XML. The Parse class is the main class to parse your Kettle file (.ktr or .kjb). Just call the class and pass it the filepath to your Kettle file:

>>> import KettleParser
>>> my_transformation = KettleParser.Parse("/path/to/my_transformation.ktr")

Steps

All steps in your transformation can be iterated on via the steps attribute:

>>> for step in my_transformation.steps:
...  step.get_attribute("name")
'Text file input'
...  step.get_attribute("type")
'TextFileInput'

Each type of step will have different attributes, but common attributes you’ll like use are:

  • name: Name of step – this will be a unique value across all steps in the same transformation

  • type: Type of step

  • copies: Number of copies of that step launched (.ktr files only)

To filter by enabled or disabled steps use the get_enabled_steps() or get_disabled_steps() methods respectively.

Hops

All hops in your transformation can be iterated on via the hops attribute:

>>> for hop in my_transformation.hops:
...  hop.get_attribute("from")
'Text file input'
...  hop.get_attribute("to")
'Select values'
...  hop.get_attribute("enabled")
True

Each individual hops contains three main attributes:

  • from: Name of source step

  • to: Name of target step

  • enabled: Is the hop enabled? (Boolean)

For a transformation, the hops object contains all hops: both enabled and disabled, and including error handling (note that enabled/disabled and error handling are not mutually exclusive). To easily filter different types of hops, use the following methods:

  • get_enabled_hops(): returns only hops that are enabled (including error handling)

  • get_disabled_hops(): returns only hops that are disabled (including error handling)

  • get_error_hops(): returns only hops that are error handling hops (including enabled and disabled)

Graph

You can also represent your transformation as a graph object by calling the KettleGraph class. This class takes in a list of hop objects to build the graph with.

>>> import KettleParser
>>> my_transformation = KettleParser.Parse("/path/to/my_transformation.ktr")
>>> my_graph = KettleParser.KettleGraph(my_transformation.hops)

Call the graph attribute to get a python graph object:

>>> my_graph.graph
{'Text file input': ['Select values'],
'Filter rows': ['Dummy (do nothing)', 'Text file output'],
'Select values': ['Filter rows']}

You can also find all paths between two steps by using the find_all_paths() method and passing it to step names. This method is a generator, letting you iterate through all possible paths (please be aware that very complex transformations could have thousands of paths between steps):

>>> paths = my_graph.find_all_paths("Text file input", "Text file output")
>>> paths.next()
['Text file input', 'Select values', 'Filter rows', 'Text file output']

Installation

To install KettleParser, simply:

pip install KettleParser

Issues

Please submit issues here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

KettleParser-1.0.2.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file KettleParser-1.0.2.tar.gz.

File metadata

  • Download URL: KettleParser-1.0.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for KettleParser-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5442b7a1c45a13488a348589f2e3e509c82239517d890ec4d3a2cb23c9d5a8e2
MD5 b6438aa0eb6717bf2725b17c197e8739
BLAKE2b-256 74d6bbfa84a93bf2fd6ce34e2491cc5144c4d69c6d870e8dd921585c12c3f337

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page