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 and zsh

Installation

Prerequisites

  • pass must be installed and initialized
  • Python 3.8 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

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

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.2.0.tar.gz (9.8 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.2.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for passenv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a228ac814aeb547bf2656bba66221dc2a96e1f171b0c4cf84bf0425cc42b089
MD5 924f49d2aa2892a51c291678d370cb83
BLAKE2b-256 3af05debfc7f5816c785cb7c2dd6ba624f6197cb646b5b6a4ec53dc5f16e1ac3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: passenv-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3d7a8a2456d7d342b6a5b7439aeecb5e03358fa1dc366b0b63348c916713192
MD5 7e20f4631f65f59d4515373c886477ee
BLAKE2b-256 f17fdee049c9833e7deb1730c43875642760a45515b84438ae0f2f84dcc91d07

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