API Reference¶
chumicro_config¶
chumicro_config
¶
Runtime-config helpers: section loader and on-device reader.
The public entry points are :data:config, :func:load_runtime_config,
:func:load_section, and :func:try_load_section.
ConfigError
¶
Bases: Exception
Base class for every chumicro-config error.
InvalidConfigType
¶
Bases: ConfigError
A config value had the wrong shape, usually not a dict.
MissingConfigKey
¶
Bases: ConfigError
A required config key was not present.
RuntimeConfig
¶
Dict-like lookup over the deployed runtime config.
load_section(target_class, config, *, prefix, required=(), optional=None)
¶
Build target_class from flat config keys sharing a prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_class
|
type
|
Class to build from the collected keyword args. |
required |
config
|
object
|
A :class: |
required |
prefix
|
str
|
Dotted prefix shared by this section's keys. |
required |
required
|
tuple
|
Key names that must be present. |
()
|
optional
|
dict | None
|
Key names mapped to the fallback used when absent. |
None
|
Returns:
| Type | Description |
|---|---|
object
|
An instance of target_class. |
Raises:
| Type | Description |
|---|---|
MissingConfigKey
|
A required key is missing. |
InvalidConfigType
|
config is |
try_load_section(target_class, config, *, prefix, required=(), optional=None)
¶
Like :func:load_section, but return None instead of raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_class
|
type
|
Class to build from the collected keyword args. |
required |
config
|
object
|
A :class: |
required |
prefix
|
str
|
Dotted prefix shared by this section's keys. |
required |
required
|
tuple
|
Key names that must be present. |
()
|
optional
|
dict | None
|
Key names mapped to the fallback used when absent. |
None
|
Returns:
| Type | Description |
|---|---|
object | None
|
An instance of target_class, or |
object | None
|
not configured. |
chumicro_config.runtime¶
The runtime-config reader (load_runtime_config, the lazy config
singleton, and DEFAULT_RUNTIME_CONFIG_PATH) resolves lazily through
the package, so its reference renders from the module itself.
chumicro_config.runtime
¶
On-device reader for /runtime_config.msgpack (flat dotted-key shape).
DEFAULT_RUNTIME_CONFIG_PATH = '/runtime_config.msgpack'
module-attribute
¶
Default on-device location of the runtime config file.
load_runtime_config(path=None)
¶
Read and decode the deployed runtime config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
File to read; defaults to
:data: |
None
|
Returns:
| Type | Description |
|---|---|
RuntimeConfig
|
The decoded config wrapped in a :class: |
Raises:
| Type | Description |
|---|---|
OSError
|
The file is missing or unreadable. |
InvalidConfigType
|
The payload is not valid msgpack or does not decode to a dict. |