All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 Welcome to tasklib's documentation!
2 ===================================
4 tasklib is a Python library for interacting with taskwarrior_ databases, using
5 a queryset API similar to that of Django's ORM.
7 Supports Python 2.6, 2.7, 3.2, 3.3 and 3.4 with taskwarrior 2.1.x and 2.2.x.
8 Older versions of taskwarrior are untested and may not work.
13 * taskwarrior_ v2.1.x or v2.2.x
18 Install via pip (recommended)::
22 Or clone from github::
24 git clone https://github.com/robgolding63/tasklib.git
26 python setup.py install
31 Optionally initialize the ``TaskWarrior`` instance with ``data_location`` (the
32 database directory). If it doesn't already exist, this will be created
33 automatically unless ``create=False``.
35 The default location is the same as taskwarrior's::
37 >>> tw = TaskWarrior(data_location='~/.task', create=True)
42 ``tw.tasks`` is a ``TaskQuerySet`` object which emulates the Django QuerySet
43 API. To get all tasks (including completed ones)::
50 Filter tasks using the same familiar syntax::
52 >>> tw.tasks.filter(status='pending', tags__contain='work')
53 ['Upgrade Ubuntu Server']
55 Filter arguments are passed to the ``task`` command (``__`` is replaced by
56 a period) so the above example is equivalent to the following command::
58 $ task status:pending tags.contain=work
60 Tasks can also be filtered using raw commands, like so::
62 >>> tw.tasks.filter('status:pending +work')
63 ['Upgrade Ubuntu Server']
65 There are built-in functions for retrieving pending & completed tasks::
67 >>> tw.tasks.pending().filter(tags__contain='work')
68 ['Upgrade Ubuntu Server']
69 >>> len(tw.tasks.completed())
72 Use ``get()`` to return the only task in a ``TaskQuerySet``, or raise an
75 >>> tw.tasks.filter(status='pending', tags__contain='work').get()
76 'Upgrade Ubuntu Server'
77 >>> tw.tasks.filter(status='pending', tags__contain='work').get(status='completed')
78 Traceback (most recent call last):
79 File "<stdin>", line 1, in <module>
80 File "tasklib/task.py", line 224, in get
81 'Lookup parameters were {0}'.format(kwargs))
82 tasklib.task.DoesNotExist: Task matching query does not exist. Lookup parameters were {'status': 'completed'}
83 >>> tw.tasks.filter(status='pending', tags__contain='home').get()
84 Traceback (most recent call last):
85 File "<stdin>", line 1, in <module>
86 File "tasklib/task.py", line 227, in get
87 'Lookup parameters were {1}'.format(num, kwargs))
88 ValueError: get() returned more than one Task -- it returned 2! Lookup parameters were {}
93 Attributes of task objects are accessible through indices, like so::
95 >>> task = tw.tasks.pending().filter(tags__contain='work').get()
96 >>> task['description']
97 'Upgrade Ubuntu Server'
101 datetime.datetime(2013, 12, 5, 0, 0)
105 The following fields are deserialized into Python objects:
107 * ``due``: deserialized to a ``datetime`` object
108 * ``annotations``: deserialized to a list of dictionaries, where the ``entry``
109 field is a ``datetime`` object
110 * ``tags``: deserialized to a list
112 Attributes should be set using the correct Python representation, which will be
113 serialized into the correct format when the task is saved.
118 After modifying one or more attributes, simple call ``save()`` to write those
119 changes to the database::
121 >>> task = tw.tasks.pending().filter(tags__contain='work').get()
122 >>> task['due'] = datetime(year=2014, month=1, day=5)
125 To mark a task as complete, use ``done()``::
127 >>> task = tw.tasks.pending().filter(tags__contain='work').get()
129 >>> len(tw.tasks.pending().filter(tags__contain='work'))
132 .. _taskwarrior: http://taskwarrior.org