Skip to Content
Data StudioPython Models

Python Models

Build advanced data transformations, ML predictions, and statistical analysis with Python templates.

Last reviewed September 15, 2026

Python models run custom Python code against your BigQuery data for advanced logic. Examples are customer segmentation, predictive scoring, and recommendation engines. Start from a pre-built template or write your own.

Creating a Python transformation

  1. Open Studio.
  2. Click New Data Model.
  3. Select Python.
  4. In Input data, select the connected sources that the model reads.
  5. Set the output table name and the Write mode.
  6. Customize the Python code and parameters.
  7. Save the model.

Template Categories

CategoryTemplatesUse Case
RecommendationsProduct affinity, cross-sell modelsSuggest products based on purchase history
SegmentationRFM analysis, behavioral clusteringGroup customers by behavior or value
PredictionChurn prediction, LTV forecastingPredict future customer behavior
AnalyticsCustomer Acquisition Cost, Cohort Retention Analysis, ForecastingMeasure acquisition cost, retention and trends

Input Tables

Map one or more BigQuery tables as inputs to your model. Each input table is available in your code as a pandas DataFrame, with the alias of the input as the variable name.

Output Configuration

SettingDescription
Output TableName of the BigQuery table to write results to
Write Modereplace (overwrite table each run) or append (add new rows)

Writing Python Code

Your code runs in a secure environment with these libraries:

LibraryVersionPurpose
pandas2.xData manipulation
numpy1.xNumerical computing
datetime, math, json, re, collections, itertoolsPython standard libraryDates, math, JSON, regular expressions and iteration helpers

Code Structure

Your code receives the mapped input tables as DataFrames. It must set the output or result variable to a DataFrame:

import pandas as pd # RFM segmentation example rfm = orders_df.groupby('customer_id').agg({ 'created_at': 'max', # Recency 'id': 'count', # Frequency 'total_price': 'sum' # Monetary }).reset_index() rfm.columns = ['customer_id', 'last_order', 'frequency', 'monetary'] output = rfm

Note: Vendo disables external network access for security. All data must come from the configured input tables.

Scheduling and Triggers

Python models can run in these ways:

TriggerDescription
ManualRun on demand from the model detail page
Source triggerRun automatically when a source app finishes syncing
Model triggerRun after an upstream model completes

Chaining Models

Set a source model trigger to make a pipeline of models. For example:

  1. Source sync imports Shopify orders
  2. SQL model computes daily revenue (triggered by source sync)
  3. Python model runs RFM segmentation (triggered by the SQL model)

Vendo detects circular dependencies and prevents chains longer than 10 models.

Best Practices

  • Keep models focused: one transformation for each model.
  • Use descriptive output table names: for example customer_segments or product_recommendations.
  • Handle edge cases: check for empty DataFrames and null values.
  • Start from templates: customize a pre-built template instead of writing from scratch.
  • Use replace mode for idempotent outputs, and append for time-series accumulation.
Need help?

When you contact support, give your workspace, the source or destination name, the job ID and the first error message.

support@vendodata.com
Last updated on