Skip to main content
Version: v0.1.0

Python Code Guide

You can use the Python code node in D.Hub pipelines to transform data or perform analysis logic.

Basic Structure

The Python code node operates based on Polars DataFrames.

Input

  • Data from the connected previous node is passed as a Polars DataFrame.
  • The input variable name follows the Input Alias set by the user.

Options

  • Runtime variables can be received through the options dictionary defined in the pipeline settings.

Output

  • A dictionary with the key output must be returned.
  • The value of output must be a Polars DataFrame.

Example Code

import polars as pl

def transform(inputs, options):
# 1. Get input data (when the input alias is 'input_df')
df = inputs['input_df']

# 2. Data transformation logic (e.g., multiply the 'count' column by 2)
result_df = df.with_columns(
(pl.col("count") * 2).alias("doubled_count")
)

# 3. Return result
return {
"output": result_df
}

Available Packages

The following packages are included in the environment by default. Additional packages can be specified in the node settings.

  • polars
  • pandas
  • numpy