Skip to main content

SVG Image

A small, highly opinionated python tool to handle configurations for machine learning pipelines. The library is designed to load configurations from both json and yaml files, as well as from standard python dictionaries.

Design rules

The configurations, once loaded are frozen. Each configuration file can contain only int, float, str, bool and None fields, as well as homogeneous lists of one of the same types. That's all. No nested structures are allowed.

Installation

ML configurations can be installed directly from git by running

pip install ml-confs

Basic usage

A valid ml_confs configuration file configs.yml in YAML is:

int_field: 1
float_field: 1.0
str_field: 'string'
bool_field: true
none_field: null
list_field: [1, 2, 3]

To load it we just use:

import ml_confs

#Loading configs
configs = ml_confs.from_file('configs.yml')

#Accessing configs with dot notation
print(configs.int_field) # >>> 1

#Additionally, one can use the ** notation to unpack the configurations
def foo(**kwargs):
    # Do stuff...
foo(**configs)


#Saving configs to json format
configs.to_file('json_configs_copy.json') #Will create a .json file 

One can also pretty print a loaded configuration with configs.tabulate(), which in the previous example would output:

┏━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Key         ┃ Value     ┃ Type      ┃
┡━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━┩
│ int_field   │ 1         │ int       │
│ float_field │ 1.0       │ float     │
│ str_field   │ string    │ str       │
│ bool_field  │ True      │ bool      │
│ none_field  │ None      │ NoneType  │
│ list_field  │ [1, 2, 3] │ list[int] │
└─────────────┴───────────┴───────────┘

JAX Pytree registration

By default, ml_confs will try to register the configuration object as a JAX pytree, so that configs can be safely used with JAX transformations.

import ml_confs
import jax

configs = mlc.from_dict({'exp': 1.5})

@jax.jit 
def power_fn(x, cfg):
    return x**cfg.exp

assert f(2.0, configs) == 2.0**exp # This works!
assert jax.grad(power_fn)(3.0, configs) == 3.0**(exp - 1.0) * exp # This works too!

If JAX is not installed the following warning will be displayed:

Unable to import JAX. The argument register_jax_pytree will be ignored. To suppress this warning, load the configurations with register_jax_pytree=False.

If one is not interested in this feature, the warning can be silenced by explicitly setting register_jax_pytree to False upon configuration loading.

API Reference

function ml_confs.from_json

from_json(path: os.PathLike, register_jax_pytree: bool = True)

Load configurations from a JSON file.

Args:

  • path (os.PathLike): Configuration file path.
  • register_jax_pytree (bool, optional): Register the configuration as a JAX pytree. This allows the configurations to be safely used in JAX's transformations.. Defaults to False.

Returns:

  • Configs: Instance of the loaded configurations.

function ml_confs.from_yaml

from_yaml(path: os.PathLike, register_jax_pytree: bool = True)

Load configurations from a YAML file.

Args:

  • path (os.PathLike): Configuration file path.
  • register_jax_pytree (bool, optional): Register the configuration as a JAX pytree. This allows the configurations to be safely used in JAX's transformations.. Defaults to False.

Returns:

  • Configs: Instance of the loaded configurations.

function ml_confs.from_dict

from_dict(storage: dict, register_jax_pytree: bool = True)

Load configurations from a python dictionary.

Args:

  • storage (dict): Configuration dictionary.
  • register_jax_pytree (bool, optional): Register the configuration as a JAX pytree. This allows the configurations to be safely used in JAX's transformations.. Defaults to False.

Returns:

  • Configs: Instance of the loaded configurations.

function ml_confs.from_file

from_file(path: os.PathLike, register_jax_pytree: bool = True)

Load configurations from a YAML/JSON file.

Args:

  • path (os.PathLike): Configuration file path.
  • register_jax_pytree (bool, optional): Register the configuration as a JAX pytree. This allows the configurations to be safely used in JAX's transformations.. Defaults to False.

Returns:

  • Configs: Instance of the loaded configurations.

class Configs


method Configs.tabulate

tabulate()

Print the configurations in a tabular format.


method Configs.to_dict

to_dict() → dict

Export configurations to a python dictionary.

Returns:

  • dict: A standard python dictionary containing the configurations.

method Configs.to_file

to_file(path: os.PathLike)

Save configurations to a YAML/JSON file.

Args:

  • path (os.PathLike): File path to save the configurations.

method Configs.to_json

to_json(path: os.PathLike)

Save configurations to a JSON file.

Args:

  • path (os.PathLike): File path to save the configurations.

method Configs.to_yaml

to_yaml(path: os.PathLike)

Save configurations to a YAML file.

Args:

  • path (os.PathLike): File path to save the configurations.

The API reference was automatically generated via lazydocs.

Metadata

Release files for ml-confs 0.0.4

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

Source distribution (sdist)

Source distribution for ml-confs 0.0.4
File Size Uploaded Provenance Actions
ml_confs-0.0.4.tar.gz 11.5 kB Without provenance Details for ml_confs-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ml-confs 0.0.4
File Interpreter ABI Platform Actions
ml_confs-0.0.4-py3-none-any.whl Python 3 none any Details for ml_confs-0.0.4-py3-none-any.whl

Total release size: 18.3 kB

Release files / ml_confs-0.0.4.tar.gz

Download URL ml_confs-0.0.4.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
59eb401c660426495b8b179c8c76063982a6bbdb06c81f3d94a6ef69db5f3539
BLAKE2b-256 checksum
How to use checksums
11cb48bd8dcec98f83090d9688d7e70d490c6355c04c81056aea7d0946cc1090
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / ml_confs-0.0.4-py3-none-any.whl

Download URL ml_confs-0.0.4-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4bd60351fed1d32ccc61d8badef15a6f83d9a5f37cf22ca7ddb0ad82b8a2d3d
BLAKE2b-256 checksum
How to use checksums
676d49c7077388bf80b1f26c1d12abc11dbc001240068e8a5aa21e63caa81146
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for ml-confs 0.0.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

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