uv
uv copied to clipboard
Include a method to create machine readable output
When automating uv, having to parse the command output (which is intended for human readability) is not ideal. It would be useful to have an option to produce machine readable (probably JSON) output from the various uv commands.
- For
uv pip installsomething along the lines of the pip installation report would probably be a reasonable format. - For
uv pip list, thepip list --format=jsoncommand is probably a good model. uv pip showanduv pip freezeare machine readable, although having a--format=jsonequivalent for consistency might be worthwhile.uv pip checkprobably doesn't need an output option, assuming the exit code is success or failure as appropriate.uv pip compileanduv pip synccan probably have an installation report similar touv pip install. I've not used these myself, though, so I don't know how useful they would be in practice.uv venvcould produce JSON output showing details of the created environment - path to the environment, Python executable path, scripts and site-package directories. Basically, the values that the stdlibvenvmodule captures in the "context" object documented here.
To make automation easier, it's probably worth having some additional command line capabilities:
- An isolated mode, to prevent user config affecting results (
uvdoesn't have as many possibilities for problems here as pip does, but that may change, I guess...) - A "guaranteed quiet" mode that ensures that just the JSON data will be printed to stdout, with any user messages either going to stderr or being suppressed. (Writing the data to a file is another possibility, but IMO it tends to be clumsy to manage).
- I assume
uvalways writes its output as UTF-8, but if it doesn't (for example it follows the system defined encoding) then a "guaranteed UTF-8 output" mode would be important to avoid encoding problems.
should we note in the description that uv pip list --format json already exists? https://github.com/astral-sh/uv/blob/main/crates/uv/src/commands/pip_list.rs#L115
$ python -m uv pip list --format json | jq .
[
{
"name": "certifi",
"version": "2024.2.2"
},
{
"name": "charset-normalizer",
"version": "3.3.2"
},
{
"name": "idna",
"version": "3.6"
},
{
"name": "requests",
"version": "2.31.0"
},
{
"name": "urllib3",
"version": "2.2.1"
}
]
Thanks, I’d missed that.
We also need it for equivalent of --dry-run without doing the install.
Related:
- https://github.com/astral-sh/uv/issues/411
- https://github.com/astral-sh/uv/issues/1442