Skip to main content

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 CI - Test
Package PyPI - Version
Downloads PyPI - Downloads
Python Version PyPI - Python Version
Meta Linting - Ruff Code Style - Black Types - MyPy
License License - MIT
Changes CHANGELOG.md

Table of Contents

Features at a Glance

  • CLI Tool: Run programs with customized environment variables from a .env file.
  • 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

  1. Create a .env file 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=VALUE pairs.
  • Use # for comments.
  • Inline comments are also supported after a #.
  1. Run a command with the environment loaded from the .env file:

    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 .env file again even if already loaded by runenv CLI (default is False).
  • search_parent (int, optional): Number of parent directories to search for .env file (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 .env files 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


Download files

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

Source Distribution

runenv-1.2.4.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

runenv-1.2.4-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file runenv-1.2.4.tar.gz.

File metadata

  • Download URL: runenv-1.2.4.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for runenv-1.2.4.tar.gz
Algorithm Hash digest
SHA256 73d76d5167951444f25f3bfa3e357522ca2566771e4e9d9c1386ca3ef6a24ca9
MD5 821a387379f21ce9c44c99e651ff10d2
BLAKE2b-256 0c132c87244c648380098b6b5fba158fc0bd21cf5fd4decea6e98f7e9fec024c

See more details on using hashes here.

File details

Details for the file runenv-1.2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: runenv-1.2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for runenv-1.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 466c469b5673c76474752a25307e466a93d8981f3a1f19ce995b6435d80a2ccc
MD5 65ddaadcc80875d66cac8b57263d04fb
BLAKE2b-256 97fcf24d795e6ad05d5c1fd6b9cc3dacd71ca74879abac5281f884814ca41a51

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