Skip to main content

Simple Python Read

In this guide, we'll build a Simple Python Read Component that retrieves data without incremental or Smart partitioning strategies.

Let's keep it Simple!

Prerequisites

Create a new Component

From your Workspace Super Graph view, follow these steps to create your Component:

  1. Double-click the Flow where you want to create your Component
  2. Right-click anywhere in the Flow Graph
  3. Hover over Create Component, then over Read in the expanded menu, and click From Scratch menu
  4. Complete the form with these details:
    • Select your Flow
    • Enter a descriptive Component Name like read_sales
    • Select Python as your file type form

Create your Python Read Component

Structure your Python Read Component following this pattern:

  1. Import necessary packages: Include Ascend resources (read), context handlers (ComponentExecutionContext), and (typically) a data processing library like pandas
  2. Apply the @read() decorator: This automatically converts your function's output into Ascend's internal data format
  3. Define your read function: Write a function that retrieves data from your source
  4. Return structured data: Your function should return a dataframe or table structure

The @read() decorator seamlessly handles conversion between Python data structures and Ascend's internal format, allowing smooth integration with downstream Components in your data pipeline.

Base Python example

This minimal example uses core Python to return a simple list:

simple_read_core.py
from ascend.application.context import ComponentExecutionContext
from ascend.resources import read


@read()
def simple_read(context: ComponentExecutionContext):
"""Return a simple list of dictionaries, each representing a row."""
return [{"value": 1}]

pandas example

You can leverage popular data processing libraries like pandas or Polars. This example uses pandas to create a DataFrame with a single row:

simple_read_pandas.py
import pandas as pd
from ascend.application.context import ComponentExecutionContext
from ascend.resources import read


@read()
def simple_read_pandas(context: ComponentExecutionContext):
"""Create a DataFrame with a single row of data."""
data = pd.DataFrame({"value": [1]})
return data

Practical example

This example from our Otto's Expeditions Project reads CSV data from cloud storage:

read_guides.py
import pandas as pd
from ascend.application.context import ComponentExecutionContext
from ascend.resources import read


@read()
def read_guides(context: ComponentExecutionContext) -> pd.DataFrame:
"""Read CSV data from cloud storage."""
df = pd.read_csv("gs://ascend-io-gcs-public/ottos-expeditions/lakev0/seed/guides.csv")
return df

Check out our reference guide for additional examples and advanced options.

🎉 Congratulations! You've successfully created a Simple Python Read Component in Ascend.