{"id":8039,"library":"creosote","title":"Creosote","description":"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.","status":"active","version":"5.2.0","language":"en","source_language":"en","source_url":"https://github.com/fredrikaverpil/creosote","tags":["dependency management","unused dependencies","virtual environment","cli","linting"],"install":[{"cmd":"pip install creosote","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[],"quickstart":{"code":"mkdir my_project\ncd my_project\npython -m venv .venv\nsource .venv/bin/activate\npip install creosote\npip install requests\n\n# Create a dummy pyproject.toml\ncat <<EOL > pyproject.toml\n[project]\nname = \"my_project\"\nversion = \"0.1.0\"\nrequires-python = \">=3.10\"\n\n[project.dependencies]\nrequests = \">=2.31.0,<3.0.0\"\nunused_lib = \"==1.0.0\"\nEOL\n\n# Create a dummy Python file that uses 'requests'\ncat <<EOL > app.py\nimport requests\n\ndef fetch_data(url):\n    response = requests.get(url)\n    return response.text\n\nif __name__ == \"__main__\":\n    print(\"Fetching example.com...\")\n    fetch_data(\"https://example.com\")\nEOL\n\ncreosote --venv .venv --paths . --deps-file pyproject.toml --sections project.dependencies","lang":"bash","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to version 3.10 or higher. If unable to upgrade, use Creosote version <5.0.0.","message":"Creosote dropped support for Python 3.9 in version 5.0.0. Projects requiring Creosote must use Python 3.10 or newer.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Include `--sections` argument with the path to your dependency group, e.g., `--sections project.dependencies` or `--sections tool.poetry.dependencies`.","message":"When using `pyproject.toml` for dependency management, you must specify the correct section(s) where dependencies are declared using the `--sections` argument (e.g., `project.dependencies`, `tool.poetry.dependencies`). Omitting this will lead to Creosote not finding any declared dependencies.","severity":"gotcha","affected_versions":"all"},{"fix":"Add the `--include-deferred` flag to your Creosote command: `creosote ... --include-deferred`.","message":"Creosote might miss imports that are deferred (i.e., imported inside functions or conditionally) by default. Use the `--include-deferred` flag to enable detection of these imports.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the `--django-settings` flag with the path to your Django settings module, e.g., `--django-settings myproject.settings`.","message":"For Django projects, explicitly imported apps or middleware might not be recognized as used. Creosote provides a `--django-settings` option to scan `INSTALLED_APPS` and `MIDDLEWARE` in your settings file.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `creosote` is installed in your active virtual environment (`pip install creosote`) and that the virtual environment is properly activated (`source .venv/bin/activate`). Alternatively, install it with `pipx install creosote` for global access.","cause":"The `creosote` executable is not in your system's PATH. This typically happens if the package was not installed in the active virtual environment, or if the virtual environment's bin directory is not sourced.","error":"command not found: creosote"},{"fix":"Upgrade your Python environment to 3.10 or newer. If you must use Python 3.9, install a compatible older version of Creosote, e.g., `pip install 'creosote<5.0.0'`.","cause":"You are attempting to run Creosote version 5.0.0 or later on a Python 3.9 environment, which is no longer supported.","error":"Error: Python 3.9 is not supported. The minimum required version is now Python 3.10."},{"fix":"Double-check the `--deps-file` path and the `--sections` argument for typos. Ensure the file exists and the section path is correct for your project's configuration (e.g., `project.dependencies` for PEP 621 or `tool.poetry.dependencies` for Poetry).","cause":"Creosote could not locate the specified dependency file or the given section within it. This might be due to an incorrect file path, a typo in the section name, or the file not existing.","error":"Could not find any dependencies file at path: 'pyproject.toml' for sections 'project.dependencies'."}]}