OneEnv: Environment variable management and generation tool
Project description
OneEnv ๐ใ
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.examplefiles 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.examplefiles - ๐ 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
def database_template():
"""Database configuration template"""
return {
"DATABASE_URL": {
"description": "Database connection URL\nExample: postgresql://user:pass@localhost:5432/db",
"default": "sqlite:///app.db",
"required": True
},
"DB_POOL_SIZE": {
"description": "Database connection pool size",
"default": "10",
"required": False,
"choices": ["5", "10", "20", "50"]
}
}
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 ๐
{
"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
}
}
Real-World Examples ๐
Django + FastAPI + Redis Project
pip install oneenv django-oneenv fastapi-oneenv redis-oneenv
oneenv template
Generated .env.example:
# Auto-generated by OneEnv
# (Defined in: django-oneenv, fastapi-oneenv)
# Django database connection URL
# From fastapi-oneenv: FastAPI database connection
# Required
DATABASE_URL=sqlite:///django.db
# (Defined in: redis-oneenv)
# Redis connection for caching and sessions
REDIS_URL=redis://localhost:6379/0
# (Defined in: django-oneenv)
# Django secret key for security
# Required
SECRET_KEY=your-secret-key-here
Custom Project Templates
# myproject/env_templates.py
from oneenv import oneenv
@oneenv
def custom_project_config():
return {
"PROJECT_NAME": {
"description": "Name of your awesome project",
"default": "My Awesome App",
"required": True
},
"ENVIRONMENT": {
"description": "Deployment environment",
"default": "development",
"choices": ["development", "staging", "production"]
}
}
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.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
๐ Migration from v0.1.x
Your existing @oneenv decorators continue to work without any changes! The new plugin system runs alongside your current setup.
For package developers: Consider adding entry-points to your pyproject.toml for automatic discovery:
[project.entry-points."oneenv.templates"]
myfeature = "mypackage.templates:my_template_function"
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
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 oneenv-0.2.0.tar.gz.
File metadata
- Download URL: oneenv-0.2.0.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
402f3723b8ebd88e4b5cfdac21c20d81749d495ffc8caf992fa74122a30eea4f
|
|
| MD5 |
1d984d6c8c31cb10d8b23070ee0d107b
|
|
| BLAKE2b-256 |
4ae79e6ac5492dff8a1406cdea292184511f1dea266d3762f0d837e52609e285
|
File details
Details for the file oneenv-0.2.0-py3-none-any.whl.
File metadata
- Download URL: oneenv-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47b8fe2361955e3a2f76fb8e29099f6e739442666d42eab6601b2459eeda7b57
|
|
| MD5 |
0779a87aa7ea7a4065b290d3284c5c4a
|
|
| BLAKE2b-256 |
60bf21f7a2903f2459c50a472b87bdb7dd326ca40a2e8cd4e1448e1784502887
|