I like PDM, the “modern Python package and dependency manager.” It can do a whole bunch of things related to managing Python projects. In particular, there are two features I rely upon often and really appreciate.
PDM allows you to write, more or less, Python scripts with
dependencies that do not require any setup steps beforehand. This is
accomplished by including a description of the requirements (Python
version, dependencies, and more), in a top-level comment, and then
running the script with pdm run $SCRIPTPATH. PDM will then
create a Python environment for you on the fly, set it up according to
what you specified in the comment, and run your script within it.
Of course, to run such a script, you still need PDM, which itself is
a reasonably heavyweight setup step. Since the interface is minimal
(just one PDM command), stable (written in stone PEP 723), and interoperable
(based on a PEP), I tolerate it.
The top-level comment and basic script machinery looks like this:
# /// script
# requires-python = ">=3.14"
# dependencies = [
# "tqdm==4.70.1"
# ]
# ///
# Run with `pdm run $SCRIPT`
from pathlib import Path
import json
def main():
pass
if __name__ == "__main__":
main()I have the above script saved in ~/Templates/script.py
such that my file manager
allows me to create a new one from the right-click context menu. Any
file manager worth it’s salt will likely support this, as it’s part of
the XDG user
directory guidelines. Pretty nice if you ask me!
If you’re curious to read more, have a look at the documentation. PEP 723 specifies the metadata format used in the comments.
Before, I used a different Python project manager. Sadly, it got acquired by OpenAI.
I have yet to find a use case that’s not covered by PDM, though I’m sure there are differences. If you like no-hassle Python tooling, give PDM a try!
Generated with BYOB.
License: CC-BY-SA.
This page is designed to last.
Don't participate in systems built on massive exploitation and waste of scarce resources..
⇐ [ This site is part of the UT webring ] ⇒