megaconf
megaconf is a tool to help with producing configs. This tool allows you to describe configuration combinations declaratively, instead of writing nested loops in code.
How it works
megaconf generates configurations from two inputs:
- Base config – a starting configuration.
- Override config – rules describing how to modify the base config to produce multiple variants.
The result is a set of generated configs.
Example
Suppose we start with a base config:
algo: NN
lr: 0.001
layer_count: 8
activation: ReLU
initializer: He
We want to run experiments across different algorithms and hyperparameters.
This might look like:
for algo in ["XGBoost", "NN"]:
for lr in [0.1, 0.01, 0.001]:
if algo == "NN":
for layer_count in [4, 8, 12, 16]:
for activation in ["ReLU", "Tanh"]:
...
As the number of parameters and dependencies grows, this approach becomes hard to maintain.
megaconf allows expressing the same logic using override rules.
Override Config:
- fixed:
algo: XGBoost
product:
lr: [0.1, 0.01, 0.001]
- fixed:
algo: NN
joint:
activation: [ReLU, Tanh]
initializer: [He, Glorot]
product:
lr: [0.1, 0.01, 0.001]
layer_count: [4, 8, 12, 16]
Override Methods
megaconf supports three override methods.
fixed
Sets specific values in the config.
fixed:
algo: NN
Equivalent to:
config["algo"] = "NN"
If the key does not exist in the base config, it is added.
joint
Iterates over multiple parameters together.
All lists must be the same length.
joint:
activation: [ReLU, Tanh]
initializer: [He, Glorot]
Result:
activation=ReLU initializer=He
activation=Tanh initializer=Glorot
This is useful for paired parameters.
product
Produces the cartesian product of parameter values.
product:
lr: [0.1, 0.01, 0.001]
layer_count: [4, 8, 12]
This generates:
lr=0.1 layer_count=4
lr=0.1 layer_count=8
lr=0.1 layer_count=12
lr=0.01 layer_count=4
...
This is equivalent to a grid search.
How Overrides Are Combined
Within an override block:
- fixed values are applied first.
- joint combinations are generated.
- product combinations are generated.
The final configs are the combination of these rules applied to the base config.
Interface
Create configurations with generate_configs. It accepts a base config and an
overrides config.
Both inputs can be provided in two ways:
- as a Python object (e.g., a dictionary or list).
- as a path to a configuration file (.yaml, .yml, or .json).
generate_configs returns an iterator that yields each generated config. The
number of generated configs depends on the combinations produced by the override
rules. Use generate_configs_list if you need all generated configs in a list.
Example usage:
from megaconf import generate_configs
base_config = {
"algo": "NN",
"lr": 0.001,
"layer_count": 8,
"activation": "ReLU",
"initializer": "He"
}
overrides = [
{
"fixed": {
"algo": "XGBoost"
},
"product": {
"lr": [0.1, 0.01, 0.001]
}
},
{
"fixed": {
"algo": "NN"
},
"joint": {
"activation": ["ReLU", "Tanh"],
"initializer": ["He", "Glorot"]
},
"product": {
"lr": [0.1, 0.01],
"layer_count": [4, 8]
}
}
]
configs = generate_configs(base_config, overrides)
Or if the base and overrides separate config files:
configs = generate_configs(
"base_config.yaml",
"overrides.yaml"
)
Nesting
If a key is deeply nested in the config, a dot-key separator is used by default. This means that specifying a nested key is done as follows:
fixed:
key1.key2.key3: value
However, if a dot conflicts with your key strings, you can specify a custom key separator as follows:
configs = generate_configs(
"base_config.yaml",
"overrides.yaml",
key_separator="::"
)
Metadata
Release files for megaconf 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| megaconf-0.1.0.tar.gz | 6.1 kB | With provenance | Details for megaconf-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| megaconf-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for megaconf-0.1.0-py3-none-any.whl |
Total release size: 14.4 kB
Release files / megaconf-0.1.0.tar.gz
| Download URL | megaconf-0.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62de741cc8ad3f3d510fef8f2ae8eb630bf6082ba22fbc83b401e55c899a6bf3
|
|
BLAKE2b-256 checksum How to use checksums |
587dbae8f95e609688510b72c8cc7efc90baa168eb091a81d001ef765ae672aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency logRelease files / megaconf-0.1.0-py3-none-any.whl
| Download URL | megaconf-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54a6b98b8104804b82de3e98d206eb49bc325f428fd14dafe97bdcef420dbaae
|
|
BLAKE2b-256 checksum How to use checksums |
cae5e02418394d446470f4cc8a7a64d637b9676bb475bb3ee1f1619efbaf73ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency logSecurity for megaconf 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for megaconf-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.