Skip to content

usethis-python/usethis-python

Repository files navigation


usethis

usethis PyPI Version PyPI License PyPI Supported Versions uv codecov GitHub Actions Status Docs

Automate Python project setup and development tasks that are otherwise performed manually.

usethis is a command-line interface to automate the configuration of popular Python tools, workflows, and frameworks. You can use it to declaratively add, remove, and configure tools in an existing project, as well as set up a new project from scratch. It won't break your existing configuration, and ensures all tools work together smoothly.

usethis gives detailed messages about what it is doing (and what you need to do next).

  • Output beginning with βœ” represents a task which usethis has automated.
  • Output beginning with ☐ represents a task which you need to perform manually.
  • Output beginning with β„Ή gives hints and tips.

Inspired by an R package of the same name, this package brings a similar experience to the Python ecosystem as a CLI tool.

Tip

usethis is great for fresh projects using uv, but also supports updating existing projects. However, this should be considered experimental. If you encounter problems or have feedback, please open an issue.

Highlights

  • 🧰 First-class support for state-of-the-practice tooling: uv, Ruff, pytest, pre-commit, and many more.
  • πŸ€– Automatically add and remove tools: declare, install, and configure in one step.
  • 🧠 Powerful knowledge of how different tools interact and sensible defaults.
  • πŸ”„ Update existing configuration files automatically.
  • πŸ“’ Fully declarative project configuration.
  • ⚑ Get started on a new Python project or a new workflow in seconds.

🧭 Getting Started

First, it is strongly recommended you install the uv package manager: this is a simple, documented process. If you're already using uv, make sure you're using at least version v0.6.8. To check this, run uv self version to check (if available, otherwise uv version), and run uv self update to upgrade.

Tip

At the moment, usethis assumes you will have uv installed in some circumstances. Support for projects that don't use uv is planned for late 2025.

You can install usethis directly into the project environment:

# With uv
$ uv add --dev usethis

# With pip
$ pip install usethis

Alternatively, you can also run usethis commands in isolation, using uvx or pipx. For example, to add Ruff to the project:

# With uv
$ uvx usethis tool ruff

# With pipx
$ pipx run usethis tool ruff

πŸ–₯️ Command Line Interface

Start a New Project

  • usethis init β€” Initialize a new project with recommended defaults.

Manage Tooling

Manage Configuration

Manage the README

Information

  • usethis list β€” Display a table of all available tools and their current usage status.
  • usethis version β€” Display the current version of usethis.
  • usethis browse pypi β€” Display or open the PyPI landing page associated with another project.
  • usethis show β€” Show a specific piece of information about the project.

πŸ’‘ Example Usage

To start a new project from scratch with a complete set of recommended tooling, run:

$ uvx usethis init
βœ” Writing 'pyproject.toml' and initializing project.
βœ” Writing 'README.md'.
☐ Populate 'README.md' to help users understand the project.
βœ” Adding recommended documentation tools.
☐ Run 'uv run mkdocs build' to build the documentation.
☐ Run 'uv run mkdocs serve' to serve the documentation locally.
βœ” Adding recommended linters.
☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.
☐ Run 'uv run deptry src' to run deptry.
βœ” Adding recommended formatters.
☐ Run 'uv run ruff format' to run the Ruff formatter.
☐ Run 'uv run pyproject-fmt pyproject.toml' to run pyproject-fmt.
βœ” Adding recommended spellcheckers.
☐ Run 'uv run codespell' to run the Codespell spellchecker.
βœ” Adding recommended test frameworks.
☐ Add test files to the '/tests' directory with the format 'test_*.py'.
☐ Add test functions with the format 'test_*()'.
☐ Run 'uv run pytest' to run the tests.
☐ Run 'uv run pytest --cov' to run your tests with Coverage.py.

To use Ruff on an existing project, run:

$ uvx usethis tool ruff
βœ” Adding dependency 'ruff' to the 'dev' group in 'pyproject.toml'.
βœ” Adding Ruff config to 'pyproject.toml'.
βœ” Selecting Ruff rules 'A', 'C4', 'E4', 'E7', 'E9', 'F', 'FLY', 'FURB', 'I', 'PLE', 'PLR', 'RUF', 'SIM', 'UP' in 'pyproject.toml'.
βœ” Ignoring Ruff rules 'PLR2004', 'SIM108' in 'pyproject.toml'.
☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.
☐ Run 'uv run ruff format' to run the Ruff formatter.

To use pytest, run:

$ uvx usethis tool pytest
βœ” Adding dependency 'pytest' to the 'test' group in 'pyproject.toml'.
βœ” Adding pytest config to 'pyproject.toml'.
βœ” Selecting Ruff rule 'PT' in 'pyproject.toml'.
βœ” Creating '/tests'.
βœ” Writing '/tests/conftest.py'.
☐ Add test files to the '/tests' directory with the format 'test_*.py'.
☐ Add test functions with the format 'test_*()'.
☐ Run 'uv run pytest' to run the tests.

To configure Bitbucket pipelines, run:

$ uvx usethis ci bitbucket
βœ” Writing 'bitbucket-pipelines.yml'.
βœ” Adding cache 'uv' definition to 'bitbucket-pipelines.yml'.
βœ” Adding 'Run Ruff' to default pipeline in 'bitbucket-pipelines.yml'.
βœ” Adding 'Test on 3.12' to default pipeline in 'bitbucket-pipelines.yml'.
βœ” Adding 'Test on 3.13' to default pipeline in 'bitbucket-pipelines.yml'.
☐ Run your pipeline via the Bitbucket website.

πŸ“š Similar Projects

Not sure if usethis is the exact fit for your project?

The closest match to usethis is PyScaffold. It provides a Command Line Interface to automate the creation of a project from a sensible templated structure.

You could also consider your own hard-coded template. Templating tools such as Cookiecutter and Copier allow you to create static templates with fixed configuration you can use across multiple projects. However, it's not always obvious which template you should use, and many do not use state-of-practice tooling such as pyproject.toml. Also, sometimes a template can overwhelm you with too many unfamiliar tools.

You could consider this template or this one, which work with Copier, or this template which works with Cookiecutter.

Tip

You can still use usethis as a part of a templates using hooks for Cookiecutter and tasks for Copier.

If you're using Cookiecutter, then you can update to a latest version of a template using a tool like cruft. Copier has inbuilt support for template updating. Another template-style option which provides updating is jaraco/skeleton, which is a specific, git-based template rather than a general templating system.

πŸš€ Development

Commits since latest release CodSpeed

Roadmap

Major features planned for later in 2025 are:

  • Support for users who aren't using uv, e.g. poetry users,
  • Support for automated GitHub Actions workflows (#57), and
  • Support for a typechecker (likely Pyright, #121).

Other features are tracked in the GitHub Issues page.

Contributing

See the CONTRIBUTING.md file.

License

usethis is licensed under the MIT license (LICENSE or https://opensource.org/licenses/MIT)

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in usethis by you, as defined in the Apache License, Version 2.0, (https://www.apache.org/licenses/LICENSE-2.0), shall be licensed under the MIT license, without any additional terms or conditions.

About

Automate Python project setup and development tasks that are otherwise performed manually.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 6

Languages