Skip to main content

Prototype projects fast with YAML configuration

Project description

CliYaml

Prototype projects fast with YAML configuration, override it with CLI.

The idea of this package is to make building reusable, copiable, and configurable scripts in a very fast and readable way.

For instance, this is especially useful when iterating on pytorch model designs and training loops, using separate scripts that can easily be modified, copied, while keeping a readable YAML & CLI api for running them with various configurations.

Basically:

  1. Define a typed default config in a subset of YAML (put paths, devices, epochs, learning rates there...)
  2. Define cli subcommands that each refer to a config file using the @subcommand("file.yaml") decorator
  3. Register subcommands, parse cli args and run the correct subcommands using initialize() and handle()

Usage

YAML subset

This packages relies on YAML for configuration due to its readability, however it only parses a subset of it. Here is what it looks like.

config.yaml

# An example configuration

string: "string"
int: 0
float: 0.0

# docstring
docstring: "value"

bool: true

empty: # int

nested:
  one: 1
  two: 2
  • the top comments are the subcommand's description
  • comments before a value are its docstring
  • only true and false are valid booleans
  • type hints can be specified for null values with an inline comment
  • no lists
  • nested values are flattened into a flat python dict, with keys joined by _

CLI API

Define some scripts in separate files, for instance in a scripts/ folder.

scripts/main.py:

from cliyaml import subcommand

# NOTE: multiple different files can be specified to extend the configuration
@subcommand("config.yaml")
def main(**kwargs):
    print("Called with args:", kwargs)

In your main.py, include the following code:

if __name__ == "__main__":
    import cliyaml

    # Registers subcommands
    # NOTE: you can also register single files
    cliyaml.initialize(None, "scripts/")

    # Parses CLI args and runs commands
    cliyaml.handle()

Then, run the following code to use your API:

python main.py -h
python main.py main -h
python main.py main

You can also use cliyaml.call() to call a function by giving it kwargs directly, it will only pass the correct arguments. This function also allows you to pass named and list arguments to override the kwargs.

Building

uv build

Publish

uv publish

Test

pytest

TODO : more comprehensive tests

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

cliyaml-0.1.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cliyaml-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file cliyaml-0.1.1.tar.gz.

File metadata

  • Download URL: cliyaml-0.1.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for cliyaml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 27a082109242d5ad1d7861307382aae0f14af507243e3c7cc17cd2805db367d6
MD5 58dafe7e45b123fb48dd18508443bf49
BLAKE2b-256 2e0ae1505f6b2743fa7fc4327df3e77c9df882a248c6555307cf8b92ce8b1c2f

See more details on using hashes here.

File details

Details for the file cliyaml-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cliyaml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for cliyaml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9e8a78972e9b257fcbc4013b331a4697a423354a24532a81092069eef3c64f5
MD5 ae0fdb558c0cccd9c8fa8f7296ce11c9
BLAKE2b-256 162016b02e9e0181d282e8c96f41d6e441c613a8543e6bb995398b51efa29ba0

See more details on using hashes here.

Supported by

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