Skip to main content

OneEnv: Environment variable management and generation tool

Project description

OneEnv ๐ŸŒŸใ€€PyPI Downloads

OneEnv is a revolutionary environment variable management tool for Python applications that makes configuration management incredibly simple. It automatically discovers and consolidates environment variable templates from all your installed packages into a single .env.example file - no manual configuration required!

Why OneEnv Makes Your Life Easier ๐Ÿš€

Before OneEnv:

  • ๐Ÿ˜“ Manual creation of .env.example files for each project
  • ๐Ÿ˜ค Hunting through documentation to find required environment variables
  • ๐Ÿ˜ฑ Missing critical configuration when integrating new packages
  • ๐Ÿคฏ Inconsistent environment variable formats across projects

After OneEnv:

  • โœจ Automatic discovery of environment variables from all packages
  • ๐ŸŽฏ One command generates complete .env.example files
  • ๐Ÿ”„ Smart merging of duplicate variables with detailed descriptions
  • ๐Ÿ“ฆ Plugin ecosystem where packages provide their own templates
  • ๐Ÿ›ก๏ธ Type safety with Pydantic validation

Revolutionary Features ๐ŸŒŸ

๐Ÿ”Œ Plugin System with Entry-points

Packages can automatically provide their environment variable templates - just install and use!

๐ŸŽจ Smart Duplicate Handling

When multiple packages define the same variable, OneEnv intelligently merges descriptions while keeping configuration consistent.

โšก Zero Configuration Setup

Install a package with OneEnv templates? They're automatically discovered. No imports, no manual registration needed.

๐Ÿ”’ Type-Safe Templates

Built with Pydantic models for runtime validation and better error messages.

๐Ÿ“‹ Legacy Decorator Support

Existing @oneenv decorators continue to work seamlessly alongside the new plugin system.

Supported Environments ๐Ÿ–ฅ๏ธ

  • Python: โ‰ฅ 3.10
  • Operating Systems: Windows, macOS, Linux

Installation ๐Ÿ“ฆ

You can install OneEnv easily via pip:

pip install oneenv

For development mode, install from the source using:

pip install -e .

Super Simple Usage ๐ŸŽฏ

Step 1: Install Packages with OneEnv Support

pip install oneenv
pip install django-oneenv-plugin  # Example: Django templates
pip install fastapi-oneenv-plugin # Example: FastAPI templates

Step 2: Generate Your Environment Template

oneenv template

That's it! ๐ŸŽ‰ OneEnv automatically discovers all environment variables from your installed packages and creates a complete .env.example file.

Advanced Usage ๐Ÿš€

๐Ÿ” See What's Discovered

oneenv template -d

This shows you:

  • ๐Ÿ“ฆ Which plugins were discovered
  • ๐Ÿ”„ Which variables are duplicated across packages
  • โšก Template generation process

๐Ÿ“ Custom Output File

oneenv template -o my-custom.env

๐Ÿ”„ Compare Environment Files

oneenv diff old.env new.env

For Package Developers: Creating OneEnv Plugins ๐Ÿ“ฆ

Method 1: Modern Plugin System (Recommended) โญ

Create environment templates that are automatically discovered:

1. Create your template function:

# mypackage/templates.py

# Option A: New Groups Format (Recommended) โญ
def database_template():
    """Database configuration template"""
    return {
        "groups": {
            "Database": {
                "DATABASE_URL": {
                    "description": "Database connection URL\nExample: postgresql://user:pass@localhost:5432/db",
                    "default": "sqlite:///app.db",
                    "required": True,
                    "importance": "critical"
                },
                "DB_POOL_SIZE": {
                    "description": "Database connection pool size",
                    "default": "10",
                    "required": False,
                    "choices": ["5", "10", "20", "50"],
                    "importance": "important"
                }
            },
            "Cache": {
                "REDIS_URL": {
                    "description": "Redis connection URL",
                    "default": "redis://localhost:6379/0",
                    "importance": "important"
                }
            }
        }
    }

# Option B: Traditional Format (Still Supported)
def legacy_template():
    """Legacy format template"""
    return {
        "DATABASE_URL": {
            "description": "Database connection URL",
            "default": "sqlite:///app.db",
            "required": True,
            "group": "Database",
            "importance": "critical"
        }
    }

2. Register in pyproject.toml:

[project.entry-points."oneenv.templates"]
database = "mypackage.templates:database_template"
redis = "mypackage.templates:redis_template"

3. That's it! ๐ŸŽ‰ When users install your package, OneEnv automatically discovers your templates.

Method 2: Legacy Decorator System ๐Ÿ“‹

Still supported for backward compatibility:

from oneenv import oneenv

@oneenv
def my_env_template():
    return {
        "MY_API_KEY": {
            "description": "API key for accessing the service",
            "default": "",
            "required": True
        },
        "MODE": {
            "description": "Application mode setting",
            "default": "development",
            "required": False,
            "choices": ["development", "production"]
        }
    }

Smart Duplicate Variable Handling ๐ŸŽจ

When multiple packages define the same environment variable, OneEnv intelligently merges them:

Example Output:

# Auto-generated by OneEnv

# (Defined in: django-plugin, fastapi-plugin)
# Django database connection URL
# Example: postgresql://user:pass@localhost:5432/django_db
# From fastapi-plugin:
# FastAPI application database connection
# Supports: PostgreSQL, MySQL, SQLite
# Required
DATABASE_URL=sqlite:///django.db

# (Defined in: redis-plugin)
# Redis connection URL
# Example: redis://localhost:6379/0
REDIS_URL=redis://localhost:6379/0

How it works:

  • โœ… Single entry: Each variable appears only once
  • ๐Ÿ“ Merged descriptions: All package descriptions are combined
  • โš™๏ธ First wins: Configuration (default, required, choices) uses the first package's settings
  • ๐Ÿ“‹ Source tracking: Shows which packages define each variable

Template Field Reference ๐Ÿ“š

Basic Template (v0.1.x - v0.2.x)

{
    "VARIABLE_NAME": {
        "description": "Clear description of what this variable does",  # Required
        "default": "default_value",      # Optional: Default value
        "required": True,                # Optional: Whether required (default: False)
        "choices": ["option1", "option2"] # Optional: Valid choices
    }
}

Enhanced Template (v0.3.0+)

Traditional Enhanced Format

{
    "VARIABLE_NAME": {
        "description": "Clear description of what this variable does",  # Required
        "default": "default_value",      # Optional: Default value
        "required": True,                # Optional: Whether required (default: False)
        "choices": ["option1", "option2"], # Optional: Valid choices
        "group": "Category Name",        # NEW: Group for organization
        "importance": "critical"         # NEW: critical/important/optional
    }
}

New Groups Format (v0.3.1+) โญ

{
    "groups": {
        "Database": {
            "DATABASE_URL": {
                "description": "Database connection URL",
                "default": "postgresql://localhost:5432/mydb",
                "required": True,
                "importance": "critical"
            },
            "DB_POOL_SIZE": {
                "description": "Maximum database connections",
                "default": "10",
                "importance": "important"
            }
        },
        "Security": {
            "SECRET_KEY": {
                "description": "Application secret key",
                "required": True,
                "importance": "critical"
            }
        }
    }
}

Mixed Format (Both Supported)

{
    # Direct variables (assigned to default group)
    "GLOBAL_VAR": {
        "description": "Global setting",
        "group": "Application",  # Explicit group assignment
        "importance": "critical"
    },
    
    # Grouped variables
    "groups": {
        "Database": {
            "DATABASE_URL": {...}
        }
    }
}

Importance Levels

  • critical: Essential settings for application operation (ๅฟ…้ ˆ่จญๅฎš้ …็›ฎ)
  • important: Settings to configure for production use (้‡่ฆ่จญๅฎš้ …็›ฎ)
  • optional: Fine-tuning settings where defaults are sufficient (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆใงๅๅˆ†)

Real-World Examples ๐ŸŒ

Django + FastAPI + Redis Project

pip install oneenv django-oneenv fastapi-oneenv redis-oneenv
oneenv template

Generated .env.example (v0.3.0 with grouping):

# Auto-generated by OneEnv

# ========== CRITICAL: Essential Settings for Application Operation ==========

# ----- Database -----

# (Defined in: django-oneenv, fastapi-oneenv)
# Django database connection URL
# From fastapi-oneenv: FastAPI database connection
# Required
DATABASE_URL=sqlite:///django.db

# ----- Security -----

# (Defined in: django-oneenv)
# Django secret key for security
# Required
SECRET_KEY=your-secret-key-here

# ========== IMPORTANT: Settings to Configure for Production Use ==========

# ----- Cache -----

# (Defined in: redis-oneenv)
# Redis connection for caching and sessions
REDIS_URL=redis://localhost:6379/0

Custom Project Templates (v0.3.1 Enhanced)

# myproject/env_templates.py
from oneenv import oneenv

# New Groups Format (Recommended)
@oneenv
def custom_project_config():
    return {
        "groups": {
            "Application": {
                "PROJECT_NAME": {
                    "description": "Name of your awesome project",
                    "default": "My Awesome App",
                    "required": True,
                    "importance": "critical"
                },
                "ENVIRONMENT": {
                    "description": "Deployment environment",
                    "default": "development",
                    "choices": ["development", "staging", "production"],
                    "importance": "important"
                }
            },
            "Logging": {
                "LOG_ROTATION_DAYS": {
                    "description": "Number of days to keep log files",
                    "default": "30",
                    "required": False,
                    "importance": "optional"
                },
                "LOG_LEVEL": {
                    "description": "Application logging level",
                    "default": "INFO",
                    "choices": ["DEBUG", "INFO", "WARNING", "ERROR"],
                    "importance": "optional"
                }
            }
        }
    }

# Traditional Format (Still Supported)
@oneenv
def legacy_project_config():
    return {
        "PROJECT_NAME": {
            "description": "Name of your awesome project",
            "default": "My Awesome App",
            "required": True,
            "group": "Application",
            "importance": "critical"
        }
    }

Integration with dotenv ๐Ÿ”„

OneEnv wraps python-dotenv, so you can use all dotenv features directly:

from oneenv import load_dotenv, dotenv_values

# Load environment variables
load_dotenv()

# Get variables as dictionary
config = dotenv_values(".env")

What's New in v0.3.1 ๐Ÿ†•

๐Ÿ—๏ธ Revolutionary Groups Format

One function can now define multiple groups, making template organization incredibly flexible:

@oneenv
def complete_webapp_config():
    return {
        "groups": {
            "Database": {
                "DATABASE_URL": {...},
                "DB_POOL_SIZE": {...}
            },
            "Security": {
                "SECRET_KEY": {...},
                "JWT_EXPIRY": {...}
            },
            "Cache": {
                "REDIS_URL": {...}
            }
        }
    }

Benefits:

  • ๐Ÿ“ฆ Single Source: One function defines all related variables
  • ๐ŸŽฏ Logical Grouping: Variables are automatically organized by purpose
  • ๐Ÿ”„ Backward Compatible: Traditional format still works perfectly
  • ๐Ÿš€ Entry-Point Friendly: Fewer entry-point registrations needed

๐ŸŽฏ Smart Organization & Prioritization (v0.3.0)

Environment variables are intelligently organized by importance and grouped by category:

  • ๐Ÿ“Š Enhanced Grouping: Both traditional and new groups format supported
  • โšก Importance Levels:
    • critical: Essential for application operation
    • important: Should be configured for production
    • optional: Fine-tuning settings (defaults are sufficient)
  • ๐ŸŒ Multilingual Headers: Automatic locale detection with Japanese/English support

๐Ÿ“‹ Enhanced Template Format

@oneenv
def advanced_template():
    return {
        "DATABASE_URL": {
            "description": "Primary database connection",
            "default": "postgresql://localhost:5432/mydb",
            "required": True,
            "group": "Database",        # NEW: Group organization
            "importance": "critical"    # NEW: Priority level
        },
        "LOG_LEVEL": {
            "description": "Application logging level",
            "default": "INFO",
            "required": False,
            "group": "Logging",
            "importance": "important"
        }
    }

๐ŸŒ Multilingual Support

Japanese Environment:

# ========== CRITICAL: ๅฟ…้ ˆ่จญๅฎš้ …็›ฎ ==========
# ========== IMPORTANT: ้‡่ฆ่จญๅฎš้ …็›ฎ ==========
# ========== OPTIONAL: ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆใงๅๅˆ† ==========

English Environment:

# ========== CRITICAL: Essential Settings for Application Operation ==========
# ========== IMPORTANT: Settings to Configure for Production Use ==========
# ========== OPTIONAL: Fine-tuning Settings (Defaults are Sufficient) ==========

๐Ÿ”„ Perfect Backward Compatibility

All existing templates work unchanged! New features use sensible defaults:

  • group: "General" (if not specified)
  • importance: "important" (if not specified)

Previous Updates

v0.2.0: Revolutionary Plugin System

  • Entry-points Integration: Packages automatically provide environment variable templates
  • Smart Duplicate Handling: Intelligent merging of variables from multiple packages
  • Pydantic Type Safety: Runtime validation with clear error messages
  • Zero Configuration: Automatic discovery - no imports or manual registration needed

Why OneEnv is Game-Changing ๐ŸŽฏ

  • ๐Ÿšซ No more hunting: Environment variables are automatically documented
  • โšก Zero setup time: Install packages, run one command, done
  • ๐Ÿ”„ Stay synchronized: Environment configs update automatically with package updates
  • ๐Ÿ‘ฅ Team harmony: Everyone gets the same environment setup
  • ๐Ÿ“ฆ Ecosystem growth: Package authors can provide better configuration experiences

Running Tests ๐Ÿงช

pytest tests

Contributing ๐Ÿค

We welcome contributions! Please feel free to submit a Pull Request or open an issue on GitHub.

License โš–๏ธ

This project is released under the MIT License.

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

oneenv-0.3.1.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

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

oneenv-0.3.1-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file oneenv-0.3.1.tar.gz.

File metadata

  • Download URL: oneenv-0.3.1.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for oneenv-0.3.1.tar.gz
Algorithm Hash digest
SHA256 760c1c6a4c7d000c2c3da157281f04076160572e2c914577b63dc48043027c4e
MD5 e4ee5a355ad7732e17d6665ec1401c2e
BLAKE2b-256 6d590217d4f2ff29cd97c1073697db15ca1614e43d7117ba86fd7ce7e8b0e975

See more details on using hashes here.

File details

Details for the file oneenv-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: oneenv-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 20.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for oneenv-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2361ae9ef7ff5dba5f4b19cd7ec306f60d7228fd3af3310528d2a960889735dc
MD5 8b87754ed7edb33127e45ef25b701a3c
BLAKE2b-256 91fc1d5a475928548e51cb31f26adc75ba004b2f795420dc39fde6d476160845

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