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.2.tar.gz (5.9 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.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cliyaml-0.1.2.tar.gz
Algorithm Hash digest
SHA256 19c58cbb250a9cb3ac98c99c6d64c09c0c01c81a440f02bb4145393829b52b8a
MD5 70d1186102b12a1c097227075cf3261c
BLAKE2b-256 6698ac3cd33e6e167bc0e25931c84638f2041eca82b4d18935a8fc8950c1df6f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cliyaml-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c4fb33bf90324cba6dfe67dd419f9ad6817026deebdb18aedd53e4929b755bd
MD5 3bb29e1e93d6067e91f3554c14a7afa3
BLAKE2b-256 dd0ae4f6066857cf5da179f5090fee9e1495007f509bb98dcfd3f74208fc6c7a

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