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.tomlandpoetry.lock) at the root of your dbt™ project, alongsidedbt_project.yml. Bolt runs schedule commands from that folder, so Poetry finds your project there. - Make
poetry installthe 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 runthen 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 withpoetry install:
Fix package version conflicts
Becausepoetry 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:
This is a known issue. Until Bolt gives Poetry its own environment, use one of these workarounds.
Give Poetry its own environment
- Add the Bolt environment variable
POETRY_VIRTUALENVS_CREATEwith the valuetrue. You can set it for the workspace or as an override on the schedule. See Bolt schedule environment variables. - Add
poetry env use python3beforepoetry install:
poetry install takes longer, because it installs all of your dependencies in each run.
Pin sqlglot with its compiled extension
If the error comes fromsqlglot 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:
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.