Skip to content

rahulsub/envprofile

Repository files navigation

EnvProfile - Environment Variable Profile Manager

Python Tests PyPI version License: MIT

EnvProfile is a tool that lets you create and manage different sets of environment variables that you can easily load when needed. This is particularly useful for developers who work with different projects that require different environment configurations.

Features

  • Create multiple named environment profiles
  • Add, remove, and update environment variables in profiles
  • Load environment variables from profiles into your current shell
  • List available profiles and view their contents
  • Easy to use command-line interface

Installation

From PyPI (Recommended)

pip install envprofile

From Source

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

# Install the package
pip install -e .

Shell Integration

Add a shell function to your .bashrc, .zshrc, or equivalent shell configuration file:

# Add this to your shell configuration file
function use-env() {
    eval "$(envprofile load $1)"
}

Reload your shell configuration:

source ~/.bashrc  # or ~/.zshrc

Usage Examples

Creating Profiles

# Create a new profile for development environment
envprofile create dev

# Add environment variables to the profile
envprofile add dev DB_HOST localhost
envprofile add dev DB_PORT 5432
envprofile add dev API_KEY dev_api_key_123
envprofile add dev DEBUG true

# Create another profile for production
envprofile create prod
envprofile add prod DB_HOST production.example.com
envprofile add prod DB_PORT 5432
envprofile add prod API_KEY prod_api_key_456
envprofile add prod DEBUG false

Managing Profiles

# List all available profiles
envprofile list

# Show details of a specific profile
envprofile show dev

# Remove a variable from a profile
envprofile remove dev DEBUG

# Delete an entire profile
envprofile delete test

Loading Profiles

# Method 1: Using the shell function defined during installation
use-env dev

# Method 2: Direct evaluation
eval $(envprofile load prod)

Checking Active Environment Variables

# After loading a profile, you can verify the environment variables are set
echo $DB_HOST
echo $API_KEY

Configuration

All profiles are stored in a single JSON file at ~/.config/envprofile/profiles.json. The format is:

{
  "dev": {
    "DB_HOST": "localhost",
    "DB_PORT": "5432",
    "API_KEY": "dev_api_key_123"
  },
  "prod": {
    "DB_HOST": "production.example.com",
    "DB_PORT": "5432",
    "API_KEY": "prod_api_key_456"
  }
}

Advanced Usage

Using with Docker

You can use EnvProfile to generate environment files for Docker:

# Generate a .env file for docker-compose
envprofile load dev > .env

Using with Multiple Projects

Create project-specific profiles by using prefixes:

# Create profiles for different projects
envprofile create project1-dev
envprofile create project1-prod
envprofile create project2-dev

Troubleshooting

Common Issues

Issue: Changes to environment variables not appearing in the shell

Solution: Make sure you're using the eval command or the use-env function as described in the installation section.

Issue: Error "command not found: envprofile"

Solution: Ensure that the installation directory is in your PATH or install using pip.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Inspired by various environment management tools like direnv and autoenv
  • Thanks to all contributors

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors