Skip to main content

No project description provided

Project description

paramflow

A parameter and configuration management library motivated by training machine learning models and managing configuration for applications that require profiles and layered parameters. paramflow is designed for flexibility and ease of use, enabling seamless parameter merging from multiple sources. It also auto-generates a command-line argument parser and allows for easy parameter overrides.

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. Layer the chosen profile on top of the default profile.
  • Layered meta-parameters: paramflow loads its own configuration using layered approach.
  • Convert types: Convert types during merging using target parameters as a reference for type conversions.
  • Generate argument parser: Use parameters defined in files as a reference for generating argparse parser.

Usage

Install:

pip install paramflow

Install with .env support:

pip install "paramflow[dotenv]"

params.toml

[default]
learning_rate = 0.001
batch_size = 64

app.py

import paramflow as pf
params = pf.load('params.toml')
print(params.learning_rate)
python app.py --help
usage: app.py [-h] [--learning_rate LEARNING_RATE] [--batch_size BATCH_SIZE]

options:
  -h, --help            show this help message and exit
  --learning_rate LEARNING_RATE
                        learning_rate = 0.001
  --batch_size BATCH_SIZE
                        batch_size = 64

Meta-parameter Layering

Meta-parameter layering controls how paramflow.load reads its own configuration.

Layering order:

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

Activate profile using command-line arguments:

python print_params.py --profile dqn-adam

Activate profile using environment variable:

P_PROFILE=dqn-adam python print_params.py

Parameter Layering

Parameter layering merges parameters from multiple sources.

Layering order:

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

Layering order can be customized via source argument to param.flow.

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

Overwrite parameter value:

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

ML hyper-parameters profiles

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 adam profile

python app.py --profile adam

will result in overwriting default learning rate with 1e-4, default optimizer class with torch.optim.Adam and default optimizer arguments with and empty dict.

Development stages profiles

Profiles can be used to manage software development stages. 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"

Activate prod 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.2.1.tar.gz (21.6 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.2.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paramflow-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e622c42e382421ae143d0031d919ee9a3bba3f4b3680fead5312e4e0f2c5bc68
MD5 8187d10095f718258877f2049f4d6ed1
BLAKE2b-256 fe12100523c71c928c4870ccf69ce7209d0218e6fab4b66eb272a914ae7cdaca

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for paramflow-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7aee0e9c389942a5fd81caf64adadafb349642c87a0b95355586327006af20c2
MD5 8487dc58d3080abce430f533f86f2dbf
BLAKE2b-256 e4061ff18a6bfafcef53ead416a401aa7edffdef201f965b59cc6d5616c98878

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