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
- Ascend Flow
Create a new Component
From your Workspace Super Graph view, follow these steps to create your Component:
- Form
- Files panel
- Double-click the Flow where you want to create your Component
- Right-click anywhere in the Flow Graph
- Hover over Create Component, then over Read in the expanded menu, and click From Scratch
- Complete the form with these details:
- Select your Flow
- Enter a descriptive Component Name like
read_sales
- Select Python as your file type
- Open the files panel in the top left corner
- Navigate to and select your desired Flow
- Right-click on the components directory and choose New file
- Name your file with a descriptive name like
read_sales.py
and press enter
Create your Python Read Component
Structure your Python Read Component following this pattern:
- Import necessary packages: Include Ascend resources (
read
), context handlers (ComponentExecutionContext
), and (typically) a data processing library likepandas
- Apply the
@read()
decorator: This automatically converts your function's output into Ascend's internal data format - Define your read function: Write a function that retrieves data from your source
- 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:
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:
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:
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.