Projects
toggl_api.ProjectBody
dataclass
¶
Bases: BaseBody
JSON body dataclass for PUT, POST & PATCH requests.
Source code in 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 |
|
name: Optional[str] = field(default=None)
class-attribute
instance-attribute
¶
Name of the project. Defaults to None. Will be required if its a POST request.
active: bool | Literal['both'] = field(default='both')
class-attribute
instance-attribute
¶
Whether the project is archived or active. The literal 'both' is used for querying.
is_private: Optional[bool] = field(default=True, metadata={'endpoints': frozenset(('edit', 'add'))})
class-attribute
instance-attribute
¶
Whether the project is private or not. Defaults to True.
client_name: Optional[str] = field(default=None, metadata={'endpoints': frozenset(('edit', 'add'))})
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: Optional[str] = field(default=None, metadata={'endpoints': frozenset(('edit', 'add'))})
class-attribute
instance-attribute
¶
Color of the project. Refer to BASIC_COLORS for accepted colors for non-premium users.
start_date: Optional[date] = field(default=None, metadata={'endpoints': frozenset(('edit', 'add'))})
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: Optional[date] = field(default=None, metadata={'endpoints': frozenset(('edit', 'add'))})
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: Optional[date | int] = field(default=None, metadata={'endpoints': frozenset(('collect'))})
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: list[int] = field(default_factory=list, metadata={'endpoints': frozenset(('collect'))})
class-attribute
instance-attribute
¶
Query for specific projects with assocciated users. API only.
client_ids: list[int] = field(default_factory=list, metadata={'endpoints': frozenset(('collect'))})
class-attribute
instance-attribute
¶
Query for specific projects with assocciated clients.
group_ids: list[int] = field(default_factory=list, metadata={'endpoints': frozenset(('collect'))})
class-attribute
instance-attribute
¶
Query for specific projects with assocciated groups. API only
statuses: list[TogglProject.Status] = field(default_factory=list, metadata={'endpoints': frozenset(('collect'))})
class-attribute
instance-attribute
¶
Query for specific statuses when using the collect endpoint. Deleted status only works with the remote API.
format(endpoint: str, **body: Any) -> dict[str, Any]
¶
Formats the body for JSON requests.
Gets called by the endpoint methods before requesting.
Parameters:
-
endpoint
(str
) –Name of the endpoint for filtering purposes.
-
body
(Any
, default:{}
) –Additional arguments for the body.
Returns:
-
dict[str, Any]
–dict[str, Any]: JSON compatible formatted body.
Source code in 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 |
|
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
Parameters:
-
workspace_id
(int | TogglWorkspace
) –The workspace the projects belong to.
-
auth
(BasicAuth
) –Basic authentication with an api token or username/password combo.
-
cache
(TogglCache[TogglProject]
) –Cache to push the projects to.
-
timeout
(int
, default:10
) –How long it takes for the client to timeout. Keyword Only. Defaults to 10 seconds.
-
re_raise
(bool
, default:False
) –Whether to raise all HTTPStatusError errors and not handle them internally. Keyword Only.
-
retries
(int
, default:3
) –Max retries to attempt if the server returns a 5xx status_code. Has no effect if re_raise is
True
. Keyword Only.
Attributes:
-
BASIC_COLORS
(Final[dict[str, str]]
) –Default colors that are available for non-premium users.
Source code in toggl_api/project.py
167 168 169 170 171 172 173 174 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 |
|
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'}
class-attribute
instance-attribute
¶
Basic colors available for projects in order of the API index.
collect(body: Optional[ProjectBody] = None, *, refresh: bool = False, sort_pinned: bool = False, only_me: bool = False, only_templates: bool = False) -> list[TogglProject]
¶
Returns all cached or remote projects.
Parameters:
-
body
(Optional[ProjectBody]
, default:None
) –Optional body for adding query parameters for filtering projects.
-
refresh
(bool
, default:False
) –Whether to fetch from the remote API if true else using the local cache.
-
sort_pinned
(bool
, default:False
) –Whether to put pinned projects ontop of the results. Only works with the remote API at the moment.
-
only_me
(bool
, default:False
) –Only retrieve projects that are assigned to the current user assocciated with the authentication. API specific.
-
only_templates
(bool
, default:False
) –Retrieve template projects. API specific.
Raises:
-
HTTPStatusError
–If any response that is not '200' code is returned.
-
NotImplementedError
–Deleted or Active status are used with a 'False' refresh argument.
Returns:
-
list[TogglProject]
–A list of projects or an empty list if None are found.
Source code in toggl_api/project.py
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 |
|
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", ...)
Parameters:
-
project_id
(int | TogglProject
) –TogglProject to retrieve. Either a model with the correct id or integer.
-
refresh
(bool
, default:False
) –Whether to check cache or not.
Raises:
-
HTTPStatusError
–If any status code that is not '200' or a '404' is returned.
Returns:
-
TogglProject | None
–A project model or None if nothing was found.
Source code in toggl_api/project.py
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 |
|
delete(project: TogglProject | int) -> None
¶
Deletes 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
Parameters:
-
project
(TogglProject | int
) –TogglProject to delete. Either an existing model or the integer id.
Raises:
-
HTTPStatusError
–For anything that's not a '200' or '404' status code.
Source code in toggl_api/project.py
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 |
|
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, ...)
Parameters:
-
project
(TogglProject | int
) –The existing project to edit. Either the model or the integer id.
-
body
(ProjectBody
) –The body with the edited attributes.
Raises:
-
HTTPStatusError
–For anything that's not a 'ok' status code.
Returns:
-
TogglProject
–The project model with the provided modifications.
Source code in toggl_api/project.py
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 |
|
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, ...)
Parameters:
-
body
(ProjectBody
) –The body with the new attributes of the project.
Raises:
-
HTTPStatusError
–For anything that's not a 'ok' status code.
Returns:
-
TogglProject
–The newly created project.
Source code in toggl_api/project.py
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 |
|
get_color(name: str) -> str
classmethod
¶
Get a color by name. Defaults to gray.
Source code in toggl_api/project.py
476 477 478 479 480 |
|
get_color_id(color: str) -> int
classmethod
¶
Get a color id by name.
Parameters:
-
color
(str
) –Name of the desired color.
Raises:
-
IndexError
–If the color name is not a standard color.
Returns:
-
int
–Index of the provided color name.
Source code in toggl_api/project.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
|
status_to_query(status: TogglProject.Status) -> list[TogglQuery]
staticmethod
¶
Creates a list of queries depending on the desired project status.
Parameters:
-
status
(Status
) –What is the status you are querying for?
Raises:
-
NotImplementedError
–Active & Deleted Statuses are currently not supported for local querying.
Returns:
-
list[TogglQuery]
–A list of query parameters for the desired status.
Source code in toggl_api/project.py
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 |
|