DEV Community

Jonatas Baldin
Jonatas Baldin

Posted on

A Recipe for Poetry and CircleCI

Originally posted at Deploy Everyday.

Last week I wrote a Python library using Poetry to manage its dependencies and for publishing it to PyPI. So far, the experience has been fantastic.


Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right stack everywhere.

Poetry is so cool! It does a lot of things, including:

  • Manages Python dependencies really well, using the new standardized pyproject.toml.
  • Separates dependencies and dev dependencies.
  • Deals with the virtual environment for you.
  • Has one (one!) command to build and publish the package to PyPI.

After Poetry was up and running, I needed to hook it up with a Continuous Integration & Continuos Delivery tool to run our builds and publish the lib to PyPI. Enters CircleCI.


CircleCI is a CI/CD platform. It runs certain workflows in a certain environment when a certain event happens. Very specific, right?

Let me give you two examples:

  • Whenever I open a PR at GitHub, I want to checkout the new code and run the tests.
  • Whenever I create a new release at GitHub, I'd like to run the step defined before and publish it to a package repository.

This is what CircleCI can do for you! On top of that, the tool is free for open source projects ✨

All the nitty gritty from the examples above are configured in a .circleci/config.yml file. There, you can specify which kind of environment you want to have (Python?, Node?), what commands you want to execute (install dependencies? run tests?) and when they should be execute (new PR? new release?).

The catch of my adventure was to figure it out how Poetry and CircleCI could be good friends ❤️

The Recipe

First of all, no change was needed in the Poetry configuration file – just make sure you have the libraries used in the CircleCI jobs: flake8 and coveralls. The file below is the .circleci/config.yml.

Second, it took me a while to figure out the whole cache thing, but everything seems to be working nicely now 😌

Finally, here is how you can make this friendship thrive!

I hope this article helped you to get into Poetry with CircleCI! If you have any feedback, please leave them in the comments 🚀

Discussion (5)

defman profile image
Sergey Kislyakov 🇷🇺 🇺🇸

Your deployment job lacks an indentation as well as the deployment-workflow workflow.
Regardless, thanks for sharing your config. This might come in handy for me as well, because I use poetry too.

jonatasbaldin profile image
Jonatas Baldin Author

Thanks man! Just fixed that :)

If u ever use it, lmk :)

timonweb profile image
Tim Kamanin 🚀

Thank you Jonatas for saving my time and sharing this!

andreguerra123 profile image
André Catarino Guerra

How does CircleCI detects the deployment workflow? Only the main contributor should deploy...

jonatasbaldin profile image
Jonatas Baldin Author

hey there, sorry for the delay, just saw it now :<

i don't get the question tho :( can u explain more pls?