Skip to main content

toggl-python

https://pypi.python.org/pypi/toggl_python Downloads Supported python versions MIT License

Typed Toggl API Python wrapper with pre-validation to avoid extra network usage.

Important Note

Migration to API V9 is currently in progress. Many methods are not implemented yet. Feel free to open an issue to escalate their development.

Install

pip install toggl-python

Usage

Fetch information about current user via TokenAuth (TOGGL_TOKEN is required):

from toggl_python.auth import TokenAuth
from toggl_python.entities.user import CurrentUser


if __name__ == "__main__":
    auth = TokenAuth(token="TOGGL_TOKEN")
    CurrentUser(auth=auth).me()

Basic Auth is also supported:

from toggl_python.auth import BasicAuth
from toggl_python.entities.user import CurrentUser


if __name__ == "__main__":
    auth = BasicAuth(username="username", password="password")
    CurrentUser(auth=auth).me()

Package supports different input formats for datetime arguments:

  • str:
from toggl_python.auth import TokenAuth
from toggl_python.entities.user import CurrentUser


if __name__ == "__main__":
    auth = TokenAuth(token="TOGGL_TOKEN")
    CurrentUser(auth=auth).get_time_entries(
        start_date="2024-01-01",
        end_date="2024-02-01T15:00:00-02:00",
    )
  • datetime:
from datetime import datetime, timezone

from toggl_python.auth import TokenAuth
from toggl_python.entities.user import CurrentUser


if __name__ == "__main__":
    auth = TokenAuth(token="TOGGL_TOKEN")
    CurrentUser(auth=auth).get_time_entries(
        start_date=datetime(2024, 1, 1, tzinfo=timezone.utc),
        end_date=datetime(2024, 2, 1, 15, tzinfo=timezone.utc),
    )

Query params are available as well:

from toggl_python.auth import TokenAuth
from toggl_python.entities.workspace import Workspace


if __name__ == "__main__":
    auth = TokenAuth(token="TOGGL_TOKEN")
    workspace_id = "WORKSPACE_ID"
    Workspace(auth=auth).get_projects(active=True)

Pre-validation to avoid extra network usage:

from datetime import datetime, timezone

from toggl_python.auth import TokenAuth
from toggl_python.entities.workspace import Workspace


if __name__ == "__main__":
    auth = TokenAuth(token="TOGGL_TOKEN")
    workspace_id = "WORKSPACE_ID"
    since = datetime(2024, 1, 20, tzinfo=timezone.utc)
    # Assume that datetime.now is 2024-05-01
    Workspace(auth=auth).list(since=since)

    # ValidationError: Since cannot be older than 3 months

Development

poetry is required during local setup.

  • Install minimal supported Python version using pyenv - pyenv install 3.8
  • Activate it for current project - pyenv local 3.8
  • Create virtual environment - python -m venv .venv. If Python version is not minimal then IDE suggestions will be incorrect and pre-commit hooks will not be working.

Run poetry install --no-root to setup local environment. pre-commit install is also advisable.

Unit Testing

In order to run tests using different Python versions, please follow these steps:

  • Install pyenv
  • Install all supported Python versions - pyenv install 3.8.* 3.9.* ...
  • Run pyenv local 3.8.* 3.9.* ...
  • Run poetry run nox

To run classic unit tests, execute pytest -m "not integration"

Integration Testing

Pre-defined Workspace and Project are required to have in Toggl system.

Command TOGGL_TOKEN=... WORKSPACE_ID=... PROJECT_ID=... USER_ID=... TOGGL_PASSWORD=... pytest -m integration

Credits

This package follows evrone-python-guidelines and uses configs from evrone-django-template.

Metadata

Release files for toggl_python 0.3.2

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

Source distribution (sdist)

Source distribution for toggl_python 0.3.2
File Size Uploaded
toggl_python-0.3.2.tar.gz 14.9 kB Details

Built distribution (wheel)

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

Total release size: 33.1 kB

Release files / toggl_python-0.3.2.tar.gz

Download URL toggl_python-0.3.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
60cf165614c0376811431c31cb391824fbe7e10efb5689938dbc759828f60b89
BLAKE2b-256 checksum
How to use checksums
38e607f0bd9fd03e82945e6524fe113f5305765e5757cf7d387271ad015888ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.6 Linux/6.10.10-100.fc39.x86_64

Release files / toggl_python-0.3.2-py3-none-any.whl

Download URL toggl_python-0.3.2-py3-none-any.whl
Size 18.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f77cc8b022dc0c3727accb9aa0c1c251add862f7b464c3abbe13c79a7e04a7a2
BLAKE2b-256 checksum
How to use checksums
3982921b53000555a290ce0df21865c8d816ee5e5d7b81b9559709e2467723e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.6 Linux/6.10.10-100.fc39.x86_64

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.7

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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