Skip to main content

Facilitates the use of Python from the command line

Project description

jobtools

This package contains a convenient implementation to work with Python from a command line to execute jobs of any kind. Jobs are indicated using a callable function that the TaskRunner can executed. Arguments for the callable are automatically parsed from the command line and enforced depending on if they are required of not. Type conversion is automatically handled. Special type conversion is supported for aruments of type SimpleNamespace which can be passed as arguments using YML or JSON files.

Usage

task.py

import jobtools
from types import SimpleNamespace

def mytask(name: str, max_buffer: int, params: SimpleNamespace, optional_arg: int = 10) -> int:
    """
    This is the function you want to run
    """
    ...
    text = f'Paramters are automatically parse so I can use {name}. Since params \
             is a `SimpleNamespace` argument, then the `YML` file structure will \
             be mapped. I can use {params.trips.origin} and {params.trips.destiny} \
             including {params.budget}.'
    ...

    return ...

if __name__ == "__main__":
    tr = jobtools.runner.TaskRunner()
    result = tr.run(mytask)

Then this file can be called as:

python task.py --name "my name" --max-buffer 1024 --params params.yml

or

python task.py --name "my name" --max-buffer 1024 --params params.yml --optional-arg 15

The corresponding YML file would be like:

params.yml

trips:
    origin: 'BUE'
    destinty: 'SFO'
budget: 700

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

jobtools-0.0.2.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

jobtools-0.0.2-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

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