{"id":19001124,"url":"https://github.com/wemake-services/dump-env","last_synced_at":"2025-04-06T07:14:33.611Z","repository":{"id":36982301,"uuid":"114672367","full_name":"wemake-services/dump-env","owner":"wemake-services","description":"A utility tool to create .env files","archived":false,"fork":false,"pushed_at":"2024-04-12T07:09:06.000Z","size":868,"stargazers_count":99,"open_issues_count":3,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-14T07:11:39.154Z","etag":null,"topics":["continuous-integration","dotenv","gitlab-ci","python","travis-ci"],"latest_commit_sha":null,"homepage":"http://dump-env.rtfd.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wemake-services.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"wemake-services","custom":"https://boosty.to/sobolevn"}},"created_at":"2017-12-18T18:03:41.000Z","updated_at":"2024-04-17T03:45:17.392Z","dependencies_parsed_at":"2024-01-29T10:10:13.418Z","dependency_job_id":"809f3465-e90e-4a21-8ab8-0e2d4036d92d","html_url":"https://github.com/wemake-services/dump-env","commit_stats":{"total_commits":290,"total_committers":8,"mean_commits":36.25,"dds":0.5137931034482759,"last_synced_commit":"04bee5fb0e689c2ac129e781805927021b03c2c7"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wemake-services%2Fdump-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wemake-services%2Fdump-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wemake-services%2Fdump-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wemake-services%2Fdump-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wemake-services","download_url":"https://codeload.github.com/wemake-services/dump-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445681,"owners_count":20939961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["continuous-integration","dotenv","gitlab-ci","python","travis-ci"],"created_at":"2024-11-08T18:10:03.630Z","updated_at":"2025-04-06T07:14:33.581Z","avatar_url":"https://github.com/wemake-services.png","language":"Python","funding_links":["https://github.com/sponsors/wemake-services","https://boosty.to/sobolevn"],"categories":[],"sub_categories":[],"readme":"# A utility tool to create ``.env`` files\n\n[![wemake.services](https://img.shields.io/badge/%20-wemake.services-green.svg?label=%20\u0026logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake-services.github.io)\n[![test](https://github.com/wemake-services/dump-env/actions/workflows/test.yml/badge.svg?branch=master\u0026event=push)](https://github.com/wemake-services/dump-env/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/wemake-services/dump-env/branch/master/graph/badge.svg)](https://codecov.io/gh/wemake-services/dump-env)\n[![Python Version](https://img.shields.io/pypi/pyversions/dump-env.svg)](https://pypi.org/project/dump-env/)\n[![Docs](https://readthedocs.org/projects/dump-env/badge/?version=latest)](http://dump-env.readthedocs.io/en/latest/?badge=latest) [![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)\n\n`dump-env` takes an `.env.template` file and some optional environmental variables to create a new `.env` file from these two sources. No external dependencies are used.\n\n\n## Why?\n\nWhy do we need such a tool? Well, this tool is very helpful when your CI is building `docker` (or other) images.\n[Previously](https://github.com/wemake-services/wemake-django-template/blob/6a7ab060e8435fd855cd806706c5d1b5a9e76d12/%7B%7Bcookiecutter.project_name%7D%7D/.gitlab-ci.yml#L25) we had some complex logic of encrypting and decrypting files, importing secret keys and so on.\nNow we can just create secret variables for our CI, add some prefix to it, and use `dump-env` to make our life easier.\n\n\n## Installation\n\n```bash\n$ pip install dump-env\n```\n\n\n## Quickstart\n\nThis quick demo will demonstrate the main and the only purpose of `dump-env`:\n\n```bash\n$ dump-env --template=.env.template --prefix='SECRET_ENV_' \u003e .env\n```\n\nThis command will:\n\n1. take `.env.template`\n2. parse its keys and values\n3. read all the variables from the environment starting with `SECRET_ENV_`\n4. remove this prefix\n5. mix it all together, environment vars may override ones from the template\n6. sort keys in alphabetic order\n7. dump all the keys and values into the `.env` file\n\n\n## Advanced Usage\n\n### Multiple prefixes\n\n```bash\n$ dump-env -t .env.template -p 'SECRET_ENV_' -p 'ANOTHER_SECRET_ENV_' \u003e .env\n```\n\nThis command will do pretty much the same thing as with one prefix. But, it will replace multiple prefixes.\nFurther prefixes always replace previous ones if they are the same.\nFor example:\n\n```bash\n$ export SECRET_TOKEN='very secret string'\n$ export SECRET_ANSWER='13'\n$ export ANOTHER_SECRET_ENV_ANSWER='42'\n$ export ANOTHER_SECRET_ENV_VALUE='0'\n$ dump-env -p SECRET_ -p ANOTHER_SECRET_ENV_\nANSWER=42\nTOKEN=very secret string\nVALUE=0\n```\n\n### Strict env variables\n\nIn case you want to be sure that `YOUR_VAR` exists\nin your environment when dumping, you can use `--strict` flag:\n\n```bash\n$ dump-env --strict YOUR_VAR -p YOUR_\nMissing env vars: YOUR_VAR\n```\n\nOups! We forgot to create it! Now this will work:\n\n```bash\n$ export YOUR_VAR='abc'\n$ dump-env --strict YOUR_VAR -p YOUR_\nVAR=abc\n```\n\nAny number of `--strict` flags can be provided.\nNo more forgotten template overrides or missing env vars!\n\n### Source templates\n\nYou can use an env template as a source template by using the `-s` or `--source` argument. This will restrict any non-prefixed variables found in the environment to only those already defined in your template.\n\n```bash\n$ cat template.env\nANSWER=13\nTOKEN=very secret string\nVALUE=0\n```\n\n```bash\n$ export ANSWER='42'\n$ dump-env --source=template.env\nANSWER=42\nTOKEN=very secret string\nVALUE=0\n```\n\nYou can still also use prefixes to add extra variables from the environment\n\n```bash\n$ export EXTRA_VAR='foo'\n$ dump-env -s template.env -p EXTRA_\nANSWER=13\nTOKEN=very secret string\nVALUE=0\nVAR=foo\n```\n\n#### Strict Source\n\nUsing the `--strict-source` flag has the same effect as defining a `--strict` flag for every variable defined in the source template.\n\n```bash\n$ export ANSWER='42'\n$ dump-env -s template.env --strict-source\nMissing env vars: TOKEN, VALUE\n```\n\n## Creating secret variables in some CIs\n\n- [travis docs](https://docs.travis-ci.com/user/environment-variables/#Defining-encrypted-variables-in-.travis.yml)\n- [gitlab-ci docs](https://docs.gitlab.com/ce/ci/variables/README.html#secret-variables)\n- [github actions](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables)\n\n\n## Real-world usages\n\nProjects that use this tool in production:\n\n- [wemake-django-template](https://github.com/wemake-services/wemake-django-template/blob/master/%7B%7Bcookiecutter.project_name%7D%7D/.gitlab-ci.yml#L24)\n- [wemake-vue-template](https://github.com/wemake-services/wemake-vue-template/blob/master/template/.gitlab-ci.yml#L24)\n\n\n## Related\n\nYou might also be interested in:\n\n- \u003chttps://github.com/wemake-services/dotenv-linter\u003e\n\n\n## License\n\n[MIT](https://github.com/wemake-services/dump-env/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwemake-services%2Fdump-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwemake-services%2Fdump-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwemake-services%2Fdump-env/lists"}