KARPACH

WEB DEVELOPER BLOG

Getting Started with Poetry

I don’t have much experience with Python. A few years ago, I created a few fairly simple lead collector websites using Flask and that was pretty much it.

Then a few weeks ago I bought couple TP-Link smart light bulbs and quickly realized that Home Assistant’s built-in functionality does not serve my needs. I had to modify python-kasa Python library.

The library is using a poetry dependency management tool. It took me a few hours to understand the basics of it, so below I will summarize how to get started with it. The below guide is for Windows.

Prerequisites: Make sure you have Python installed and you checked during the installation checkbox for updating the path environment variable. This will enable Python and Pip to work from any Windows folder.

First, you need to install poetry. Run the following in Windows PowerShell:

pip install poetry

Then you need to initialize it:

poetry install

I assume you want to modify the source code, so open Visual Studio Code at the root of the project. Open any Python file to trigger an installation of the Python extension.

Then in the VS Code terminal (PowerShell) run:

poetry shell

In VS Code command prompt (Shift+Ctrl+p), type “Python: Select Interpreter”. Select the line which refers to Poetry at the right.

You are all set. Optionally you can open the Testing sidebar and configure the Python testing framework. Then run tests to confirm that your dev environment is fully functional.

Posted on July 7, 2023 by