ccproxy.config.env_generator¶
ccproxy.config.env_generator
¶
Utility functions for generating environment variable configuration from Pydantic models.
is_hidden_in_example
¶
Determine if a field should be omitted from generated example configs.
Source code in ccproxy/config/env_generator.py
get_field_description
¶
Get a human-readable description from a Pydantic field.
format_value_for_env
¶
Format a configuration value for environment variable output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
String representation suitable for environment variables |
Source code in ccproxy/config/env_generator.py
generate_env_vars_from_model
¶
Generate environment variable names and values from a Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
type[T]
|
The Pydantic model class to generate env vars from |
required |
prefix
|
str
|
Prefix for env var names (e.g., "SERVER" or "PLUGINS__MAX_TOKENS") |
''
|
include_hidden
|
bool
|
Whether to include fields marked as hidden in examples |
False
|
Returns:
| Type | Description |
|---|---|
list[tuple[str, Any, str]]
|
List of tuples: (env_var_name, value, description) |
Source code in ccproxy/config/env_generator.py
generate_env_config
¶
generate_env_config(
model_class,
prefix="",
include_hidden=False,
commented=True,
header_comment=None,
export_format=True,
)
Generate environment variable configuration string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
type[BaseModel]
|
The Pydantic model class to generate config from |
required |
prefix
|
str
|
Prefix for env var names (e.g., "SERVER" or "PLUGINS__MAX_TOKENS") |
''
|
include_hidden
|
bool
|
Whether to include fields marked as hidden in examples |
False
|
commented
|
bool
|
Whether to comment out all settings (default True) |
True
|
header_comment
|
str | None
|
Optional custom header comment |
None
|
export_format
|
bool
|
Whether to use 'export VAR=value' format (True) or 'VAR=value' (False) |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Environment variable configuration as a string |
Source code in ccproxy/config/env_generator.py
write_env_config
¶
write_env_config(
output,
model_class,
prefix="",
include_hidden=False,
commented=True,
header_comment=None,
export_format=True,
)
Write environment variable configuration directly to a stream or file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
TextIO | Path | str
|
Output destination - can be a TextIO stream (file, StringIO, stdout), a Path object, or a string path to a file |
required |
model_class
|
type[BaseModel]
|
The Pydantic model class to generate config from |
required |
prefix
|
str
|
Prefix for env var names (e.g., "SERVER" or "PLUGINS__MAX_TOKENS") |
''
|
include_hidden
|
bool
|
Whether to include fields marked as hidden in examples |
False
|
commented
|
bool
|
Whether to comment out all settings (default True) |
True
|
header_comment
|
str | None
|
Optional custom header comment |
None
|
export_format
|
bool
|
Whether to use 'export VAR=value' format (default True) |
True
|
Examples:
Write to stdout¶
write_env_config(sys.stdout, Settings)
Write to file¶
write_env_config("env.sh", Settings) write_env_config(Path("env.sh"), Settings)
Write to StringIO¶
buffer = StringIO() write_env_config(buffer, Settings) content = buffer.getvalue()
Write with prefix for plugin¶
write_env_config(sys.stdout, MaxTokensConfig, prefix="PLUGINS__MAX_TOKENS")
Write without export (for .env files)¶
write_env_config("env.sh", Settings, export_format=False)