Skip to main content

Python configuration file and command line executable to run a script with

Project description

Python Configuration and a command line Runner

CircleCI codecov Documentation Status image

Python configuration file and command line executable to run a script with.

Why a python file as configuration?

  • Configuration of any complexity
  • No need to serialize the configuration
  • No need other meta-languages for the configuration

Usage

In the code

Configuration file (e.g. config.py):

num_epochs = 100
batch_size = 256

model = resnet18(10)
train_loader = get_train_loader("/path/to/dataset", batch_size=batch_size)
unsup_dataloader = get_train_unsup_loader("/path/to/unsup_dataset", batch_size=batch_size)
...

Script file (e.g. training.py):

from torch.utils.data import DataLoader
from py_config_runner import ConfigObject, TrainvalConfigSchema


class SSLTrainvalConfigSchema(TrainvalConfigSchema):

    unsup_dataloader: DataLoader



def training(config):
    # ...
    print(config.config_filepath)
    print(config.output_path)
    print(config.num_epochs)
    print(config.model)
    print(len(config.train_loader))


def main():

    config_filepath = "/path/to/config.py"
    config = ConfigObject(config_filepath)

    SSLTrainvalConfigSchema.validate(config)

    # Add more things at runtime    
    config.output_path = "/tmp/output"

    training(config)

With launcher

cd /path/to/my/project
py_config_runner scripts/training.py configs/train/baseline.py

or

cd /path/to/my/project
python -u -m py_config_runner scripts/training.py configs/train/baseline.py

or if your specific launcher requires only python script files:

cd /path/to/my/project
python -m special_launcher `py_config_runner_script` scripts/training.py configs/train/baseline.py

The only condition on the script file is it should contain run(config, **kwargs) callable method. Additionally, argument kwargs contains logger (e.g. kwargs['logger']) and local_rank (e.g. kwargs['logger']) for distributed computations.

No restrictions are applied on the configuration file. It is user's responsibility to provide the script file that can consume given configuration file. Provided configuration file is loaded as python module and exposed into the script as the module named config.

Examples

Installation

pip install py-config-runner

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

py_config_runner-0.3.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

py_config_runner-0.3.1-py2.py3-none-any.whl (11.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file py_config_runner-0.3.1.tar.gz.

File metadata

  • Download URL: py_config_runner-0.3.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.61.2 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for py_config_runner-0.3.1.tar.gz
Algorithm Hash digest
SHA256 215dae9514760e3f870fee3e02bec19423130c72911d6693814cab9449b2e710
MD5 330a48b1dcd080790712bacc544bc0b1
BLAKE2b-256 aad6e83fb0e7f0bef384180e721412d7ad29f2b8e094cbabd8a05978f7838af1

See more details on using hashes here.

File details

Details for the file py_config_runner-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: py_config_runner-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.61.2 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for py_config_runner-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d9ccaf7c78274c2497efee04d0360c8cec2bc365666069c5a8eb38d6295fc48
MD5 fc4edd773a145a6555af268270b8257a
BLAKE2b-256 cb3e8d1b2ceba902f67b165ee3bce36633ea5b56c80ddb21d2ef9c9f548dc83d

See more details on using hashes here.

Supported by

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