No project description provided
Project description
runenv
Manage your application’s settings with runenv, using the 12-factor principles. This library provides both a CLI tool and a Python API to simplify the management of environment variables in your projects.
| Section | Details |
|---|---|
| CI/CD | |
| Package | |
| Downloads | |
| Python Version | |
| Meta | |
| License | |
| Changes | CHANGELOG.md |
Table of Contents
Features at a Glance
- CLI Tool: Run programs with customized environment variables from a
.envfile. - Python API: Load and manage environment variables programmatically.
- Integration: Easily integrate with frameworks like Django and Flask.
Getting Started
Installation
To install runenv along with its CLI tool, run:
pip install runenv
Quick CLI Usage
- Create a
.envfile in your project’s root directory:
The .env file can contain simple key-value pairs, comment lines, and inline comments:
# Base settings
BASE_URL=http://127.0.0.1:8000
DATABASE_URI=postgres://postgres:password@localhost/dbname
# Email configuration
EMAIL_HOST=smtp.example.com
EMAIL_PORT=587 # Port for SMTP
EMAIL_USER="user@example.com"
EMAIL_PASSWORD='password'
EMAIL_USE_TLS=1
# Reusing variables
EMAIL_FROM=user@${EMAIL_HOST}
- Variables are set in
KEY=VALUEpairs. - Use
#for comments. - Inline comments are also supported after a
#.
-
Run a command with the environment loaded from the
.envfile:runenv .env ./your_command
Python API Overview
You can load environment variables directly in Python:
from runenv import load_env
# Load variables from the specified .env file
load_env(".env")
In-Depth Usage and Examples
Using the CLI Tool
The runenv CLI provides flexibility to run any command with custom environment settings:
runenv .env.development ./manage.py runserver
Full help and options:
runenv --help
usage: runenv [-h] [-V] [-v {1,2,3}] [-p PREFIX] [-s] [--dry-run] env_file command
Run program with given environment file loaded
positional arguments:
env_file Environment file to load
command Command to run with loaded environment
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-v {1,2,3}, --verbosity {1,2,3}
verbosity level, 1 - (ERROR, default), 2 - (INFO) or 3 - (DEBUG)
-p PREFIX, --prefix PREFIX
Load only variables with given prefix
-s, --strip-prefix Strip prefix given with --prefix from environment variables names
--dry-run Return parsed .env instead of running command
Python API Details
load_env
Load variables into the environment:
load_env(env_file=".env", prefix="DJANGO_", strip_prefix=True, force=False, search_parent=0)
Parameters:
env_file(str, optional): The environment file to read from (default is.env).prefix(str, optional): Load only variables that start with this prefix.strip_prefix(bool, optional): If True, removes the prefix from variable names when loaded (default is True).force(bool, optional): Force loading the.envfile again even if already loaded byrunenvCLI (default is False).search_parent(int, optional): Number of parent directories to search for.envfile (default is 0).
create_env
Parse .env contents into a dictionary without modifying the environment:
env_vars = create_env(env_file=".env", prefix="APP_", strip_prefix=True)
print(env_vars)
Parameters:
env_file(str, optional): The environment file to read from (default is.env).prefix(str, optional): Load only variables that start with this prefix.strip_prefix(bool, optional): If True, removes the prefix from variable names when loaded (default is True).
Framework Integration
Easily integrate runenv with web frameworks:
# In Django's manage.py or Flask's app setup
from runenv import load_env
load_env(".env")
Similar Projects
- envdir: Run programs with a modified environment based on files in a directory.
- python-dotenv: Reads key-value pairs from
.envfiles and adds them to the environment.
With runenv, managing environment variables becomes simpler and more consistent, making it easier to develop and deploy applications across different environments.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file runenv-1.2.3.tar.gz.
File metadata
- Download URL: runenv-1.2.3.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0736f6d4a9345513991d70554a16022886dead25f911aab9cc0d3e15cf1bbf3
|
|
| MD5 |
8beac911c792bf06a11ff643bd526e16
|
|
| BLAKE2b-256 |
62895b5d7f3b7710796cae48ef1ea49ad1b343829e9452f6b5103c68fe87ed73
|
File details
Details for the file runenv-1.2.3-py2.py3-none-any.whl.
File metadata
- Download URL: runenv-1.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a3777a5e525a8555e0ca3f18bd1e4611c163f1a08cda9d86d8a7d90f1081618
|
|
| MD5 |
f2800f63766ba76b0a995e7f215961cf
|
|
| BLAKE2b-256 |
833b5825e5b60dc37a9c5998e22b3ba861909aacc9dd5463a218ca407bc1f70a
|