Skip to main content

Tasker is a way to organize your scripts. If you have dozens of small scripts and you keep forgetting what they do and what parameters they take, tasker is for you. Instead of scripts you write functions, put them in a file or a couple of them, and then run the main tasker script giving them the task name and the parameters of the task like this:

run_task <task-name> [<task-parameter> ...]

The built-in help task will scan your tasks package and give you the call signatures and docstrings of your tasks (see example below).

To be considered a task, the function name should end with _task. The task name is the function name less the suffix. Suppose we have the following file stucture:

run_task
tasks/
    __init__.py
    module1.py

__init__.py

def taskone_task(p1):
    print('in taskone_task, parameters:', p1)

def tasktwo_task(p1, p2):
    print('in tasktwo_task, parameters:', p1, p2)

and module1.py

def t1_task(p1):
    """This is the task's documentation string.

    Continuation of the docstring
    """
    print('in t1_task, parameters:', p1)

def t2_task(p1, p2=None):
    print('in t2_task, parameters:', p1, p2)

To generate the run_task script in the current directory run:

python -m tasker <fully-qualified-name-of-tasks-package>  # default = "tasks"

A run of the script with the built-in help task produces the following:

./run_task help
Usage: run_task <task-name> [parameter, ...]

All available tasks:
    help      # print help screen

    In module tasks
        taskone :  (p1)
        tasktwo :  (p1, p2)

    In module tasks.module1
        module1.t1 :  (p1)
            This is the task's documentation string.
        module1.t2 :  (p1, p2=None)

We see the call signatures of the tasks. If a task function contains a docstring the first line of the docstring will also be included. To print the complete docstring of a task run:

./run_task help <task-name>

IMPORTANT: All task parameters are strings.

With the above setup we can run the following examples in the current directory (which just print the parameters):

./run_task taskone foo          # prints foo
./run_task tasktwo foo baz      # prints foo, baz
./run_task tasktwo foo          # fails, not enough parameters
./run_task module1.t1 spam      # prints spam
./run_task module1.t2 spam ham  # prints spam, ham
./run_task module1.t2 spam      # works too because of default value of the second parameter

You will want to put something meaningful in your tasks.

You can include tasks with distribution of your project and run them all with a single installed script. Suppose your project looks like this:

myproject/
    __init__.py
    somestuff.py
    tasks/

Then you can include the following snippet in __init__.py:

def run_task():
    import tasker
    tasker.main('tasks')

then include the following in your setuptools-based setup.py:

entry_points={
    'console_scripts': [
        'myproject_run_task = myproject:run_task',
        ],
    }

This setup will create script myproject_run_task, which will run your tasks.

Installation

pip install tasker

The current version is Python 3 only. Use version 0.1.2 for Python 2.7.

Release files for tasker 0.3

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

Source distribution (sdist)

Source distribution for tasker 0.3
File Size Uploaded
tasker-0.3.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tasker 0.3
File Interpreter ABI Platform
tasker-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / tasker-0.3.tar.gz

Download URL tasker-0.3.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2acf92909d92b24bf64db124c4801584508869719153878f8c3295d87c059d67
BLAKE2b-256 checksum
How to use checksums
a8f5602309acc9c9bd3b512ec8afd509d8f4927a5f0a2d49f207d7f084e370ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Release files / tasker-0.3-py3-none-any.whl

Download URL tasker-0.3-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d03ea76f9bbbbca4ece3ecd9fbb0f5d42eabdfec1556d49fdc749402eea961da
BLAKE2b-256 checksum
How to use checksums
cf962d847c303e698099c50b43969ea73e7c77cf1b74106e16d9c90177672ea7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

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