Python — How to “Black” on Pycharm with docker without hassle in 3 min

Jonhnatha Trigueiro
2 min readJun 19, 2022

In this post, I will show you how to simply setup your Pycharm (or Intelij ultimate) to format code using black via blackd.

I’ll assume that you’re familiarized with Black. For more introductory content about this code formatter, please reach out the official site.

Blocks with letters showing “order” organized and “chaos” scrambled, but still making sense.
Photo by Brett Jordan on Unsplash

Prerequisites

  1. Do You have a PyCharm (or Intelij Ultimate)? ✅
  2. Do You have Docker installed? ✅
  3. Do You have Docker compose installed? ✅

So you’re good to go!

Now, How?

  1. Create a folder on your development environment: I suggest a folder called tools/blackd (because you can reuse it for other Python projects on your local machine as well)
  2. Place a file named docker-compose.yml with the following content;

3. Start yourblackd service running the following command: $ docker compose up -d

REMARK: -d in that command means “run in background” 😉

4. Open your Pycharm; Go under settings -> plugins and install “BlackConnect”;

plugins page with “BlackConnect” selected

5. Now the “BlackConnect” menu will be available. (If it doesn’t show for you, restart your IDE and then it will be available)

6. Configure “BlackConnect” pointing to your newly created container;

BlackConnect configuration screen (shown on my Intelij Ultimate)

Click on “Check connection”; it should be Ok.

Last, but not least, check the “Trigger Settings” as you please. I recommend to select this Trigger when saving changed files . It self explanatory though. 😅

Wrapping up

So, that’s it. Please leave a comment if you want to have more content like this. If you have more questions like that, please let me know.

Thank you for your time!

--

--