Env
provide.foundation.serialization.env
¶
TODO: Add module docstring.
Functions¶
env_dumps
¶
Serialize dictionary to .env file format string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
dict[str, str]
|
Dictionary of environment variables |
required |
quote_values
|
bool
|
Whether to quote string values |
True
|
Returns:
| Type | Description |
|---|---|
str
|
.env format string |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If object cannot be serialized |
Example
env_dumps({"KEY": "value"}) 'KEY="value"\n' env_dumps({"KEY": "value"}, quote_values=False) 'KEY=value\n'
Source code in provide/foundation/serialization/env.py
env_loads
¶
Deserialize .env file format string to dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
.env format string to deserialize |
required |
use_cache
|
bool
|
Whether to use caching for this operation |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of environment variables |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If string is not valid .env format |
Example
env_loads('KEY=value') {'KEY': 'value'} env_loads('KEY="value"')