Skip to main content

configen

Automatically generates Structured Configs that can be used with hydra.utils.instantiate()

This is optional at two levels:

  1. Structured Configs are optional, one can use Hydra without them.
  2. One can manually code these dataclasses. The advantage of this tool is that it does the work automatically.

Setup

Configen requires config file per project. The config indicates what classes to generate code for, where to put the generated code etc. Configen will suggest creating a config on the first run:

$ configen 
[2020-08-14 12:06:11,359][configen.configen][ERROR] - Use --config-dir DIR.
If you have no config dir yet use the following command to create an initial config in the `conf` dir:
        configen init_config_dir=conf
$ configen init_config_dir=conf
[2020-08-14 12:07:07,752][configen.configen][INFO] - Initializing config in 'conf'

This will generate a basic config similar to:

$ cat conf/configen.yaml 
configen:
  # output directory
  output_dir: ${hydra:runtime.cwd}/gen

  header: |
    # Generated by configen, do not edit.
    # See https://github.com/facebookresearch/hydra/tree/master/tools/configen

  # The directory of each module under output_dir
  module_dir: '{{module_path}}/conf'

  # list of modules to generate configs for
  modules:
    - name: configen.samples.user
      # for each module, a list of classes
      classes:
        - User

Configen comes with a few samples classes that are being processed by the default config. For example:

class User:
    def __init__(self, age: int, name: str):
        self.age = age
        self.name = name

Running configen with this config directory:

$ configen --config-dir conf
[2020-08-14 12:44:54,990][configen.configen][INFO] - configen.samples.user.User -> /home/omry/tmp/configen/gen/configen/samples/user/conf/User.py

Will result in a file gen/configen/samples/user/conf/User.py like:

# Generated by configen, do not edit.
# See https://github.com/facebookresearch/hydra/tree/master/tools/configen
# fmt: off
# isort:skip_file
# flake8: noqa

from dataclasses import dataclass
from typing import *

from omegaconf import MISSING


@dataclass
class UserConf:
    _target_: str = "configen.samples.user.User"
    age: int = MISSING
    name: str = MISSING

The generated code can be used by a Hydra application to instantiate the user object. See the example aplication.

Metadata

Release files for neoconfigen 2.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neoconfigen 2.5.0
File Size Uploaded
neoconfigen-2.5.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for neoconfigen 2.5.0
File Interpreter ABI Platform
neoconfigen-2.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / neoconfigen-2.5.0.tar.gz

Download URL neoconfigen-2.5.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
90b82bfa8f157279732438cec5f1580d5c034a56e846245ae6fb12b0c0f90dfa
BLAKE2b-256 checksum
How to use checksums
956886eb74fd22ebc4e22bf647656918a7681a8ac71a4c55b84525eda781dd12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.1 CPython/3.11.6 Linux/6.5.0-25-generic

Release files / neoconfigen-2.5.0-py3-none-any.whl

Download URL neoconfigen-2.5.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36d7b87dbfe3405a82fe3a2c3f03d2f016cc04abfed764deb98aa047991f907a
BLAKE2b-256 checksum
How to use checksums
97b4b6e96820f66a747f8c053893a6fcb0e7fb3d3c64a7bb92f6d8fa84c34f46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.1 CPython/3.11.6 Linux/6.5.0-25-generic

Release history Release notifications | RSS feed

This release

2.5.0 This release

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page