Skip to main content

tugboat

tugboat

A simple Python package to generate a Dockerfile and corresponding Docker image from an analysis directory. tugboat also prepares your analysis repository to be shared via Binder.

tugboat uses the pigar package to automatically detect all the packages necessary to replicate your analysis and will generate a Dockerfile that contains an exact copy of your entire directory with all the essential Python packages installed. tugboat uses uv under the hood; as a result, projects that already utilize uv should be directly compatible with no additional setup.

tugboat may be of use, for example, when preparing a replication package for research. With tugboat, you can take a directory on your local computer and quickly generate a corresponding Dockerfile and Docker image that contains all the code and the necessary software to reproduce your findings.

Installation

Install tugboat from PyPI:

pip install tugboat-py

or install tugboat from GitHub:

pip install git+https://github.com/dmolitor/tugboat-py

Usage

tugboat has three primary functions; one to create a Dockerfile from your analysis directory, one to build the corresponding Docker image, and one to make your project ready to share and run in an online, interactive compute environment via Binder.

Create the Dockerfile

The primary function from tugboat is create(). This function converts your analysis directory into a Dockerfile that includes all your code and essential Python packages.

This function scans all files in the current analysis directory, attempts to detect all Python packages, and installs these packages in the resulting Docker image. It also copies the entire contents of the analysis directory into the Docker image. For example, if your analysis directory is named incredible_analysis, the corresponding location of your code and data files in the generated Docker image will be /incredible_analysis.

For the most common use-cases, there are a couple of arguments in this function that are particularly important:

  • project: This argument tells tugboat which directory is the one to generate the Dockerfile from. You can set this value yourself, or you can just use the default value. By default, tugboat uses the working directory to determine the analysis directory.
  • exclude: A list of files or sub-directories in your analysis directory that should NOT be included in the Docker image. This is particularly important when you have, for example, a sub-directory with large data files that would make the resulting Docker image extremely large if included. You can tell tugboat to exclude this sub-directory and then simply mount it to a Docker container as needed.

Below I'll outline a couple examples.

from tugboat import create

# The simplest scenario where your analysis directory is your current
# working directory, you are fine with the default base "python:3.x-slim"
# Docker image, and you want to include all files/directories:
create()

# Suppose your analysis directory is actually a sub-directory of your
# main project directory:
create(project="./sub-directory")

# Suppose that you specifically need a Docker base image that has uv
# installed. To do this, we will explicitly specify a different Docker
# base image using the `FROM` argument.
create(FROM="ghcr.io/astral-sh/uv:latest")

# Finally, suppose that we want to include all files except a couple
# particularly data-heavy sub-directories:
create(exclude=["data/big_directory_1", "data/big_directory_2"])

Build the Docker image

Once the Dockerfile has been created, we can build the Docker image with the build() function. By default this will assume the Dockerfile is located in the current working directory. This function assumes a little knowledge about Docker; if you aren't sure where to start, this is a great starting point.

The following example will do the simplest thing and will build the image locally.

build(image_name="awesome_analysis")

Suppose that, like above, your analysis directory is a sub-directory of your main project directory:

build(
    dockerfile="./sub-directory",
    build_context="./sub-directory",
    image_name="awesome_analysis"
)

Push to DockerHub

If, instead of just building the Docker image locally, you want to build the image and then push to DockerHub, you can make a couple small additions to the code above:

import os
from dotenv import load_dotenv
from tugboat import build

load_dotenv()

build(
    dockerfile="./sub-directory",
    build_context="./sub-directory",
    image_name="awesome_analysis",
    push=True,
    dh_username=os.environ["DOCKERHUB_USERNAME"],
    dh_password=os.environ["DOCKERHUB_USERNAME"]
)

Note: If you choose to push, you also need to provide your DockerHub username and password. Typically you don't want to pass these in directly and should instead use environment variables (or a similar method) instead.

Share your project via Binder

Binder lets others instantly launch and interact with your project in a live, cloud-based environment with no local setup required. tugboat will prepare your project to be shared with Binder. The process is easy; simply prep your directory for Binder with the binderize() function:

[!NOTE] Your analysis directory must be a GitHub repository.

binderize(branch="main")

By default this will add a Binder badge to your README.md file if it already has a section for badges:

Added badge to /.../README.md

If your README file does not have a section for badges, it will automatically save the badge to your clipboard and you will need to manually insert it into the README.

Add the following to your README.md file:

<!-- badges: start -->
[![Launch RStudio Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/{username}/{repo}/{branch}?urlpath=rstudio)
<!-- badges: end -->

After running binderize() you will see the following message:

Your repository has been configured for Binder.
[x] Commit and push all changes
[x] Launch Binder at: https://mybinder.org/v2/gh/{username}/{repo}/{branch}?urlpath=rstudio

You must commit and push all changes before visiting the Binder link, otherwise it will likely fail. Binder can automatically detect changes to the repository and will rebuild as necessary, ensuring that the Binder repository stays up to date.

R package

This package has a sibling R package!

Metadata

Release files for tugboat-py 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tugboat-py 0.1.4
File Size Uploaded Provenance
tugboat_py-0.1.4.tar.gz 8.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tugboat-py 0.1.4
File Interpreter ABI Platform
tugboat_py-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / tugboat_py-0.1.4.tar.gz

Download URL tugboat_py-0.1.4.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3e20b049f05dd3ef654eb934e5de5f91d0ef13903679ab97bb7dfe4233c43734
BLAKE2b-256 checksum
How to use checksums
4b36a761be2569f9032a61de2d0b596117a451d2b64138ec7b3ae9eb67af8a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tugboat_py-0.1.4-py3-none-any.whl

Download URL tugboat_py-0.1.4-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
daa44332da4816dd2cd4fa8b882e5d58c212bce2b7352cc10e275c96a5386025
BLAKE2b-256 checksum
How to use checksums
09766cec70148f857e21deb2fa47f0edec874e341c5ab0965e4052c61aa2fe52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for tugboat-py 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page