Skip to main content

Bitwarden Environment Variables

Securely use and share environment variables in your local development using Bitwarden!

Before Using This Tool

Before using this tool, it is recommended you take a look at Bitwarden Secrets Manager and see if it fulls your needs. At the time of writing, it is in beta and does not have the ability to replicate this tool's feature set. However, the Bitwarden Secrets Manager CLI is described as "a powerful tool for retrieving and injecting your secrets", so it may be possible to replicate this tool with their native offering in the future.

Why Use This Tool

In short, storing your secrets (e.g., API keys, client secrets, etc.) in a plaintext .env file is insecure and not portable. If your computer is ever hacked or stolen, the perpetrator will have easy access to this data. Additionally, with any distributed system without a central source of truth, it can be hard to know what the most up-to-date version of any secret is. In other words, when working in a team, storing your secrets in a secrets/passwords manager makes it is much easier to keep everyone in sync. This tool helps bridge the gap between storing these secrets in Bitwarden, and using these secrets in your shell.

Install

pip install bwenv

This tool requires the Bitwarden CLI. Make sure it is on your PATH before using this tool (or else you will get a FileNotFoundError error).

Usage

bwenv [-h] [--session SESSION] {run,generate} ...

This tool uses the Bitwarden CLI and needs a session token to access your Bitwarden vault. The session token can be generated by running bw unlock and can be passed into this tool by either setting the session token to the BW_SESSION environment variable or by using the --session flag.

Setting up Bitwarden

Within Bitwarden, you need to create the item to hold your environment variables. The type of the item does not matter, however all environment variables need to add to the Custom Fields section and must not have the type Linked. Fields with type Linked will not have an environment variable created for them.

Custom Fields in the Bitwarden App

bwenv generate

bwenv generate [-h] [-f ENV_FILE] name [name ...]

This command is for generating a .env file (filename is customizable with the -f flag). This will perform either a fuzzy search for the Bitwarden Item Name or ID. The founded environment variables will be appended to file (i.e., this will not overwrite existing data within the file).

bwenv run

bwenv run [-h] [-f ENV_FILE] command [command ...]

This command is for running a command with the environment variables pulled from Bitwarden. .env is the default filename and can be customized with the -f flag. This will not create environment variables for key-values defined without the bwenv:// prefix.

Is it safe to commit the generated .env?

You should still avoid committing your .env, however if your .env is exposed, none of the information in the generated secret reference string is sensitive. You would still need the Bitwarden credentials to make use of this information.

What about 1Password?

1Password already has native support this for feature, and it is called Secret References.

Metadata

Release files for bwenv 1.0.0

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

Source distribution (sdist)

Source distribution for bwenv 1.0.0
File Size Uploaded
bwenv-1.0.0.tar.gz 7.0 kB Details

Built distribution (wheel)

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

Total release size: 15.0 kB

Release files / bwenv-1.0.0.tar.gz

Download URL bwenv-1.0.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f297516226f0b3556c1eee46d1d3a517a855941970105e9baef316edc45946e0
BLAKE2b-256 checksum
How to use checksums
70fc6eaaed941959914e29463100802cb7ad55b747960d2ce8a93b9a2ebe6fb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / bwenv-1.0.0-py3-none-any.whl

Download URL bwenv-1.0.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33692e7985e6f105b97773398842e8fb91eaa3251536907de8498fa361aa0a15
BLAKE2b-256 checksum
How to use checksums
650a5036580842881d238e6e91538b3eb34d6b795590e1610c3b91aed42fbb02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

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