DEV Community

Cover image for taskwarrior with Python
natamacm
natamacm

Posted on

taskwarrior with Python

Taskwarrior is Free and Open Source Software that manages your TODO listing from the command line. It is flexible, fast, and unobtrusive. It does its job then gets out of your way.

Setup taskw

You can use Taskwarrior from Python using the module taskw. Using taskw requires that you first set up taskwarrior.

Installing it is easy with pip:

$ pip install taskw

That will install the taskw module on your system. If you don't want a system wide installation add --user or setup inside a virtual environment.

Taskwarrior in Python

Using taskwarrior from Python

Looking at tasks

    >>> from taskw import TaskWarrior
    >>> w = TaskWarrior()
    >>> tasks = w.load_tasks()
    >>> tasks.keys()
    ['completed', 'pending']
    >>> type(tasks['pending'])
    <type 'list'>
    >>> type(tasks['pending'][0])
    <type 'dict'>

Adding tasks

    >>> from taskw import TaskWarrior
    >>> w = TaskWarrior()
    >>> w.task_add("Eat food")
    >>> w.task_add("Take a nap", priority="H", project="life", due="1359090000")

Retrieving tasks

    >>> from taskw import TaskWarrior
    >>> w = TaskWarrior()
    >>> w.get_task(id=5)

Updating tasks

    >>> from taskw import TaskWarrior
    >>> w = TaskWarrior()
    >>> id, task = w.get_task(id=14)
    >>> task['project'] = 'Updated project name'
    >>> w.task_update(task)

Deleting tasks

    >>> from taskw import TaskWarrior
    >>> w = TaskWarrior()
    >>> w.task_delete(id=3)

Completing tasks

    >>> from taskw import TaskWarrior
    >>> w = TaskWarrior()
    >>> w.task_done(id=46)

Related links:

Top comments (0)