I found that python can use pyproject.toml to list dependencies instead of requirements.txt file. It's more convenient and is very similar to package.json for node.However, I could not find a documentation to init the pyproject.toml file much like the npm init
command. How to autogenerate the file with virtualenv or pip?
also, is there a way to autoupdate the toml file, as the packagaes get installed, much like npm --save tag, that saves the package to the package.json as its installed?
Asked
Active
Viewed 6,043 times
2

isnvi23h4
- 1,910
- 1
- 27
- 45
-
1Look into a project called *poetry* it can do it for you quiet neatly. – schneebuzz Feb 14 '20 at 15:20
-
I feel like Pipenv is more closer to having a package.json – OneCricketeer Feb 14 '20 at 15:22
-
Agree, but not to the pyproject toml as of the upcoming *standardisation* – schneebuzz Feb 14 '20 at 15:24
-
1https://www.python.org/dev/peps/pep-0518/#specification – phd Feb 14 '20 at 15:43
-
`poetry init` in the project root dir, answer the questions, done. – hoefling Feb 14 '20 at 16:43
-
What are you asking exactly? There are many tools that store configuration in that file. `poetry` is one of them, so is `flit`, and a bunch of others. Some can cohabit peacefully, some might not. From the details in your question, `poetry` might be indeed a strong candidate, but it has its own quirks and limitations, so you have to make sure it is what you want to buy. But really a `pyproject.toml` is just 2 or 3 lines (the `[build-system]` section) as per the specification @phd linked to in its comment. Every other section in that file is most likely specific to a tool and non standard. – sinoroc Feb 14 '20 at 17:08
-
Maybe there is a [`cookiecutter`](https://pypi.org/project/cookiecutter/) somewhere that allows you to choose a _build-system_ (poetry, filt, setuptools, etc.) interactively and populate the `pyproject.toml` accordingly. – sinoroc Feb 14 '20 at 17:12
-
You could give PDM a try. It has an init feature: https://pdm.fming.dev/latest/usage/hooks/#initialization – Jeff Wright Feb 23 '23 at 17:51
1 Answers
2
Look at poetry. It can do it for you nicely. Actually I think its the only project that handles this already that I know of.

schneebuzz
- 348
- 1
- 2
- 10
-
-
1TOML is now natively supported in Python (as of 3.11). :-) An alternative to poetry that has full support for the `pyproject.toml` file is pdm: https://pdm.fming.dev/latest/ – Jeff Wright Feb 23 '23 at 17:47