Projects
toggl_api.ProjectBody
dataclass
¶
Bases: BaseBody
JSON body dataclass for PUT, POST & PATCH requests.
METHOD | DESCRIPTION |
---|---|
format |
Format the body for JSON requests. |
ATTRIBUTE | DESCRIPTION |
---|---|
name |
Name of the project. Defaults to None. Will be required if its a POST request.
TYPE:
|
active |
Whether the project is archived or active. |
is_private |
Whether the project is private or not. Defaults to True.
TYPE:
|
client_name |
Client name if client_id is not set. Defaults to None. If client_id is
TYPE:
|
color |
Color of the project. Refer to BASIC_COLORS
TYPE:
|
start_date |
Date to set the start of a project. If not set or start date is after
TYPE:
|
end_date |
Date to set the end of the project. If not set or start date is after
TYPE:
|
since |
Timestamp for querying for projects with the 'collect' endpoint. |
user_ids |
Query for specific projects with assocciated users. API only. |
client_ids |
Query for specific projects with assocciated clients. |
group_ids |
Query for specific projects with assocciated groups. API only |
statuses |
Query for specific statuses when using the collect endpoint. |
Source code in src/toggl_api/_project.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
name
class-attribute
instance-attribute
¶
Name of the project. Defaults to None. Will be required if its a POST request.
active
class-attribute
instance-attribute
¶
Whether the project is archived or active. The literal 'both' is used for querying.
is_private
class-attribute
instance-attribute
¶
Whether the project is private or not. Defaults to True.
client_name
class-attribute
instance-attribute
¶
Client name if client_id is not set. Defaults to None. If client_id is set the client_name will be ignored.
color
class-attribute
instance-attribute
¶
Color of the project. Refer to BASIC_COLORS for accepted colors for non-premium users.
start_date
class-attribute
instance-attribute
¶
Date to set the start of a project. If not set or start date is after the end date the end date will be ignored.
end_date
class-attribute
instance-attribute
¶
Date to set the end of the project. If not set or start date is after the end date the end date will be ignored.
since
class-attribute
instance-attribute
¶
Timestamp for querying for projects with the 'collect' endpoint. Retrieve projects created/modified/deleted since this date using UNIX timestamp. If using local cache deleted projects are not present.
user_ids
class-attribute
instance-attribute
¶
user_ids: list[int] = field(
default_factory=list, metadata={"endpoints": frozenset(("collect",))}
)
Query for specific projects with assocciated users. API only.
client_ids
class-attribute
instance-attribute
¶
client_ids: list[int] = field(
default_factory=list, metadata={"endpoints": frozenset(("collect",))}
)
Query for specific projects with assocciated clients.
group_ids
class-attribute
instance-attribute
¶
group_ids: list[int] = field(
default_factory=list, metadata={"endpoints": frozenset(("collect",))}
)
Query for specific projects with assocciated groups. API only
statuses
class-attribute
instance-attribute
¶
statuses: list[Status] = field(
default_factory=list, metadata={"endpoints": frozenset(("collect",))}
)
Query for specific statuses when using the collect endpoint. Deleted status only works with the remote API.
format
¶
Format the body for JSON requests.
Gets called by the endpoint methods before requesting.
PARAMETER | DESCRIPTION |
---|---|
endpoint
|
Name of the endpoint for filtering purposes.
TYPE:
|
body
|
Additional arguments for the body.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
dict[str, Any]: JSON compatible formatted body. |
Source code in src/toggl_api/_project.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
toggl_api.ProjectEndpoint
¶
Bases: TogglCachedEndpoint[TogglProject]
Specific endpoints for retrieving and modifying projects.
Examples:
>>> from toggl_api.utility import get_authentication, retrieve_workspace_id
>>> from toggl_api import JSONCache
>>> project_endpoint = ProjectEndpoint(retrieve_workspace_id(), get_authentication(), JSONCache(...))
>>> project_endpoint.get(213141424)
TogglProject(213141424, "Amaryllis", ...)
>>> project_endpoint.delete(213141424)
None
PARAMETER | DESCRIPTION |
---|---|
workspace_id
|
The workspace the projects belong to.
TYPE:
|
auth
|
Basic authentication with an api token or username/password combo.
TYPE:
|
cache
|
Cache to push the projects to.
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:
|
ATTRIBUTE | DESCRIPTION |
---|---|
BASIC_COLORS |
Default colors that are available for non-premium users. |
METHOD | DESCRIPTION |
---|---|
collect |
Return all cached or remote projects. |
get |
Request a project based on its id. |
delete |
Delete a project based on its id. |
edit |
Edit a project based on its id with the parameters provided in the body. |
add |
Create a new project based on the parameters provided in the body. |
get_color |
Get a color by name. Defaults to gray. |
get_color_id |
Get a color id by name. |
status_to_query |
Create a list of queries depending on the desired project status. |
Source code in src/toggl_api/_project.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 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 |
|
BASIC_COLORS
class-attribute
instance-attribute
¶
BASIC_COLORS: Final[dict[str, str]] = {
"blue": "#0b83d9",
"violet": "#9e5bd9",
"pink": "#d94182",
"orange": "#e36a00",
"gold": "#bf7000",
"green": "#2da608",
"teal": "#06a893",
"beige": "#c9806b",
"dark-blue": "#465bb3",
"purple": "#990099",
"yellow": "#c7af14",
"dark-green": "#566614",
"red": "#d92b2b",
"gray": "#525266",
}
Basic colors available for projects in order of the API index.
collect
¶
collect(
body: ProjectBody | None = None,
*,
refresh: bool = False,
sort_pinned: bool = False,
only_me: bool = False,
only_templates: bool = False,
) -> list[TogglProject]
Return all cached or remote projects.
PARAMETER | DESCRIPTION |
---|---|
body
|
Optional body for adding query parameters for filtering projects.
TYPE:
|
refresh
|
Whether to fetch from the remote API if true else using the local cache.
TYPE:
|
sort_pinned
|
Whether to put pinned projects ontop of the results. Only works with the remote API at the moment.
TYPE:
|
only_me
|
Only retrieve projects that are assigned to the current user assocciated with the authentication. API specific.
TYPE:
|
only_templates
|
Retrieve template projects. API specific.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If any response that is not '200' code is returned. |
NotImplementedError
|
Deleted or Active status are used with a 'False' refresh argument. |
RETURNS | DESCRIPTION |
---|---|
list[TogglProject]
|
A list of projects or an empty list if None are found. |
Source code in src/toggl_api/_project.py
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 |
|
get
¶
get(
project_id: int | TogglProject, *, refresh: bool = False
) -> TogglProject | None
Request a project based on its id.
Examples:
>>> project_endpoint.get(213141424)
TogglProject(213141424, "Amaryllis", ...)
PARAMETER | DESCRIPTION |
---|---|
project_id
|
TogglProject to retrieve. Either a model with the correct id or integer.
TYPE:
|
refresh
|
Whether to check cache or not.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If any status code that is not '200' or a '404' is returned. |
RETURNS | DESCRIPTION |
---|---|
TogglProject | None
|
A project model or None if nothing was found. |
Source code in src/toggl_api/_project.py
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 |
|
delete
¶
delete(project: TogglProject | int) -> None
Delete a project based on its id.
This endpoint always hits the external API in order to keep projects consistent.
Examples:
>>> project_endpoint.delete(213141424)
None
PARAMETER | DESCRIPTION |
---|---|
project
|
TogglProject to delete. Either an existing model or the integer id.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that's not a '200' or '404' status code. |
Source code in src/toggl_api/_project.py
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 |
|
edit
¶
edit(project: TogglProject | int, body: ProjectBody) -> TogglProject
Edit a project based on its id with the parameters provided in the body.
This endpoint always hit the external API in order to keep projects consistent.
Examples:
>>> body = ProjectBody(name="Amaryllis")
>>> project_endpoint.add(213141424, body)
TogglProject(213141424, "Amaryllis", client=87695895, ...)
PARAMETER | DESCRIPTION |
---|---|
project
|
The existing project to edit. Either the model or the integer id.
TYPE:
|
body
|
The body with the edited attributes.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that's not a 'ok' status code. |
RETURNS | DESCRIPTION |
---|---|
TogglProject
|
The project model with the provided modifications. |
Source code in src/toggl_api/_project.py
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 |
|
add
¶
add(body: ProjectBody) -> TogglProject
Create a new project based on the parameters provided in the body.
This endpoint always hit the external API in order to keep projects consistent.
Examples:
>>> body = ProjectBody(name="Zinnia", client_id=87695895)
>>> project_endpoint.add(body)
TogglProject(213141424, "Zinnia", client=87695895, ...)
PARAMETER | DESCRIPTION |
---|---|
body
|
The body with the new attributes of the project.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that's not a 'ok' status code. |
NamingError
|
If the new project name is invalid. |
RETURNS | DESCRIPTION |
---|---|
TogglProject
|
The newly created project. |
Source code in src/toggl_api/_project.py
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 |
|
get_color
classmethod
¶
Get a color by name. Defaults to gray.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the color.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Color in a hexcode. |
Source code in src/toggl_api/_project.py
515 516 517 518 519 520 521 522 523 524 525 |
|
get_color_id
classmethod
¶
Get a color id by name.
PARAMETER | DESCRIPTION |
---|---|
color
|
Name of the desired color.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
IndexError
|
If the color name is not a standard color. |
RETURNS | DESCRIPTION |
---|---|
int
|
Index of the provided color name. |
Source code in src/toggl_api/_project.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
status_to_query
staticmethod
¶
status_to_query(status: Status) -> list[TogglQuery[Any]]
Create a list of queries depending on the desired project status.
PARAMETER | DESCRIPTION |
---|---|
status
|
What is the status you are querying for?
TYPE:
|
RAISES | DESCRIPTION |
---|---|
NotImplementedError
|
Active & Deleted Statuses are currently not supported for local querying. |
RETURNS | DESCRIPTION |
---|---|
list[TogglQuery[Any]]
|
A list of query parameters for the desired status. |
Source code in src/toggl_api/_project.py
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 |
|
toggl_api.asyncio.AsyncProjectEndpoint
¶
Bases: TogglAsyncCachedEndpoint[TogglProject]
Specific endpoints for retrieving and modifying projects.
Examples:
>>> from toggl_api.utility import get_authentication, retrieve_workspace_id
>>> from toggl_api.asyncio import AsyncSqliteCache, ProjectEndpoint
>>> project_endpoint = ProjectEndpoint(retrieve_workspace_id(), get_authentication(), AsyncSqliteCache(...))
>>> await project_endpoint.get(213141424)
TogglProject(213141424, "Amaryllis", ...)
>>> await project_endpoint.delete(213141424)
None
PARAMETER | DESCRIPTION |
---|---|
workspace_id
|
The workspace the projects belong to.
TYPE:
|
auth
|
Basic authentication with an api token or username/password combo.
TYPE:
|
cache
|
Cache to push the projects to.
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:
|
ATTRIBUTE | DESCRIPTION |
---|---|
BASIC_COLORS |
Default colors that are available for non-premium users. |
METHOD | DESCRIPTION |
---|---|
status_to_query |
Create a list of queries depending on the desired project status. |
collect |
Return all cached or remote projects. |
get |
Request a project based on its id. |
delete |
Delete a project based on its id. |
edit |
Edit a project based on its id with the parameters provided in the body. |
add |
Create a new project based on the parameters provided in the body. |
get_color |
Get a color by name. Defaults to gray. |
get_color_id |
Get a color id by name. |
BASIC_COLORS
class-attribute
instance-attribute
¶
BASIC_COLORS: Final[dict[str, str]] = {
"blue": "#0b83d9",
"violet": "#9e5bd9",
"pink": "#d94182",
"orange": "#e36a00",
"gold": "#bf7000",
"green": "#2da608",
"teal": "#06a893",
"beige": "#c9806b",
"dark-blue": "#465bb3",
"purple": "#990099",
"yellow": "#c7af14",
"dark-green": "#566614",
"red": "#d92b2b",
"gray": "#525266",
}
Basic colors available for projects in order of the API index.
status_to_query
staticmethod
¶
Create a list of queries depending on the desired project status.
PARAMETER | DESCRIPTION |
---|---|
status
|
What is the status you are querying for?
TYPE:
|
statement
|
Base statement to add filters onto. |
RAISES | DESCRIPTION |
---|---|
NotImplementedError
|
Active & Deleted Statuses are currently not supported for local querying. |
RETURNS | DESCRIPTION |
---|---|
Select[Any]
|
A list of query parameters for the desired status. |
collect
async
¶
collect(
body: ProjectBody | None = None,
*,
refresh: bool = False,
sort_pinned: bool = False,
only_me: bool = False,
only_templates: bool = False,
) -> list[TogglProject]
Return all cached or remote projects.
PARAMETER | DESCRIPTION |
---|---|
body
|
Optional body for adding query parameters for filtering projects.
TYPE:
|
refresh
|
Whether to fetch from the remote API if true else using the local cache.
TYPE:
|
sort_pinned
|
Whether to put pinned projects ontop of the results. Only works with the remote API at the moment.
TYPE:
|
only_me
|
Only retrieve projects that are assigned to the current user assocciated with the authentication. API specific.
TYPE:
|
only_templates
|
Retrieve template projects. API specific.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If any response that is not '200' code is returned. |
NotImplementedError
|
Deleted or Active status are used with a 'False' refresh argument. |
RETURNS | DESCRIPTION |
---|---|
list[TogglProject]
|
A list of projects or an empty list if None are found. |
get
async
¶
get(
project_id: int | TogglProject, *, refresh: bool = False
) -> TogglProject | None
Request a project based on its id.
Examples:
>>> await project_endpoint.get(213141424)
TogglProject(213141424, "Amaryllis", ...)
PARAMETER | DESCRIPTION |
---|---|
project_id
|
TogglProject to retrieve. Either a model with the correct id or integer.
TYPE:
|
refresh
|
Whether to check cache or not.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
If any status code that is not '200' or a '404' is returned. |
RETURNS | DESCRIPTION |
---|---|
TogglProject | None
|
A project model or None if nothing was found. |
delete
async
¶
delete(project: TogglProject | int) -> None
Delete a project based on its id.
This endpoint always hits the external API in order to keep projects consistent.
Examples:
>>> project_endpoint.delete(213141424)
None
PARAMETER | DESCRIPTION |
---|---|
project
|
TogglProject to delete. Either an existing model or the integer id.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that's not a '200' or '404' status code. |
edit
async
¶
edit(project: TogglProject | int, body: ProjectBody) -> TogglProject
Edit a project based on its id with the parameters provided in the body.
This endpoint always hit the external API in order to keep projects consistent.
Examples:
>>> body = ProjectBody(name="Amaryllis")
>>> project_endpoint.add(213141424, body)
TogglProject(213141424, "Amaryllis", client=87695895, ...)
PARAMETER | DESCRIPTION |
---|---|
project
|
The existing project to edit. Either the model or the integer id.
TYPE:
|
body
|
The body with the edited attributes.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that's not a 'ok' status code. |
RETURNS | DESCRIPTION |
---|---|
TogglProject
|
The project model with the provided modifications. |
add
async
¶
add(body: ProjectBody) -> TogglProject
Create a new project based on the parameters provided in the body.
This endpoint always hit the external API in order to keep projects consistent.
Examples:
>>> body = ProjectBody(name="Zinnia", client_id=87695895)
>>> project_endpoint.add(body)
TogglProject(213141424, "Zinnia", client=87695895, ...)
PARAMETER | DESCRIPTION |
---|---|
body
|
The body with the new attributes of the project.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPStatusError
|
For anything that's not a 'ok' status code. |
NamingError
|
If the project name is invalid. |
RETURNS | DESCRIPTION |
---|---|
TogglProject
|
The newly created project. |