PyCharm

reading time 5 mins

This guide will show you how to seamlessly integrate the Doppler CLI with PyCharm Professional and Community Editions.

Prerequisites

Configuration

Because PyCharm uses a custom JetBrains Python debug library, the Doppler CLI cannot be used to run your application.

To work around this, we created the doppler-env package which (when activated with the DOPPLER_ENV environment variable) injects secrets as environment variables into the Python debug process before your application code is run.

Install the doppler-env package in your virtual environment:

doppler-env
pip install doppler-env
pipenv install doppler-env --dev
poetry add doppler-env@latest --dev

πŸ“˜

Ensure your PyCharm project is configured to use the Python interpreter belonging to this application's virtual environment.

Debug Configuration

Local

Add the required DOPPLER_ENV environment variable to your Debug Configuration:

Screenshot of local debugging

Now configure the Doppler CLI to select the project and config:

doppler setup

Then run your PyCharm Debug Configuration and your secrets will automatically be injected as environment variables into the Python debug process.

Docker Compose

Ensure your local Docker engine is added to PyCharm in the Build, Execution, Deployment section of its preferences.

Screenshot of Docker Compose

Make sure the "Connection successful" message appears after adding Docker.

Screenshot showing connection successful

Next, add a new Python Interpreter in the Project settings area of your preferences.

Screenshot showing where to add Python Interpreter

Choose the Docker Compose option for the interpreter, select the Docker engine you created earlier,

Screenshot showing where to choose docker compose

Click Apply and then OK.

Screenshot showing apply and ok buttons

Select Edit Configurations...

Screenshot showing edit configurations menu

And then add the DOPPLER_ENV environment variable to the configuration.

Screenshot showing where to add environment variable Screenshot showing adding doppler env

Finally, choose the Remote Python Interpreter you created earlier from the Python Interpreter dropdown.

Screenshot showing choosing remote python interpreter

Your project should now load secrets from Doppler in Docker Compose and breakpoints should work as expected when running using Debug mode.50

Python Console

Add the required DOPPLER_ENV environment variable to your Python Console settings in Preferences > Build, Execution, Deployment > Console > Python Console.

Screenshot of python console

πŸ‘

Awesome Work

Now you know how to use Doppler to supply secrets when developing locally with PyCharm.