Skip to main content

Load environment variables from pass entries

Project description

PassEnv

Load environment variables from pass entries seamlessly in your shell.

Features

  • Secure: Leverages the existing pass password manager
  • Simple: Load/unload environment variables with a single command
  • Stateful: Tracks what's loaded and prevents conflicts
  • Auto-completion: Tab completion for pass entries
  • Shell Integration: Works with bash, zsh, fish, and more

Installation

Prerequisites

  • pass must be installed and initialized
  • Python 3.10 or higher

Install from PyPI

pip install passenv

Set up shell integration

After installation, run the setup command:

passenv install

This will add the necessary shell function and completion to your ~/.bashrc, ~/.zshrc, or specific shell rc file.

Usage

Basic Commands

# Load environment variables from a pass entry at database/envs
passenv load database/envs

# Check what's currently loaded
passenv status

# List available pass entries
passenv list

# Unload current environment
passenv unload

# Export as .env format (default)
passenv export database/envs

Pass Entry Format

Store your environment variables in pass entries using the KEY=VALUE format:

# Create a pass entry
pass edit database/envs

Example entry content:

DATABASE_URL=postgres://user:pass@localhost/mydb
API_KEY=secret123
DEBUG=false
# This is a comment
LOG_LEVEL=info

Advanced Usage

Environment Isolation

PassEnv automatically handles environment isolation:

  • Loading a new set of environment variables automatically unloads the previous ones
  • Tracks which variables were loaded to prevent conflicts
  • Provides clear status information

Examples

Development Workflow

# Load development environment
passenv load myapp/development

# Run your application
python manage.py runserver

# Switch to staging environment
passenv load myapp/staging

# Deploy to staging
./deploy.sh

# Clean up
passenv unload

Basic Export Usage

# Export as .env format (default)
passenv export database/envs

# Export to different formats
passenv export database/envs --format yaml
passenv export database/envs --format json
passenv export database/envs --format csv
passenv export database/envs --format docker

# Save to file
passenv export database/envs --output .env
passenv export database/envs --format yaml --output config.yaml

Export Formats

.env format (default)

passenv export myapp/production

Output:

DATABASE_URL=postgres://user:pass@localhost/mydb
API_KEY=secret123
DEBUG=false
LOG_LEVEL=info

YAML format

passenv export myapp/production --format yaml

Output:

DATABASE_URL: postgres://user:pass@localhost/mydb
API_KEY: secret123
DEBUG: "false"
LOG_LEVEL: info

JSON format

passenv export myapp/production --format json

Output:

{
  "DATABASE_URL": "postgres://user:pass@localhost/mydb",
  "API_KEY": "secret123", 
  "DEBUG": "false",
  "LOG_LEVEL": "info"
}

CSV format

passenv export myapp/production --format csv

Output:

KEY,VALUE
DATABASE_URL,postgres://user:pass@localhost/mydb
API_KEY,secret123
DEBUG,false
LOG_LEVEL,info

Docker format

passenv export myapp/production --format docker

Output:

-e DATABASE_URL="postgres://user:pass@localhost/mydb" -e API_KEY="secret123" -e DEBUG="false" -e LOG_LEVEL="info"

Docker Integration Examples

# Export and use directly with docker run
docker run $(passenv export myapp/production --format docker) my-app:latest

# Save to file and use with docker-compose
passenv export myapp/production --output .env
docker-compose up

# Use with Kubernetes ConfigMap
passenv export myapp/production --format yaml --output configmap.yaml
kubectl create configmap app-config --from-file=configmap.yaml

Pass Entry Organization Suggestion

Organize your pass entries logically:

myapp/
├── development
├── staging
└── production

database/
├── local
├── staging
└── production

Environment Variable Format

  • Comments: Lines starting with # are ignored
  • Empty lines: Skipped automatically
  • Format: KEY=VALUE (spaces around = are stripped)
  • Quotes: Optional quotes around values are removed
  • Variable names: Must be valid shell variable names ([A-Za-z_][A-Za-z0-9_]*)

Troubleshooting

Common Issues

Pass not found

Error: 'pass' command not found. Please install pass.

Install pass using your package manager:

# Ubuntu/Debian
sudo apt install pass

# macOS
brew install pass

# Arch Linux
sudo pacman -S pass

Pass not initialized

Error: Pass store not initialized.

Initialize your pass store:

pass init your-gpg-key-id

Entry not found

Error: Pass entry 'myapp/staging' not found.

Create the entry:

pass edit myapp/staging

Invalid variable format

Error: Invalid line 'malformed-line' in pass entry.

Check your pass entry format. Each line should be KEY=VALUE or a comment.

Getting Help

# Show help
passenv --help

# Show command-specific help
passenv load --help

Development

Local Development

# Clone the repository
git clone https://github.com/yourusername/passenv.git
cd passenv

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/
isort src/ tests/

# Type checking
mypy src/

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=passenv

# Run specific test file
pytest tests/test_parser.py

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

MIT License - see LICENSE file for details.

Related Projects

  • pass - The password manager this tool integrates with

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

passenv-0.3.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

passenv-0.3.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file passenv-0.3.0.tar.gz.

File metadata

  • Download URL: passenv-0.3.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for passenv-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5b9450c42cd2164a276f43f52f80941004b7ec7ad29251c13ff506b44663a2d1
MD5 a1ddc6e7531aca96185ccd6f589daef2
BLAKE2b-256 fa9972b0f587438095a4aecf8823f0e4abcf348ccf57d62e78cacae2c8e9e699

See more details on using hashes here.

File details

Details for the file passenv-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: passenv-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for passenv-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d28952883fa78c7609a6723c5cc84d2b9ed295af983e3ba716da0dfbbeb37eb8
MD5 d8cf95326a5c823a145bd4359eda46eb
BLAKE2b-256 99d5c818f2fa78afb76c68be325b80fa578b645f990ae965f649abb8413e994d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page