Skip to main content

Environment variable mapping utilities for UniversalInit framework

Project description

UniversalInit Environment Package

A Python package for mapping environment variables between different frameworks and a common format.

Features

  • Map environment variables from framework-specific formats to a common format
  • Map environment variables from common format to framework-specific formats
  • Support for multiple frameworks through YAML template files
  • Easy extensibility for new frameworks
  • Optional prefix support for bulk environment variable transformation

Installation

pip install universalinit-env

Usage

Basic Usage

from universalinit_env import map_framework_to_common, map_common_to_framework

# Map React-specific env vars to common format
react_env = {
    "REACT_APP_SUPABASE_URL": "https://example.supabase.co",
    "REACT_APP_API_KEY": "your-api-key",
    "REACT_APP_DATABASE_URL": "postgresql://..."
}

common_env = map_framework_to_common("react", react_env)
# Result: {"SUPABASE_URL": "https://example.supabase.co", ...}

# Map common env vars to React format
framework_env = map_common_to_framework("react", common_env)
# Result: {"REACT_APP_SUPABASE_URL": "https://example.supabase.co", ...}

Available Functions

  • get_template_path(framework): Get the path to the environment template file for a given framework
  • parse_template_file(template_path): Parse a YAML template file and extract the prefix and mapping
  • map_common_to_framework(framework, common_env): Map common environment variables to framework-specific ones
  • map_framework_to_common(framework, framework_env): Map framework-specific environment variables to common ones
  • get_supported_frameworks(): Get a list of supported frameworks

Supported Frameworks

Currently supports:

  • React (via react/env.template)

Template File Format

Environment template files use YAML syntax with the following structure:

# Optional prefix that will be added to all environment variables
# prefix: REACT_APP_

# Direct mapping of environment variables
mapping:
  # Example: maps FOO environment variable to REACT_FOO in the React app
  REACT_FOO: FOO
  
  # Example: maps API_URL environment variable to REACT_API_URL in the React app
  REACT_API_URL: API_URL
  
  # Example: maps DATABASE_URL environment variable to REACT_DB_URL in the React app
  REACT_DB_URL: DATABASE_URL

Template Rules:

  1. Prefix (Optional): If specified, all unmapped environment variables will have this prefix added
  2. Direct Mapping: Specific environment variable name transformations
  3. Fallback: Any environment variable not matched by mapping rules preserves its original name

Mapping Priority:

  1. Direct mappings in the mapping section are applied first
  2. If a prefix is specified, it's applied to remaining unmapped variables
  3. Any variables still unmapped are preserved as-is

Adding New Frameworks

To add support for a new framework:

  1. Create a new directory under src/universalinit_env/ with your framework name
  2. Add an env.template file with YAML mappings:
    # Optional prefix
    prefix: FRAMEWORK_PREFIX_
    
    # Direct mappings
    mapping:
      FRAMEWORK_VAR: COMMON_VAR
    
  3. The framework will automatically be detected and available

Development

# Install dependencies
poetry install

# Run tests
pytest

License

Same license as the main UniversalInit project.

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

universalinit_env-0.1.9.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

universalinit_env-0.1.9-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file universalinit_env-0.1.9.tar.gz.

File metadata

  • Download URL: universalinit_env-0.1.9.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.14.0-29-generic

File hashes

Hashes for universalinit_env-0.1.9.tar.gz
Algorithm Hash digest
SHA256 ec70050ad0a06e2208a15d9acb1cd8ab1e06e0d1c4d49ecbece7a12c52569d99
MD5 23e72998c22a9f7667e54c49a5e68f80
BLAKE2b-256 f8f761580252ef7f0a772d8c73d76587cce1a40d8b17fad341a494e278d38b3a

See more details on using hashes here.

File details

Details for the file universalinit_env-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: universalinit_env-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.14.0-29-generic

File hashes

Hashes for universalinit_env-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 64dd5068e867079f66ee454329184ae0b9cb19c8187b27945d6967e1310b94e6
MD5 854ec4771e23e03c9bd429eaf5ad9a29
BLAKE2b-256 55ce8715ee0770af6689a8b479c322a89d1a90a0c5625f1103381e32dffa8eee

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