One of Poetry’s “killer” features is the
poetry add subcommand, which can be used to add dependencies to Poetry’s custom
pyproject.toml sections. From Poetry’s docs:
Adding a few dependencies at once:
poetry add requests pendulum
Adding dependencies, with constraints:
# Allow >=2.0.5, <3.0.0 versions poetry add pendulum@^2.0.5 # Allow >=2.0.5, <2.1.0 versions poetry add pendulum@~2.0.5 # Allow >=2.0.5 versions, without upper bound poetry add "pendulum>=2.0.5" # Allow only 2.0.5 version poetry add pendulum==2.0.5
(Similar art exists in the form of
cargo add for Rust and
npm save for Node.)
Many developers find the experience of adding dependencies via the CLI more pleasant and less error-prone, and having a CLI allows the associated tooling to (optionally) do other opinionated things, like keep the dependency list sorted.
So, this got me thinking: does it make sense to offer similar functionality for standard PEP 621 metadata, specifically the
Here’s a rough sketch of what a CLI for that could look like (
pep621tool being a placeholder):
$ # adds requests to project.dependencies, no pin $ pep621tool add requests $ # adds example to project.dependencies, pinned to 1.2.3 $ pep621tool add example==1.2.3 $ # uses normal extras syntax as well $ pep621tool add example[dev]==1.2.3 $ # adds build to `project.optional-dependencies.dev` $ pep621tool add build --extra dev $ # standalone sorting, or sorting while adding $ pep621tool sort $ pep621tool add --sort requests
As of writing, the technical aspects of this should be feasible: PEP 621 itself is accepted and is being increasingly adopted, and packages like
tomlkit offer TOML modification with edit points (i.e., comments and user formatting).
I’m curious to hear what people think of this! One significant reservation I have around this is contributing to the “toolbag” problem that Python packaging already has by adding yet another distinct tool for package development. Given that, I’m interested to hear thoughts on whether it makes sense to add this to an existing frontend tool.