| name | config-generation |
| description | Generate configuration files. Use for creating YAML, TOML, JSON, or INI config files. |
Config Generation
Generate configuration files in various formats.
Quick Start
import json
import yaml # pip install pyyaml
config = {
"app": {"name": "myapp", "version": "1.0.0"},
"settings": {"debug": False, "port": 8080}
}
# JSON
with open("config.json", "w") as f:
json.dump(config, f, indent=2)
# YAML
with open("config.yaml", "w") as f:
yaml.dump(config, f, default_flow_style=False)
Common Patterns
Generate .gitignore
def generate_gitignore(patterns: list[str]) -> str:
return "\n".join(patterns) + "\n"
gitignore = generate_gitignore([
"*.pyc",
"__pycache__/",
".env",
"venv/",
"dist/",
"*.egg-info/"
])
Generate pyproject.toml
import toml # pip install toml
config = {
"project": {
"name": "myproject",
"version": "0.1.0",
"dependencies": ["requests>=2.28.0"]
},
"tool": {
"pytest": {"testpaths": ["tests"]}
}
}
with open("pyproject.toml", "w") as f:
toml.dump(config, f)
INI config
import configparser
config = configparser.ConfigParser()
config["database"] = {"host": "localhost", "port": "5432"}
config["logging"] = {"level": "INFO"}
with open("config.ini", "w") as f:
config.write(f)
Environment file
def generate_env(variables: dict) -> str:
return "\n".join(f"{k}={v}" for k, v in variables.items())
env_content = generate_env({
"DATABASE_URL": "postgresql://localhost/db",
"SECRET_KEY": "your-secret-key",
"DEBUG": "false"
})