Skip to main content

Share code across projects

As the number of projects grows, some code ends up being needed in more than one of them, such as cleaning functions, column mappings or small helpers. In ordinary Python, you would put it in a shared package in the repository and import it everywhere. Bauplan models, however, run in containers that receive only the top-level files of their project directory, making a shared package elsewhere in the repository unavailable to them.

The simplest option is to copy the shared module into each project that uses it, as a top-level file. When many projects use the same code and it can be made public, publish it as a package instead, and declare it on the models that use it.

Copy shared modules into each project

Put the shared module at the top level of each project directory, next to the models, and import it inside the model function.

    • bauplan_project.yaml
    • models.py
    • utils.pyshared helpers

Don't import shared helpers from a subfolder of the project or from anywhere else in the repository. By default, a run only includes top-level files in the project folder. See how to organize SQL files for SQL files in subfolders.

Publish code that many projects use as a package

When the same code is used by many projects and it can be made public, publish it as a package on a public index, and declare it on the models that use it, like any other dependency.

@bauplan.python("3.13", pip={"shared-utils": "1.2.0"})
caution

Models install their packages from the public Python Package Index, and there is no setting that points them at a private registry (yet). Code that cannot be published needs to be copied into each project.