Trackers
toggl_api.TrackerBody
dataclass
¶
Bases: BaseBody
JSON body dataclass for PUT, POST & PATCH requests.
Examples:
>>> TrackerBody(description="What a wonderful tracker description!", project_id=2123132)
TrackerBody(description="What a wonderful tracker description!", project_id=2123132)
METHOD | DESCRIPTION |
---|---|
format |
Format the body for JSON requests. |
format
¶
Format the body for JSON requests.
Gets called by the endpoint methods before requesting.
PARAMETER | DESCRIPTION |
---|---|
endpoint
|
The endpoints name for filtering purposes.
TYPE:
|
body
|
Additional body arguments that the endpoint requires.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
JSON compatible formatted body. |
toggl_api.TrackerEndpoint
¶
Bases: TogglCachedEndpoint[TogglTracker]
Endpoint for modifying and creating trackers.
Examples:
>>> tracker_endpoint = TrackerEndpoint(324525, BasicAuth(...), JSONCache(Path("cache")))
>>> body = TrackerBody(description="What a wonderful tracker description!", project_id=2123132)
>>> tracker_endpoint.add(body)
TogglTracker(id=58687689, name="What a wonderful tracker description!", project=2123132, ...)
>>> tracker_endpoint.delete(tracker)
None
PARAMETER | DESCRIPTION |
---|---|
workspace_id
|
The workspace the Toggl trackers belong to.
TYPE:
|
auth
|
Authentication for the client.
TYPE:
|
cache
|
Where to cache trackers.
TYPE:
|
client
|
Optional client to be passed to be used for requests. Useful when a global client is used and needs to be recycled.
TYPE:
|
timeout
|
How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
TYPE:
|
re_raise
|
Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
TYPE:
|
retries
|
Max retries to attempt if the server returns a 5xx status_code.
Has no effect if re_raise is
TYPE:
|
METHOD | DESCRIPTION |
---|---|
current |
Get current running tracker. Returns None if no tracker is running. |
collect |
Get a set of trackers depending on specified parameters. |
get |
Get a single tracker by ID. |
add |
Add a new tracker. |
edit |
Edit an existing tracker based on the supplied parameters within the body. |
bulk_edit |
Bulk edit multiple trackers at the same time. |
delete |
Delete a tracker from Toggl. |
stop |
Stop the currently running tracker. |
Source code in src/toggl_api/_tracker.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
|
current
¶
current(*, refresh: bool = True) -> TogglTracker | None
Get current running tracker. Returns None if no tracker is running.
Examples:
>>> tracker_endpoint.current()
None
>>> tracker_endpoint.current(refresh=True)
TogglTracker(...)
PARAMETER | DESCRIPTION |
---|---|
refresh
|
Whether to check the remote API for running trackers. If 'refresh' is True it will check if there are any other running trackers and update if the 'stop' attribute is None.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If the request is not a success or any error that's not a '405' status code. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker | None
|
A model from cache or the API. None if nothing is running. |
Source code in src/toggl_api/_tracker.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
collect
¶
collect(
since: int | datetime | None = None,
before: date | None = None,
start_date: date | None = None,
end_date: date | None = None,
*,
refresh: bool = False,
) -> list[TogglTracker]
Get a set of trackers depending on specified parameters.
Missing meta and include_sharing query flags not supported by wrapper at the moment.
Examples:
>>> collect(since=17300032362, before=date(2024, 11, 27))
>>> collect(refresh=True)
>>> collect(start_date=date(2024, 11, 27), end_date=date(2024, 12, 27))
PARAMETER | DESCRIPTION |
---|---|
since
|
Get entries modified since this date using UNIX timestamp. Includes deleted ones if refreshing. |
before
|
Get entries with start time, before given date (YYYY-MM-DD) or with time in RFC3339 format.
TYPE:
|
start_date
|
Get entries with start time, from start_date YYYY-MM-DD or with time in RFC3339 format. To be used with end_date.
TYPE:
|
end_date
|
Get entries with start time, until end_date YYYY-MM-DD or with time in RFC3339 format. To be used with start_date.
TYPE:
|
refresh
|
Whether to refresh the cache or not.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
DateTimeError
|
If the dates are not in the correct ranges. |
HTTPStatusError
|
If the request is not a successful status code. |
RETURNS | DESCRIPTION |
---|---|
list[TogglTracker]
|
List of TogglTracker objects that are within specified parameters. Empty if none is matched. |
Source code in src/toggl_api/_tracker.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
get
¶
get(
tracker_id: int | TogglTracker, *, refresh: bool = False
) -> TogglTracker | None
Get a single tracker by ID.
PARAMETER | DESCRIPTION |
---|---|
tracker_id
|
ID of the tracker to get.
TYPE:
|
refresh
|
Whether to refresh the cache or not.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If anything thats not a ok or 404 status code is returned. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker | None
|
TogglTracker object or None if not found. |
Source code in src/toggl_api/_tracker.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
add
¶
add(body: TrackerBody) -> TogglTracker
Add a new tracker.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> body = TrackerBody(description="Tracker description!", project_id=2123132)
>>> tracker_endpoint.edit(body)
TogglTracker(id=78895400, name="Tracker description!", project=2123132, ...)
PARAMETER | DESCRIPTION |
---|---|
body
|
Body of the request. Description must be set. If start date is not set it will be set to current time with duration set to -1 for a running tracker.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that wasn't an ok status code. |
NamingError
|
Description must be set in order to create a new tracker. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker
|
The tracker that was created. |
Source code in src/toggl_api/_tracker.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
|
edit
¶
edit(
tracker: TogglTracker | int, body: TrackerBody, *, meta: bool = False
) -> TogglTracker
Edit an existing tracker based on the supplied parameters within the body.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> body = TrackerBody(description="What a wonderful tracker description!", project_id=2123132)
>>> tracker_endpoint.edit(58687684, body)
TogglTracker(id=58687684, name="What a wonderful tracker description!", project=2123132, ...)
PARAMETER | DESCRIPTION |
---|---|
tracker
|
Target tracker model or id to edit.
TYPE:
|
body
|
Updated content to add.
TYPE:
|
meta
|
Should the response contain data for meta entities.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything thats not a ok status code. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker
|
A new model if successful else None. |
Source code in src/toggl_api/_tracker.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
|
bulk_edit
¶
bulk_edit(*trackers: int | TogglTracker, body: TrackerBody) -> Edits
Bulk edit multiple trackers at the same time.
Patch will be executed partially when there are errors with some records. No transaction, no rollback.
There is a limit of editing 100 trackers at the same time, so the method will make multiple calls if the count exceeds that limit.
Examples:
>>> body = TrackerBody(description="All these trackers belong to me!")
>>> tracker_endpoint.bulk_edit(1235151, 214124, body)
Edits(successes=[1235151, 214124], failures=[])
PARAMETER | DESCRIPTION |
---|---|
trackers
|
All trackers that need to be edited.
TYPE:
|
body
|
The parameters that need to be edited.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything thats not a ok status code. |
RETURNS | DESCRIPTION |
---|---|
Edits
|
Successeful or failed ids editing the trackers. |
Source code in src/toggl_api/_tracker.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
delete
¶
delete(tracker: TogglTracker | int) -> None
Delete a tracker from Toggl.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> tracker_endpoint.delete(58687684)
None
PARAMETER | DESCRIPTION |
---|---|
tracker
|
Tracker object with ID to delete.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If anything thats not a '404' or 'ok' code is returned. |
Source code in src/toggl_api/_tracker.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
stop
¶
stop(tracker: TogglTracker | int) -> TogglTracker | None
Stop the currently running tracker.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> tracker_endpoint.stop(58687684)
TogglTracker(id=58687684, name="What a wonderful tracker description!", ...)
PARAMETER | DESCRIPTION |
---|---|
tracker
|
Tracker id to stop. An integer or model.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything thats not 'ok' or a '409' status code. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker | None
|
If the tracker was stopped or if the tracker wasn't running it will return None. |
Source code in src/toggl_api/_tracker.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
|
toggl_api.asyncio.AsyncTrackerEndpoint
¶
Bases: TogglAsyncCachedEndpoint[TogglTracker]
Endpoint for modifying and creating trackers.
Examples:
>>> tracker_endpoint = TrackerEndpoint(324525, BasicAuth(...), AsyncSqliteCache(Path("cache")))
>>> body = TrackerBody(description="What a wonderful tracker description!", project_id=2123132)
>>> await tracker_endpoint.add(body)
TogglTracker(id=58687689, name="What a wonderful tracker description!", project=2123132, ...)
>>> await tracker_endpoint.delete(tracker)
None
PARAMETER | DESCRIPTION |
---|---|
workspace_id
|
The workspace the Toggl trackers belong to.
TYPE:
|
auth
|
Authentication for the client.
TYPE:
|
cache
|
Where to cache trackers. Currently async only supports SQLite.
TYPE:
|
client
|
Optional async client to be passed to be used for requests.
TYPE:
|
timeout
|
How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
TYPE:
|
re_raise
|
Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
TYPE:
|
retries
|
Max retries to attempt if the server returns a 5xx status_code.
Has no effect if re_raise is
TYPE:
|
METHOD | DESCRIPTION |
---|---|
current |
Get current running tracker. Returns None if no tracker is running. |
collect |
Get a set of trackers depending on specified parameters. |
get |
Get a single tracker by ID. |
edit |
Edit an existing tracker based on the supplied parameters within the body. |
bulk_edit |
Bulk edit multiple trackers at the same time. |
delete |
Delete a tracker from Toggl. |
stop |
Stop the current running tracker. |
add |
Add a new tracker. |
current
async
¶
current(*, refresh: bool = True) -> TogglTracker | None
Get current running tracker. Returns None if no tracker is running.
Examples:
>>> await tracker_endpoint.current()
None
>>> await tracker_endpoint.current(refresh=True)
TogglTracker(...)
PARAMETER | DESCRIPTION |
---|---|
refresh
|
Whether to check the remote API for running trackers. If 'refresh' is True it will check if there are any other running trackers and update if the 'stop' attribute is None.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If the request is not a success or any error that's not a '405' status code. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker | None
|
A model from cache or the API. None if nothing is running. |
collect
async
¶
collect(
since: int | datetime | None = None,
before: date | None = None,
start_date: date | None = None,
end_date: date | None = None,
*,
refresh: bool = False,
) -> list[TogglTracker]
Get a set of trackers depending on specified parameters.
Missing meta and include_sharing query flags not supported by wrapper at the moment.
Examples:
>>> await tracker_ep.collect(since=17300032362, before=date(2024, 11, 27))
>>> await tracker_ep.collect(refresh=True)
>>> await tracker_ep.collect(start_date=date(2024, 11, 27), end_date=date(2024, 12, 27))
PARAMETER | DESCRIPTION |
---|---|
since
|
Get entries modified since this date using UNIX timestamp. Includes deleted ones if refreshing. |
before
|
Get entries with start time, before given date (YYYY-MM-DD) or with time in RFC3339 format.
TYPE:
|
start_date
|
Get entries with start time, from start_date YYYY-MM-DD or with time in RFC3339 format. To be used with end_date.
TYPE:
|
end_date
|
Get entries with start time, until end_date YYYY-MM-DD or with time in RFC3339 format. To be used with start_date.
TYPE:
|
refresh
|
Whether to refresh the cache or not.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
DateTimeError
|
If the dates are not in the correct ranges. |
HTTPStatusError
|
If the request is not a successful status code. |
RETURNS | DESCRIPTION |
---|---|
list[TogglTracker]
|
List of TogglTracker objects that are within specified parameters. Empty if none is matched. |
get
async
¶
get(
tracker_id: int | TogglTracker, *, refresh: bool = False
) -> TogglTracker | None
Get a single tracker by ID.
PARAMETER | DESCRIPTION |
---|---|
tracker_id
|
ID of the tracker to get.
TYPE:
|
refresh
|
Whether to refresh the cache or not.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If anything thats not a ok or 404 status code is returned. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker | None
|
TogglTracker object or None if not found. |
edit
async
¶
edit(
tracker: TogglTracker | int, body: TrackerBody, *, meta: bool = False
) -> TogglTracker
Edit an existing tracker based on the supplied parameters within the body.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> body = TrackerBody(description="What a wonderful tracker description!", project_id=2123132)
>>> await tracker_endpoint.edit(58687684, body)
TogglTracker(id=58687684, name="What a wonderful tracker description!", project=2123132, ...)
PARAMETER | DESCRIPTION |
---|---|
tracker
|
Target tracker model or id to edit.
TYPE:
|
body
|
Updated content to add.
TYPE:
|
meta
|
Should the response contain data for meta entities.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything thats not a ok status code. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker
|
A new model if successful else None. |
bulk_edit
async
¶
bulk_edit(*trackers: int | TogglTracker, body: TrackerBody) -> Edits
Bulk edit multiple trackers at the same time.
Patch will be executed partially when there are errors with some records. No transaction, no rollback.
There is a limit of editing 100 trackers at the same time, so the method will make multiple calls if the count exceeds that limit.
Examples:
>>> body = TrackerBody(description="All these trackers belong to me!")
>>> await tracker_endpoint.bulk_edit(1235151, 214124, body)
Edits(successes=[1235151, 214124], failures=[])
PARAMETER | DESCRIPTION |
---|---|
trackers
|
All trackers that need to be edited.
TYPE:
|
body
|
The parameters that need to be edited.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything thats not a ok status code. |
RETURNS | DESCRIPTION |
---|---|
Edits
|
Successeful or failed ids editing the trackers. |
delete
async
¶
delete(tracker: TogglTracker | int) -> None
Delete a tracker from Toggl.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> await tracker_endpoint.delete(58687684)
None
PARAMETER | DESCRIPTION |
---|---|
tracker
|
Tracker object with ID to delete.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If anything thats not a '404' or 'ok' code is returned. |
stop
async
¶
stop(tracker: TogglTracker | int) -> TogglTracker | None
Stop the current running tracker.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> await tracker_endpoint.stop(58687684)
TogglTracker(id=58687684, name="What a wonderful tracker description!", ...)
PARAMETER | DESCRIPTION |
---|---|
tracker
|
Tracker id to stop. An integer or model.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything thats not 'ok' or a '409' status code. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker | None
|
If the tracker was stopped or if the tracker wasn't running it will return None. |
add
async
¶
add(body: TrackerBody) -> TogglTracker
Add a new tracker.
This endpoint always hit the external API in order to keep trackers consistent.
Examples:
>>> body = TrackerBody(description="Tracker description!", project_id=2123132)
>>> await tracker_endpoint.edit(body)
TogglTracker(id=78895400, name="Tracker description!", project=2123132, ...)
PARAMETER | DESCRIPTION |
---|---|
body
|
Body of the request. Description must be set. If start date is not set it will be set to current time with duration set to -1 for a running tracker.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that wasn't an ok status code. |
NamingError
|
Description must be set in order to create a new tracker. |
RETURNS | DESCRIPTION |
---|---|
TogglTracker
|
The tracker that was created. |
Types¶
toggl_api.BulkEditParameter
¶
Bases: TypedDict
Source code in src/toggl_api/_tracker.py
35 36 37 38 |
|
toggl_api.Edits
¶
Bases: NamedTuple
Source code in src/toggl_api/_tracker.py
41 42 43 |
|