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 frameworkparse_template_file(template_path): Parse a YAML template file and extract the prefix and mappingmap_common_to_framework(framework, common_env): Map common environment variables to framework-specific onesmap_framework_to_common(framework, framework_env): Map framework-specific environment variables to common onesget_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:
- Prefix (Optional): If specified, all unmapped environment variables will have this prefix added
- Direct Mapping: Specific environment variable name transformations
- Fallback: Any environment variable not matched by mapping rules preserves its original name
Mapping Priority:
- Direct mappings in the
mappingsection are applied first - If a prefix is specified, it's applied to remaining unmapped variables
- Any variables still unmapped are preserved as-is
Adding New Frameworks
To add support for a new framework:
- Create a new directory under
src/universalinit_env/with your framework name - Add an
env.templatefile with YAML mappings:# Optional prefix prefix: FRAMEWORK_PREFIX_ # Direct mappings mapping: FRAMEWORK_VAR: COMMON_VAR
- 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
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 universalinit_env-0.1.6.tar.gz.
File metadata
- Download URL: universalinit_env-0.1.6.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bce33f668902ae15c658b93620b81b877dd50c2f1ed01b29a17770ee9399e202
|
|
| MD5 |
dd9767695093a723b2e9501c22ee7e22
|
|
| BLAKE2b-256 |
88b90bc00635fbcd6f0d273553dc98e3cc1f74e07bf42ac0e9cfbdc79f36b2d1
|
File details
Details for the file universalinit_env-0.1.6-py3-none-any.whl.
File metadata
- Download URL: universalinit_env-0.1.6-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.3 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87ad6adcb69e070953fc6a12bc3eb0cd39c67b11d409aee1fcfcd9ae3bc35223
|
|
| MD5 |
7b71056dd9d633ccdd216dc3a7610f58
|
|
| BLAKE2b-256 |
f4f94b9afc57cfe066e8915a7f798b12edba26069545b01801509b75ec0afaed
|