Skip to main content

A lightweight library for hyperparameter and configuration management

Project description

paramflow

ParamFlow is a lightweight and versatile library for managing hyperparameters and configurations, tailored for machine learning projects and applications requiring layered parameter handling. It merges parameters from multiple sources, generates command-line argument parsers, and simplifies parameter overrides, providing a seamless and efficient experience.

Features

  • Layered configuration: Merge parameters from files, environment variables, and command-line arguments.
  • Immutable dictionary: Provides a read-only dictionary with attribute-style access.
  • Profile support: Manage multiple sets of parameters with profile-based layering.
  • Layered meta-parameters: paramflow configures itself using a layered approach.
  • Automatic type conversion: Converts types during merging based on target parameter types.
  • Command-line argument parsing: Automatically generates an argparse parser from parameter definitions.
  • Nested Configuration: Allows for nested configuration and merging.

Installation

pip install paramflow

Install with .env support:

pip install "paramflow[dotenv]"

Basic Usage

Example Configuration File (params.toml)

[default]
learning_rate = 0.001
batch_size = 64

Loading Parameters in Python (app.py)

import paramflow as pf

params = pf.load('params.toml')
print(params.learning_rate)  # 0.001

Generating Command-line Help

Running the script with --help displays both meta-parameters and parameters:

python app.py --help

Meta-Parameter Layering

Meta-parameters control how paramflow.load reads its own configuration. Layering order:

  1. paramflow.load arguments
  2. Environment variables (default prefix: P_)
  3. Command-line arguments (argparse)

Activating Profiles

Via command-line:

python print_params.py --profile dqn-adam

Via environment variable:

P_PROFILE=dqn-adam python print_params.py

Parameter Layering

Parameters are merged from multiple sources in the following order:

  1. Configuration files (.toml, .yaml, .ini, .json, .env)
  2. Environment variables (default prefix: P_)
  3. Command-line arguments (argparse)

Customizing Layering Order

You can specify the order explicitly (env and args are reserved names):

params = pf.load('params.toml', 'env', '.env', 'args')

Overriding Parameters

Override parameters via command-line arguments:

python print_params.py --profile dqn-adam --learning_rate 0.0002

Managing ML Hyperparameter Profiles

Example Configuration (params.toml)

[default]
learning_rate = 0.00025
batch_size = 32
optimizer_class = 'torch.optim.RMSprop'
optimizer_kwargs = { momentum = 0.95 }
random_seed = 13

[adam]
learning_rate = 1e-4
optimizer_class = 'torch.optim.Adam'
optimizer_kwargs = {}

Activating a Profile

python app.py --profile adam

This overrides:

  • learning_rate1e-4
  • optimizer_classtorch.optim.Adam
  • optimizer_kwargs{}

Managing Development Stages

Profiles can be used to manage configurations for different environments.

Example Configuration (params.toml)

[default]
debug = true
database_url = "mysql://localhost:3306/myapp"

[dev]
database_url = "mysql://dev:3306/myapp"

[prod]
debug = false
database_url = "mysql://prod:3306/myapp"

Activating a Profile

export P_PROFILE=dev
python app.py

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

paramflow-0.5.4.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

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

paramflow-0.5.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file paramflow-0.5.4.tar.gz.

File metadata

  • Download URL: paramflow-0.5.4.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for paramflow-0.5.4.tar.gz
Algorithm Hash digest
SHA256 f25e620205edb4f96f0bea8d474f7c8fe1731a3b6d3e7c4af895f64cab1090e7
MD5 fb1ee1e686cf2ba584e84240a9b8bdbf
BLAKE2b-256 5e2749ecc58eed2415ab0509fb169dd92645e5be2983847b8f8ab363702ce28e

See more details on using hashes here.

File details

Details for the file paramflow-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: paramflow-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for paramflow-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 62d10bf10cc8e818db2f195b6523b5893a3f79222aee83b8bd25ca602adc2f40
MD5 fe41e89316dc04ccb3cb2a6e09a2e334
BLAKE2b-256 81ea0826918596c63e28deab9dcf7e1387c2d1d5bf245144f4636dd4a21f506e

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