Skip to main content

psenv -- (Parameter Store Environment)

a cli tool for managing environments stored in the AWS parameter store

When working on teams with multiple developers, who may each have their own local development environment, it can be challenging to make sure that each environment has the same set of base parameter values in a .env file to get the base project up and running. It can be common that as a project grows over time, there can be 100s of environment variables which contain everything from project configuration values, to database connection strings, or even secret API keys and tokens.

Sometimes developers may need to keep multiple .env files locally for different projects, each of which may have a different set of parameters. This can become quite difficult to manage across multiple medium to large size teams. This is where psenv comes in, to help those of us who are working within the AWS cloud ecosystem.

Getting Started

pip install psenv

However, since psenv works well as a globally available command, the preferred method of installation is to use pipx

pipx install psenv --include-deps

For those of you who are unfamiliar with pipx, it can be thought of as a "Homebrew for python applications".

Check out the amazing project here ---->>> https://pypa.github.io/pipx/docs/

Initialization

After installation, psenv needs to be initialized and configured. To speed this up you can run

psenv init

This will create a directory at ~/.psenv and a config file at ~/.psenv/psenv.yml as well as an environment file ~/.psenv/psenv.env

Setting Up An Environment

Open the ~/.psenv/psenv.yml file in your editor of choice and make an entry.

environments:
  my_project_name:
    path: /the/path/used/in-the/aws/parameter-store
    env: /path/to/local/env/file/.env

The environments key is a list, which can take as many environment definitions as you like.

Commands

At any time you can type psenv --help for a list of commands.

psenv --help
psenv <command> --help

Displaying Configured Environments

To display the environments configured

psenv show

You should see a list of all available environments formatted in your terminal as a table. This can come in handy as we will later need to reference the configured environments for the other commands

Fetch an Environment from the AWS Parameter Store

This command will fetch all the parameters on the path configured in the path section of the psenv.yml file

psenv fetch --env my_project_name

Push and Environment to the AWS Parameter Store

Sometimes you need to set up new environments. This is easy with psenv add an entry in psenv.yml

environments:
  new_env:
    path: /some/parameter-store/path
    env: /path/to/.env

populate the .env file with the secrets and parameters you need for your environment and then run

psenv push --env new_env

Private Environment Variables

Sometimes a project my have some environment variable where the value is known up-front. (eg. Project Configs), however there may be some values which need to remain secret. After all, it would not make much sense for a developer to store there personal github token in the parameter store for others to copy and use. For this case we have the #<private> section in the .env file.

All variables declared under the #<private> section in the .env file will be ignored automatically by psenv

Credential Injection

Sometimes you might want to copy some environment variables from your current terminal session environment to a .env file. Example when you use temp AWS credentials and need to load them into more than one project / environment. To do this, get your creds however you normally would and then

psenv inject --prefix aws --env some_env

all your aws credentials will be injected to your .env file! Like Magic!

Variable Templating

When configuring an environment to be shared, it is sometimes helpful to give developers hints as to what type of private credentials will be needed to get the code to behave as expected. This is where templating comes in.

psenv allows you to define a placeholder in your .env file using the prefix PSENV__TEMPLATE__that will be templated upon running the fetch command. For example, we have a project that requires a github token, and we want to make this obvious for the next developer we onboard. In our source .env file, we simply declare a variable called PSENV__TEMPLATE__GITHUB_TOKEN. We then run psenv push --env <your-env> to push these values to the parameter store.

SOME_VARIABLE1=123
SOME_VARIABLE2=234

PSENV__TEMPLATE__GITHUB_TOKEN=<REPLACE-WITH-YOUR-PERSONAL-GH-TOKEN>

The next developer we on-board simply needs to run psenv fetch --env <your-env> and the below will be created.

SOME_VARIABLE1=123
SOME_VARIABLE2=234

#<private>
GITHUB_TOKEN=<REPLACE-WITH-YOUR-PERSONAL-GH-TOKEN>

If you would like to fetch the environment values without using the template function, you can pass the --no-template flag to the fetch command, which will then fetch the raw parameters as they were created. This is useful if an admin needs to add, or remove some parameter from an environment.

Release files for psenv 0.17.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psenv 0.17.1
File Size Uploaded
psenv-0.17.1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for psenv 0.17.1
File Interpreter ABI Platform
psenv-0.17.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / psenv-0.17.1.tar.gz

Download URL psenv-0.17.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3e863c1a8d131d48db2dab560a75c032ab39b66ed01743d5ef73cdee9c623b67
BLAKE2b-256 checksum
How to use checksums
86e93b536e94e93cd5d4c83553537b114168425f67d9f9fafadb9461365c97d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.5

Release files / psenv-0.17.1-py3-none-any.whl

Download URL psenv-0.17.1-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
466fcae836ab162a90449b4f9c978594588753f9ad00b76949e51007ff68cf41
BLAKE2b-256 checksum
How to use checksums
ca9e4350fefa4abf56b0e325d423d8e842da8728ef1cc78af72be96ee89e9c5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.17.1 This release

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page