Creosote

5.2.0 · active · verified Thu Apr 16

Creosote is a Python command-line tool designed to identify unused dependencies within a project's virtual environment. It helps prevent bloated environments by scanning Python files for imports and comparing them against the declared dependencies in various specification files like `pyproject.toml`, `requirements.txt`, PDM, and Pipenv. As of version 5.2.0, it is actively maintained with frequent releases, typically on a monthly to bi-monthly cadence.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to install and run Creosote to identify an unused dependency in a simple project structure using `pyproject.toml`. It sets up a virtual environment, installs Creosote and a couple of dependencies (one used, one unused), then runs Creosote to find the unused one.

mkdir my_project
cd my_project
python -m venv .venv
source .venv/bin/activate
pip install creosote
pip install requests

# Create a dummy pyproject.toml
cat <<EOL > pyproject.toml
[project]
name = "my_project"
version = "0.1.0"
requires-python = ">=3.10"

[project.dependencies]
requests = ">=2.31.0,<3.0.0"
unused_lib = "==1.0.0"
EOL

# Create a dummy Python file that uses 'requests'
cat <<EOL > app.py
import requests

def fetch_data(url):
    response = requests.get(url)
    return response.text

if __name__ == "__main__":
    print("Fetching example.com...")
    fetch_data("https://example.com")
EOL

creosote --venv .venv --paths . --deps-file pyproject.toml --sections project.dependencies

view raw JSON →