|
1 |
| -Toggl Python API |
2 |
| -================ |
| 1 | +toggl-python |
| 2 | +============ |
3 | 3 |
|
4 |
| -.. image:: https://evrone.com/logo/evrone-sponsored-logo.png |
5 |
| - :width: 231 |
6 |
| - :alt: Sponsored by evrone.com |
7 |
| - :target: https://evrone.com/?utm_source=github.com |
| 4 | +|https://pypi.python.org/pypi/toggl_python| |Supported python versions| |
| 5 | +|MIT License| |
8 | 6 |
|
9 |
| -Based on open `Toggl API documentation <https://github.com/toggl/toggl_api_docs/blob/master/toggl_api.md>`_ |
| 7 | +Typed python wrapper for ``Toggl API`` with pre-validation to avoid |
| 8 | +extra network usage. |
10 | 9 |
|
11 |
| -Installation |
12 |
| -============ |
13 |
| -`pip install toggl-python` or use `poetry <https://python-poetry.org>`_ `poetry add toggl-python` |
| 10 | +- Based on `Toggl API <https://engineering.toggl.com/docs/>`__ |
| 11 | +- `Documentation <https://toggl-python.readthedocs.io>`__ |
| 12 | + |
| 13 | +Important Note |
| 14 | +-------------- |
| 15 | + |
| 16 | +Migration to API V9 is currently in progress. Many methods are not |
| 17 | +implemented yet. Feel free to open an issue to escalate their |
| 18 | +implementation. |
| 19 | + |
| 20 | +Install |
| 21 | +------- |
| 22 | + |
| 23 | +``pip install toggl-python`` |
| 24 | + |
| 25 | +Usage |
| 26 | +----- |
| 27 | + |
| 28 | +Fetch information about current user via ``TokenAuth`` (``TOGGL_TOKEN`` |
| 29 | +is required): |
| 30 | + |
| 31 | +.. code:: python |
| 32 | +
|
| 33 | + from toggl_python.auth import TokenAuth |
| 34 | + from toggl_python.entities.user import CurrentUser |
| 35 | +
|
| 36 | +
|
| 37 | + if __name__ == "__main__": |
| 38 | + auth = TokenAuth(token="TOGGL_TOKEN") |
| 39 | + CurrentUser(auth=auth).me() |
| 40 | +
|
| 41 | +``Basic Auth`` is also supported. |
| 42 | + |
| 43 | +.. code:: python |
| 44 | +
|
| 45 | + from toggl_python.auth import BasicAuth |
| 46 | + from toggl_python.entities.user import CurrentUser |
| 47 | +
|
| 48 | +
|
| 49 | + if __name__ == "__main__": |
| 50 | + auth = BasicAuth(username="username", password="password") |
| 51 | + CurrentUser(auth=auth).me() |
| 52 | +
|
| 53 | +Package supports different input formats for ``datetime`` arguments: |
| 54 | + |
| 55 | +- ``str``: |
| 56 | + |
| 57 | +.. code:: python |
| 58 | +
|
| 59 | + from toggl_python.auth import TokenAuth |
| 60 | + from toggl_python.entities.user import CurrentUser |
| 61 | +
|
| 62 | +
|
| 63 | + if __name__ == "__main__": |
| 64 | + auth = TokenAuth(token="TOGGL_TOKEN") |
| 65 | + CurrentUser(auth=auth).get_time_entries( |
| 66 | + start_date="2024-01-01", |
| 67 | + end_date="2024-02-01T15:00:00-02:00", |
| 68 | + ) |
| 69 | +
|
| 70 | +- ``datetime``: |
| 71 | + |
| 72 | +.. code:: python |
| 73 | +
|
| 74 | + from datetime import datetime, timezone |
| 75 | +
|
| 76 | + from toggl_python.auth import TokenAuth |
| 77 | + from toggl_python.entities.user import CurrentUser |
| 78 | +
|
| 79 | +
|
| 80 | + if __name__ == "__main__": |
| 81 | + auth = TokenAuth(token="TOGGL_TOKEN") |
| 82 | + CurrentUser(auth=auth).get_time_entries( |
| 83 | + start_date=datetime(2024, 1, 1, tzinfo=timezone.utc), |
| 84 | + end_date=datetime(2024, 2, 1, 15, tzinfo=timezone.utc), |
| 85 | + ) |
| 86 | +
|
| 87 | +Query params are available as well: |
| 88 | + |
| 89 | +.. code:: python |
| 90 | +
|
| 91 | + from toggl_python.auth import TokenAuth |
| 92 | + from toggl_python.entities.workspace import Workspace |
| 93 | +
|
| 94 | +
|
| 95 | + if __name__ == "__main__": |
| 96 | + auth = TokenAuth(token="TOGGL_TOKEN") |
| 97 | + workspace_id = "WORKSPACE_ID" |
| 98 | + Workspace(auth=auth).get_projects(active=True) |
| 99 | +
|
| 100 | +Pre-validation to avoid extra network usage: |
| 101 | + |
| 102 | +.. code:: python |
| 103 | +
|
| 104 | + from datetime import datetime, timezone |
| 105 | +
|
| 106 | + from toggl_python.auth import TokenAuth |
| 107 | + from toggl_python.entities.workspace import Workspace |
| 108 | +
|
| 109 | +
|
| 110 | + if __name__ == "__main__": |
| 111 | + auth = TokenAuth(token="TOGGL_TOKEN") |
| 112 | + workspace_id = "WORKSPACE_ID" |
| 113 | + since = datetime(2024, 1, 20, tzinfo=timezone.utc) |
| 114 | + # Assume that datetime.now is 2024-05-01 |
| 115 | + Workspace(auth=auth).list(since=since) |
| 116 | +
|
| 117 | + # ValidationError: Since cannot be older than 3 months |
14 | 118 |
|
15 |
| -Usage example |
16 |
| -============= |
| 119 | +Development |
| 120 | +----------- |
17 | 121 |
|
18 |
| -Get authenticated user time entries: |
| 122 | +``poetry`` is required during local setup. |
19 | 123 |
|
20 |
| -.. code-block:: python |
| 124 | +Run ``poetry install --no-root`` to setup local environment. |
| 125 | +``pre-commit install`` is also advisable. |
21 | 126 |
|
22 |
| - from toggl_python import TokenAuth, TimeEntries |
| 127 | +Unit Testing |
| 128 | +~~~~~~~~~~~~ |
23 | 129 |
|
24 |
| - if __name__ == "__main__": |
25 |
| - auth = TokenAuth('AUTH_TOKEN') |
26 |
| - print(TimeEntries(auth=auth).list()) |
| 130 | +In order to run tests using different Python versions, please follow |
| 131 | +these steps: \* Install ``pyenv`` \* Install all supported Python |
| 132 | +versions - ``pyenv install 3.8.* 3.9.* ...`` \* Run |
| 133 | +``pyenv local 3.8.* 3.9.* ...`` \* Run ``poetry run nox`` |
27 | 134 |
|
28 |
| -Get information about authenticated user: |
| 135 | +To run classic unit tests, execute ``pytest -m "not integration"`` |
29 | 136 |
|
30 |
| -.. code-block:: python |
| 137 | +Integration Testing |
| 138 | +~~~~~~~~~~~~~~~~~~~ |
31 | 139 |
|
32 |
| - from toggl_python import TokenAuth, Users |
| 140 | +Pre-defined ``Workspace`` and ``Project`` are required to have in |
| 141 | +``Toggl`` system. |
33 | 142 |
|
34 |
| - if __name__ == "__main__": |
35 |
| - auth = TokenAuth('AUTH_TOKEN') |
36 |
| - print(Users(auth=auth).me()) |
| 143 | +Command |
| 144 | +``TOGGL_TOKEN=... WORKSPACE_ID=... PROJECT_ID=... USER_ID=... TOGGL_PASSWORD=... pytest -m integration`` |
37 | 145 |
|
38 |
| -Get information about authenticated user workspaces: |
| 146 | +Credits |
| 147 | +------- |
39 | 148 |
|
40 |
| -.. code-block:: python |
| 149 | +This package follows |
| 150 | +`evrone-python-guidelines <https://github.com/evrone/evrone-python-guidelines>`__ |
| 151 | +and uses configs from |
| 152 | +`evrone-django-template <https://github.com/evrone/evrone-django-template>`__. |
41 | 153 |
|
42 |
| - from toggl_python import TokenAuth, Workspaces |
| 154 | +` <https://evrone.com/?utm_source=github.com>`__ |
43 | 155 |
|
44 |
| - if __name__ == "__main__": |
45 |
| - auth = TokenAuth('AUTH_TOKEN') |
46 |
| - print(Workspaces(auth=auth).list()) |
| 156 | +.. |https://pypi.python.org/pypi/toggl_python| image:: https://img.shields.io/pypi/v/toggl_python.svg |
| 157 | +.. |Supported python versions| image:: https://img.shields.io/pypi/pyversions/toggl_python.svg?style=flat-square |
| 158 | + :target: https://pypi.python.org/pypi/toggl_python |
| 159 | +.. |MIT License| image:: https://img.shields.io/pypi/l/aiogram.svg?style=flat-square |
| 160 | + :target: https://opensource.org/licenses/MIT |
0 commit comments