Skip to main content
Run one or more Python scripts in a Bolt schedule for custom data processing, transformation, API calls, or validation that built-in commands do not cover.

Prerequisites

  • The Python script committed to your project.

Manage dependencies with Poetry

We recommend managing your Python dependencies with Poetry.
  • Keep your Poetry project (pyproject.toml and poetry.lock) at the root of your dbt™ project, alongside dbt_project.yml. Bolt runs schedule commands from that folder, so Poetry finds your project there.
  • Make poetry install the first command in the schedule, so your dependencies are installed before your script runs. In Bolt, Poetry installs them into the Python environment that runs dbt™, not into a new virtual environment. poetry run then runs your script in that environment.
Store secrets (API keys, credentials) as Bolt schedule environment variables and read them with os.environ rather than hardcoding them.

Usage

Add the Run Python Script command to your schedule and enter one or more commands, one per line. If you use Poetry, start with poetry install:
Without Poetry, run the script directly:

Fix package version conflicts

Because poetry install adds your dependencies to the environment that runs dbt™, a package you add can need a different version of a library that is already there. Your script then fails when it imports that library. For example, dlt depends on sqlglot, and a schedule on dbt™ 1.11, dbt™ 1.12 or dbt™ 2.0 can fail with:
The same script works in the Code IDE, because there Poetry creates a separate virtual environment.
This is a known issue. Until Bolt gives Poetry its own environment, use one of these workarounds.

Give Poetry its own environment

  1. Add the Bolt environment variable POETRY_VIRTUALENVS_CREATE with the value true. You can set it for the workspace or as an override on the schedule. See Bolt schedule environment variables.
  2. Add poetry env use python3 before poetry install:
You need both steps. Poetry then creates a new virtual environment for your project in each run, and the environment that runs dbt™ does not change. poetry install takes longer, because it installs all of your dependencies in each run.

Pin sqlglot with its compiled extension

If the error comes from sqlglot and the schedule runs only Python scripts, you can fix it in pyproject.toml instead. Add sqlglot with the c extra under [tool.poetry.dependencies], at a version that your other dependencies accept:
The c extra installs sqlglotc at the same version as sqlglot, so the two always match. Your schedule commands do not change. Poetry still installs into the environment that runs dbt™, so for a schedule that also runs dbt™ commands, use Give Poetry its own environment instead.

Learn more

See Using Poetry for dependency management, and Bolt schedule environment variables for handling secrets.