Skip to main content

How we style our Python

Python tooling

  • 🐍 Python has a more mature and robust ecosystem for formatting and linting (helped by the fact that it doesn't have a million distinct dialects). We recommend using those tools to format and lint your code in the style you prefer.

  • 🛠️ Our current recommendations are


    ☁️ dbt Cloud comes with the black formatter built-in to automatically lint and format their SQL. You don't need to download or configure anything, just click Format in a Python model and you're good to go!

Example Python

import pandas as pd

def model(dbt, session):
# set length of time considered a churn

dbt.config(enabled=False, materialized="table", packages=["pandas==1.5.2"])

orders_relation = dbt.ref("stg_orders")

# converting a DuckDB Python Relation into a pandas DataFrame
orders_df = orders_relation.df()

orders_df.sort_values(by="ordered_at", inplace=True)
orders_df["previous_order_at"] = orders_df.groupby("customer_id")[
orders_df["next_order_at"] = orders_df.groupby("customer_id")["ordered_at"].shift(
return orders_df