Skip to main content

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

Metadata

Release files for py-config-runner 0.3.2

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

Source distribution (sdist)

Source distribution for py-config-runner 0.3.2
File Size Uploaded Provenance Actions
py_config_runner-0.3.2.tar.gz 11.2 kB Without provenance Details for py_config_runner-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-config-runner 0.3.2
File Interpreter ABI Platform Actions
py_config_runner-0.3.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for py_config_runner-0.3.2-py2.py3-none-any.whl

Total release size: 23.1 kB

Release files / py_config_runner-0.3.2.tar.gz

Download URL py_config_runner-0.3.2.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6ecae136abdd974896632b768326758c743c92bcf24a582fb23be5a7c9a02972
BLAKE2b-256 checksum
How to use checksums
788e6c8a2114c1ad3e5208bbf5df5503faa82c21a0035f9a2b94e6c0edc4efed
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / py_config_runner-0.3.2-py2.py3-none-any.whl

Download URL py_config_runner-0.3.2-py2.py3-none-any.whl
Size 11.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
079e03db6115f2a6c87a2f5531d1af0248eca2e5a6baf69c48b449de2b8cb8db
BLAKE2b-256 checksum
How to use checksums
97b377d5f6c12a7aaeb27f198227f57fb2a33127dfcf1f01b219a0128846cae1
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for py-config-runner 0.3.2

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