# doppler-env
The doppler-env package automates the injection of Doppler secrets as environment variables into any Python application and works in the terminal, PyCharm, and Visual Studio Code.
## Motivation
The Doppler CLI provides the easiest method of injecting secrets into your application:
```sh
doppler run -- python app.py
```
But when debugging with PyCharm or Visual Studio Code, a vendor-specific Python entry-point is used, preventing the Doppler CLI from acting as the application runner. At Doppler, we go to great lengths to [prevent secrets ending up on developer's machines](https://blog.doppler.com/how-to-prevent-secrets-from-ending-up-on-developers-machines) so downloading secrets to a .env file wasn't an option.
Thanks to Python's [Site configuration hook](https://docs.python.org/3/library/site.html) via a path configuration file, we can replicate the `doppler run` workflow by fetching the secrets via the Doppler CLI (recommended) or API and injecting into your Python application process prior to your code by being executed.
## Setup
Ensure you have [installed the Doppler CLI](https://docs.doppler.com/docs/enclave-installation) locally and have [created a Doppler Project](https://docs.doppler.com/docs/create-project). Then authorize the Doppler CLI to retrieve secrets from your workplace by running:
```sh
doppler login
```
Then install `doppler-env` in your local development environment or add it to the list of dev specific dependencies:
```sh
pip install doppler-env
```
## Configuration
First, define the `DOPPLER_ENV` environment variable in your IDE, editor, or terminal to trigger the injection of secrets:
```sh
export DOPPLER_ENV=1
```
You can enable logging for troubleshooting purposes by setting the `DOPPLER_ENV_LOGGING` environment variable:
```sh
export DOPPLER_ENV_LOGGING=1
```
Then configure which secrets to fetch for your application by either using the CLI in the root directory of your application:
```sh
doppler setup
```
Or set the `DOPPLER_PROJECT` and `DOPPLER_CONFIG` environment variables in your debug configuration within PyCharm or Visual Studio Code.
Now whenever the Python interpreter is invoked for your application, secrets will be injected prior to your application being run:
```sh
python app.py
# >> [doppler-env]: DOPPLER_ENV environment variable set. Fetching secrets using Doppler CLI
```
In restrictive environments where the use of the Doppler CLI isn't possible, set a `DOPPLER_TOKEN` environment variable with a [Service Token](https://docs.doppler.com/docs/service-tokens) to fetch secrets directly from the Doppler API:
```sh
export DOPPLER_TOKEN='dp.st.dev.xxxxxxx'
python app.py
# >> [doppler-env]: DOPPLER_ENV and DOPPLER_TOKEN environment variable set. Fetching secrets from Doppler API
```
## Acknowledgements
This approach to injecting environment variables was inspired by [patch-env](https://github.com/caricalabs/patch-env).
## Issues
For any bug reports, issues, or enhancements, please [create a repository issue]().
# Support
You can get support in the [Doppler community forum](https://community.doppler.com/), find us on [Twitter](https://twitter.com/doppler), and for bugs or feature requests, [create an issue](https://github.com/DopplerHQ/python-doppler-env/issues/new) on the [DopplerHQ/python-doppler-env](https://github.com/DopplerHQ/python-doppler-env) GitHub repository.
If you need help, either use our in-product support or head over to the [Doppler Community Forum](https://community.doppler.com/) to get your questions answered by a member of the Doppler support team or
Raw data
{
"_id": null,
"home_page": "https://github.com/dopplerhq/python-doppler-env",
"name": "doppler-env",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "doppler,environment variables,app secrets,app config,os.environ",
"author": "Doppler",
"author_email": "support@doppler.com",
"download_url": "https://files.pythonhosted.org/packages/8f/8b/38b4f570db3a1c68f84565078991fca249ffa878968e653e34e5442660a0/doppler_env-0.3.1.tar.gz",
"platform": null,
"description": "# doppler-env\n\nThe doppler-env package automates the injection of Doppler secrets as environment variables into any Python application and works in the terminal, PyCharm, and Visual Studio Code.\n\n## Motivation\n\nThe Doppler CLI provides the easiest method of injecting secrets into your application:\n\n```sh\ndoppler run -- python app.py\n```\n\nBut when debugging with PyCharm or Visual Studio Code, a vendor-specific Python entry-point is used, preventing the Doppler CLI from acting as the application runner. At Doppler, we go to great lengths to [prevent secrets ending up on developer's machines](https://blog.doppler.com/how-to-prevent-secrets-from-ending-up-on-developers-machines) so downloading secrets to a .env file wasn't an option.\n\nThanks to Python's [Site configuration hook](https://docs.python.org/3/library/site.html) via a path configuration file, we can replicate the `doppler run` workflow by fetching the secrets via the Doppler CLI (recommended) or API and injecting into your Python application process prior to your code by being executed.\n\n## Setup\n\nEnsure you have [installed the Doppler CLI](https://docs.doppler.com/docs/enclave-installation) locally and have [created a Doppler Project](https://docs.doppler.com/docs/create-project). Then authorize the Doppler CLI to retrieve secrets from your workplace by running:\n\n```sh\ndoppler login\n```\n\nThen install `doppler-env` in your local development environment or add it to the list of dev specific dependencies:\n\n```sh\npip install doppler-env\n```\n\n## Configuration\n\nFirst, define the `DOPPLER_ENV` environment variable in your IDE, editor, or terminal to trigger the injection of secrets:\n\n```sh\nexport DOPPLER_ENV=1\n```\n\nYou can enable logging for troubleshooting purposes by setting the `DOPPLER_ENV_LOGGING` environment variable:\n\n```sh\nexport DOPPLER_ENV_LOGGING=1\n```\n\nThen configure which secrets to fetch for your application by either using the CLI in the root directory of your application:\n\n```sh\ndoppler setup\n```\n\nOr set the `DOPPLER_PROJECT` and `DOPPLER_CONFIG` environment variables in your debug configuration within PyCharm or Visual Studio Code.\n\nNow whenever the Python interpreter is invoked for your application, secrets will be injected prior to your application being run:\n\n```sh\npython app.py\n\n# >> [doppler-env]: DOPPLER_ENV environment variable set. Fetching secrets using Doppler CLI\n```\n\nIn restrictive environments where the use of the Doppler CLI isn't possible, set a `DOPPLER_TOKEN` environment variable with a [Service Token](https://docs.doppler.com/docs/service-tokens) to fetch secrets directly from the Doppler API:\n\n\n```sh\nexport DOPPLER_TOKEN='dp.st.dev.xxxxxxx'\n\npython app.py\n\n# >> [doppler-env]: DOPPLER_ENV and DOPPLER_TOKEN environment variable set. Fetching secrets from Doppler API\n```\n\n## Acknowledgements\n\nThis approach to injecting environment variables was inspired by [patch-env](https://github.com/caricalabs/patch-env).\n\n## Issues\n\nFor any bug reports, issues, or enhancements, please [create a repository issue]().\n\n# Support\n\nYou can get support in the [Doppler community forum](https://community.doppler.com/), find us on [Twitter](https://twitter.com/doppler), and for bugs or feature requests, [create an issue](https://github.com/DopplerHQ/python-doppler-env/issues/new) on the [DopplerHQ/python-doppler-env](https://github.com/DopplerHQ/python-doppler-env) GitHub repository.\n\nIf you need help, either use our in-product support or head over to the [Doppler Community Forum](https://community.doppler.com/) to get your questions answered by a member of the Doppler support team or \n",
"bugtrack_url": null,
"license": "APL 2.0",
"summary": "Inject Doppler secrets as environment variables into your Python application during local development with debugging support for PyCharm and Visual Studio Code.",
"version": "0.3.1",
"split_keywords": [
"doppler",
"environment variables",
"app secrets",
"app config",
"os.environ"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "dc004332ea2ffc362b54436aee111178",
"sha256": "4c80437f875c7bb85c980e7a3bf96fff594d1e1b05b99b49b02e673fbaa2d65c"
},
"downloads": -1,
"filename": "doppler_env-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc004332ea2ffc362b54436aee111178",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 4375,
"upload_time": "2022-12-08T23:51:47",
"upload_time_iso_8601": "2022-12-08T23:51:47.433803Z",
"url": "https://files.pythonhosted.org/packages/76/6b/46293737fd8c854f34f099529e2606b366176cdcdee119e1474e47e367c2/doppler_env-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "df64ca1d907a84b7a2aac8606ea872a2",
"sha256": "d187c2cf6a0dec677c00af502d59b382d507d69cd9805ea9e8211860bd0aa0f7"
},
"downloads": -1,
"filename": "doppler_env-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "df64ca1d907a84b7a2aac8606ea872a2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 4368,
"upload_time": "2022-12-08T23:51:49",
"upload_time_iso_8601": "2022-12-08T23:51:49.164710Z",
"url": "https://files.pythonhosted.org/packages/8f/8b/38b4f570db3a1c68f84565078991fca249ffa878968e653e34e5442660a0/doppler_env-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-08 23:51:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "dopplerhq",
"github_project": "python-doppler-env",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "setuptools",
"specs": []
},
{
"name": "build",
"specs": []
},
{
"name": "wheel",
"specs": []
},
{
"name": "check-manifest",
"specs": []
},
{
"name": "black",
"specs": []
},
{
"name": "flake8",
"specs": []
},
{
"name": "twine",
"specs": []
}
],
"lcname": "doppler-env"
}