Typed `Toggl API` Python wrapper with pre-validation to avoid extra network usage.
Project description
toggl-python
Typed Toggl API
Python wrapper with pre-validation to avoid extra network usage.
- Based on Toggl API
- Documentation
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.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file toggl_python-0.3.1.tar.gz
.
File metadata
- Download URL: toggl_python-0.3.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.10.10-100.fc39.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43983eed3f61633f5e8729bb4c82589b58a8cb0cfb3be2538f93a9419d07d4ed |
|
MD5 | 11a1c9fdc6b151c91018fd3cb2a7e00d |
|
BLAKE2b-256 | 575e3a2822dafcdd5d0449b68494120198d32cee92aa41992f498b721aa73917 |
File details
Details for the file toggl_python-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: toggl_python-0.3.1-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.10.10-100.fc39.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc5de7afbd73bc8600c17bb0327d23ae706d88d66ea636e9967197729eaf3d24 |
|
MD5 | 0cc7d49db86698ce5ae6864b2da037a3 |
|
BLAKE2b-256 | b4ea8f2acd71af620bf6914dedd5b011cc6521a06ea99cb3d1ff327b77b20102 |