Skip to main content

Before you start

This guide assumes you have already launched a JupyterLab workspace, as described in theΒ Transformations Overview.

Environment variables

There are several environment variables that will be available when a transformation script runs in hotglue during a job: You can also add custom env variables for used in your scripts in your environment settings. You can then reference any env variable in your script using os.environ:
Python

Standard directories

In hotglue, there are threeΒ standardΒ directories:

The Working Directory

When hotglue executes your ETL script, it provides a structured working directory with all the necessary files and data for your transformation. You should reproduce this directory structure when developing scripts locally.

Directory Structure Overview

πŸ“„ Configuration Files

The key JSON configuration files available at runtime by your ETL script are:
  • catalog.json - Schema catalog for the data
  • source-config.json - Source system credentials and configuration
  • target-config.json - Target system credentials and configuration
  • target-catalog.json - Target schema catalog (V2 write jobs only)
  • source-state.json - Incremental sync state and bookmarks
  • state.json - Current job execution state
You can access these files with:
The tenant-config.json, on the other hand, is accessed from the snapshots directory. If you need to read or modify this object, your code will look something like below:

Example: Read the data

To start, we will import pandas and the gluestick Python package, and establish the standard input/output directories above. Note:snapshots are optional, and may not be needed for your scripts.
etl.ipynb
MyΒ sync_outputΒ folder contains a CSV file calledΒ campaigns. Learn more how to get sample data in theΒ Debugging a scriptΒ section. 3068 Now we can go ahead and read the data inΒ INPUT_DIRΒ with gluestick’sΒ readerΒ function.
etl.ipynb
Gluestick automatically parses out the timestamp in the CSV name, so we can access theΒ campaignsΒ data as follows:
etl.ipynb
By callingΒ campaigns.head()Β we can preview the data 2218

Manipulate the data

Now that you have the data as a pandas DataFrame, you can do any transformations you need to. For this example, we will select a few of the columns:Β id,Β emails_sent,Β create_time, andΒ status, and then rename them.
etl.ipynb
This generates the final output below. You can seeΒ samples of more complex use cases on GitHubΒ and refer to theΒ pandas documentation. 2236

Write the output data

Finally, we can write the output to the standardΒ OUTPUT_DIRΒ using pandasΒ to_csvΒ function:
etl.ipynb
This generates the output as a CSV file in theΒ etl-outputΒ directory: 3068 If you want to write this data to a non-filestore target, such as a database, CRM, or any other standard Singer target, you can use Gluestick’s to_singer function in lieu of to_csv:
etl.ipynb