Skip to main content

Automagically generate yaml schemas for your Hydra config files

Project description

hydra-auto-schema

codecov

This tool greatly improves the experience of developing a project with Hydra by enabling rich IDE support for Hydra config files.

📢 If you are thinking of using Hydra for a PyTorch or Jax-based ML project, you might want to take a look at the Research Project Template where this plugin was originally created. This is also where this plugin is best integrated!

With this, you'll now get to see:

  • the list of available configuration options in a given config
  • the default values for each entry
  • the documentation associated with each entry (taken from the source code of the _target_ callable!) Additionally
  • A warning is displayed when a value is unexpected, or of the wrong type.

All-in-all, this helps to prevent errors, and gives your codebase the same kind of neatness and safety that type hints do.

Demo

https://github.com/user-attachments/assets/08f52d47-ebba-456d-95ef-ac9525d8e983

Installation

Requirements

At the moment, we assume that you are using VSCode as your code editor. We use the yaml extension by RedHat, and install it for you if it isn't already. However any IDE with a YAML language server should be fairly easy to make work. Please make an issue if this doesn't work with your IDE.

uv (recommended)

uv add git+https://www.github.com/lebrice/hydra-auto-schema

Note: This plugin needs to be installed in your project's virtual environment. It should not be installed as an isolated tool using uv tool. This is because the plugin needs to import the modules where the _target_s are defined in order to inspect their signature.

pip

pip install git+https://www.github.com/lebrice/hydra-auto-schema

Usage (CLI)

Generate the yaml schemas for all the configs in the configs folder:

hydra-auto-schema configs

Watch for changes in the configs folder and update the schemas as needed:

hydra-auto-schema configs --watch

Usage (Hydra)

This package includes a Hydra plugin. By default, it will try to update all the schema files in your project's config directory when Hydra's main function is called.

You don't really need to call anything for this to happen! Just keep using Hydra like you used to, and hopefully your config files will just feel much better to use! 😁

To configure how the auto schema plugin is called by Hydra, you can add the following block somwehere before your main Hydra function:

from hydra_plugins.auto_schema import auto_schema_plugin

auto_schema_plugin.config = auto_schema_plugin.AutoSchemaPluginConfig(
    schemas_dir=... # Path where you want the schema files to be saved. Defaults to ".schemas",
    regen_schemas=False,  # Whether to regenerate schemas even if the config did not change.
    stop_on_error=False,
    quiet=True,
    add_headers=False,  # controls whether to add headers, use vscode settings, or either.
)

How to Contribute

This is a very new tool, and we'd love to get your feedback! Please feel free to make an Issue if you have any questions or feedback. We'll be happy to assist you.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hydra_auto_schema-0.0.3.tar.gz (51.6 kB view details)

Uploaded Source

Built Distribution

hydra_auto_schema-0.0.3-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file hydra_auto_schema-0.0.3.tar.gz.

File metadata

  • Download URL: hydra_auto_schema-0.0.3.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for hydra_auto_schema-0.0.3.tar.gz
Algorithm Hash digest
SHA256 32918b6026a9e2eb0d7b4226a12b0a28f7346168551b2553e09aab650f77ae02
MD5 b0c424561c89886b161e154eef83be41
BLAKE2b-256 820b0fb5615fc7b6f1313fbb25a1b6a9402d07291876c0c0a41ca7ba02709a27

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydra_auto_schema-0.0.3.tar.gz:

Publisher: publish.yaml on lebrice/hydra-auto-schema

Attestations:

File details

Details for the file hydra_auto_schema-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for hydra_auto_schema-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 86db1ae2ad260e41081ecc89397014a878eeee0bc06a7b8df2cb916ac6f794ea
MD5 7641a8df84918075727e8c0573e48abe
BLAKE2b-256 39bcf67466ab7ec7f5b78331222973cd74b2f90fe4c6a83d348b3035bda51462

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydra_auto_schema-0.0.3-py3-none-any.whl:

Publisher: publish.yaml on lebrice/hydra-auto-schema

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page