Convert poetry.lock file into a requirements.txt and download the packages
This guide will show you how to convert poetry.lock file into a requirements.txt and download the packages into a specific subfolder step by step.
Poetry vs pip
Poetry is starting to be more and more popular between developers as package manager for python projects (more information here https://python-poetry.org/docs/cli/) but one of the lacking thing I see is the ability to download only the libraries/packages like pip is doing with the -t flag. With this command we can download/install all the poetry.lock packages into a specific folder.
If your projects are managed with Poetry, and you want to download locally the packages into a particular subfolder for having a deeper look at the source code before using, maybe for curiosity or maybe because the company you are looking for is strongly regulated and there are particular policies in place, or maybe you just want to run and end to end static analysis and want to get more insight these are the commands that you were looking for.
Please note that at the moment of writing this article the poetry version in use is 1.1 and this functionality is still missing so this article could be invalid in a couple of months or years depends on how much is a priority for their team this functionality.
By looking around and reading here and there I found a combination of commands that will definitely be extremely useful.
Export poetry.lock into requirements.txt
To export your poetry.lock into requirements.txt just run the below command
poetry export -f requirements.txt -o requirements.txt --without-hashes
Download packages locally using pip
Once we have the requirements.txt file we can download into the destination we prefer (in our example will be the packages folder) by running this command
mkdir packages && pip install -r requirements.txt -t ./packages
I hope that helped and if you like it please share.
Share this content: