wg_utilities.clients
Useful clients for commonly accessed APIs/services.
GoogleCalendarClient
Bases: GoogleClient[GoogleCalendarEntityJson]
Custom client specifically for Google's Calendar API.
Source code in wg_utilities/clients/google_calendar.py
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 |
|
calendar_list: list[Calendar]
property
List of calendars.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Calendar]
|
a list of Calendar instances that the user has access to |
primary_calendar: Calendar
property
Primary calendar for the user.
Returns:
Name | Type | Description |
---|---|---|
Calendar |
Calendar
|
the current user's primary calendar |
create_event(summary, start_datetime, end_datetime, tz=None, calendar=None, extra_params=None)
Create an event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
summary |
str
|
the summary (title) of the event |
required |
start_datetime |
Union[datetime, date]
|
when the event starts |
required |
end_datetime |
Union[datetime, date]
|
when the event ends |
required |
tz |
str
|
the timezone which the event is in (IANA database name) |
None
|
calendar |
Calendar
|
the calendar to add the event to |
None
|
extra_params |
dict
|
any extra params to pass in the request |
None
|
Returns:
Name | Type | Description |
---|---|---|
Event |
Event
|
a new event instance, fresh out of the oven |
Raises:
Type | Description |
---|---|
TypeError
|
if the start/end datetime params are not the correct type |
Source code in wg_utilities/clients/google_calendar.py
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 |
|
delete_event_by_id(event_id, calendar=None)
Delete an event from a calendar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
str
|
the ID of the event to delete |
required |
calendar |
Calendar
|
the calendar being updated |
None
|
Source code in wg_utilities/clients/google_calendar.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
|
get_event_by_id(event_id, *, calendar=None)
Get a specific event by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
str
|
the ID of the event to delete |
required |
calendar |
Calendar
|
the calendar being updated |
None
|
Returns:
Name | Type | Description |
---|---|---|
Event |
Event
|
an Event instance with all relevant attributes |
Source code in wg_utilities/clients/google_calendar.py
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 |
|
GoogleDriveClient
Bases: GoogleClient[JSONObj]
Custom client specifically for Google's Drive API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scopes |
list
|
a list of scopes the client can be given |
None
|
creds_cache_path |
str
|
file path for where to cache credentials |
None
|
Source code in wg_utilities/clients/google_drive.py
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 |
|
GoogleFitClient
Bases: GoogleClient[Any]
Custom client for interacting with the Google Fit API.
See Also
GoogleClient: the base Google client, used for authentication and common functions
Source code in wg_utilities/clients/google_fit.py
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 |
|
data_sources: dict[str, DataSource]
property
Data sources available to this client.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, DataSource]
|
a dict of data sources, keyed by their UID |
get_data_source(data_source_id)
Get a data source based on its UID.
DataSource instances are cached for the lifetime of the GoogleClient instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source_id |
str
|
the UID of the data source |
required |
Returns:
Name | Type | Description |
---|---|---|
DataSource |
DataSource
|
an instance, ready to use! |
Source code in wg_utilities/clients/google_fit.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
GooglePhotosClient
Bases: GoogleClient[GooglePhotosEntityJson]
Custom client for interacting with the Google Photos API.
See Also
GoogleClient: the base Google client, used for authentication and common functions
Source code in wg_utilities/clients/google_photos.py
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 |
|
albums: list[Album]
property
List all albums in the active Google account.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Album]
|
a list of Album instances |
get_album_by_id(album_id)
Get an album by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
album_id |
str
|
the ID of the album to fetch |
required |
Returns:
Name | Type | Description |
---|---|---|
Album |
Album
|
the album with the given ID |
Source code in wg_utilities/clients/google_photos.py
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 |
|
get_album_by_name(album_name)
Get an album definition from the Google API based on the album name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
album_name |
str
|
the name of the album to find |
required |
Returns:
Name | Type | Description |
---|---|---|
Album |
Album
|
an Album instance, with all metadata etc. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
if the client can't find an album with the correct name |
Source code in wg_utilities/clients/google_photos.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
ItemMetadataRetrieval
Bases: StrEnum
The type of metadata retrieval to use for items.
Attributes:
Name | Type | Description |
---|---|---|
ON_DEMAND |
str
|
only retrieves single metadata items on demand. Best for reducing memory usage but makes most HTTP requests. |
ON_FIRST_REQUEST |
str
|
retrieves all metadata items on the first request for any metadata value. Nice middle ground between memory usage and HTTP requests. |
ON_INIT |
str
|
retrieves metadata on instance initialisation. Increases memory
usage, makes the fewest HTTP requests. If combined with a |
Source code in wg_utilities/clients/google_drive.py
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 |
|
JsonApiClient
Bases: Generic[GetJsonResponse]
Generic no-auth JSON API client to simplify interactions.
Sort of an SDK?
Source code in wg_utilities/clients/json_api_client.py
22 23 24 25 26 27 28 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 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 |
|
request_headers: dict[str, str]
property
Header to be used in requests to the API.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str]
|
auth headers for HTTP requests |
get_json_response(url, /, *, params=None, header_overrides=None, timeout=None, json=None, data=None)
Get a simple JSON object from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
the API endpoint to GET |
required |
params |
dict
|
the parameters to be passed in the HTTP request |
None
|
header_overrides |
dict
|
headers to add to/overwrite the headers in
|
None
|
timeout |
float
|
How many seconds to wait for the server to send data before giving up |
None
|
json |
dict
|
a JSON payload to pass in the request |
None
|
data |
dict
|
a data payload to pass in the request |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
GetJsonResponse
|
the JSON from the response |
Source code in wg_utilities/clients/json_api_client.py
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 |
|
post_json_response(url, /, *, params=None, header_overrides=None, timeout=None, json=None, data=None)
Get a simple JSON object from a URL from a POST request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
the API endpoint to GET |
required |
params |
dict
|
the parameters to be passed in the HTTP request |
None
|
header_overrides |
dict
|
headers to add to/overwrite the headers in
|
None
|
timeout |
float
|
How many seconds to wait for the server to send data before giving up |
None
|
json |
dict
|
a JSON payload to pass in the request |
None
|
data |
dict
|
a data payload to pass in the request |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
GetJsonResponse
|
the JSON from the response |
Source code in wg_utilities/clients/json_api_client.py
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 |
|
MonzoClient
Bases: OAuthClient[MonzoGJR]
Custom client for interacting with Monzo's API.
Source code in wg_utilities/clients/monzo.py
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 |
|
current_account: Account
property
Get the main account for the Monzo user.
We assume there'll only be one main account per user.
Returns:
Name | Type | Description |
---|---|---|
Account |
Account
|
the user's main account, instantiated |
request_headers: dict[str, str]
property
Header to be used in requests to the API.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str]
|
auth headers for HTTP requests |
deposit_into_pot(pot, amount_pence, dedupe_id=None)
Move money from the user's account into one of their pots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pot |
Pot
|
the target pot |
required |
amount_pence |
int
|
the amount of money to deposit, in pence |
required |
dedupe_id |
str
|
unique string used to de-duplicate deposits. Will be created if not provided |
None
|
Source code in wg_utilities/clients/monzo.py
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 |
|
get_pot_by_id(pot_id)
Get a pot from its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pot_id |
str
|
the ID of the pot to find |
required |
Returns:
Name | Type | Description |
---|---|---|
Pot |
Pot | None
|
the Pot instance |
Source code in wg_utilities/clients/monzo.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
get_pot_by_name(pot_name, *, exact_match=False, include_deleted=False)
Get a pot from its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pot_name |
str
|
the name of the pot to find |
required |
exact_match |
bool
|
if False, all pot names will be cleansed before evaluation |
False
|
include_deleted |
bool
|
whether to include deleted pots in the response |
False
|
Returns:
Name | Type | Description |
---|---|---|
Pot |
Pot | None
|
the Pot instance |
Source code in wg_utilities/clients/monzo.py
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 |
|
list_accounts(*, include_closed=False, account_type=None)
Get a list of the user's accounts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_closed |
bool
|
whether to include closed accounts in the response |
False
|
account_type |
str
|
the type of account(s) to find; submitted as param in request |
None
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[Account]
|
Account instances, containing all related info |
Source code in wg_utilities/clients/monzo.py
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 |
|
list_pots(*, include_deleted=False)
Get a list of the user's pots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_deleted |
bool
|
whether to include deleted pots in the response |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[Pot]
|
Pot instances, containing all related info |
Source code in wg_utilities/clients/monzo.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|
OAuthClient
Bases: JsonApiClient[GetJsonResponse]
Custom client for interacting with OAuth APIs.
Includes all necessary/basic authentication functionality
Source code in wg_utilities/clients/oauth_client.py
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 |
|
access_token: str | None
property
Access token.
Returns:
Name | Type | Description |
---|---|---|
str |
str | None
|
the access token for this bank's API |
access_token_has_expired: bool
property
Decode the JWT access token and evaluates the expiry time.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
has the access token expired? |
client_id: str
property
Client ID for the Google API.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the current client ID |
client_secret: str | None
property
Client secret.
Returns:
Name | Type | Description |
---|---|---|
str |
str | None
|
the current client secret |
credentials: OAuthCredentials
property
writable
Get creds as necessary (including first time setup) and authenticates them.
Returns:
Name | Type | Description |
---|---|---|
OAuthCredentials |
OAuthCredentials
|
the credentials for the chosen bank |
Raises:
Type | Description |
---|---|
ValueError
|
if the state token returned from the request doesn't match the expected value |
creds_cache_path: Path
property
Path to the credentials cache file.
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
the path to the credentials cache file |
Raises:
Type | Description |
---|---|
ValueError
|
if the path to the credentials cache file is not set, and can't be generated due to a lack of client ID |
refresh_token: str
property
Refresh token.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the API refresh token |
request_headers: dict[str, str]
property
Header to be used in requests to the API.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str]
|
auth headers for HTTP requests |
temp_auth_server: TempAuthServer
property
Create a temporary HTTP server for the auth flow.
Returns:
Name | Type | Description |
---|---|---|
TempAuthServer |
TempAuthServer
|
the temporary server |
__init__(*, client_id=None, client_secret=None, log_requests=False, creds_cache_path=None, creds_cache_dir=None, scopes=None, oauth_login_redirect_host='localhost', oauth_redirect_uri_override=None, headless_auth_link_callback=None, use_existing_credentials_only=False, access_token_endpoint=None, auth_link_base=None, base_url=None, validate_request_success=True)
Initialise the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_id |
str
|
the client ID for the API. Defaults to None. |
None
|
client_secret |
str
|
the client secret for the API. Defaults to None. |
None
|
log_requests |
bool
|
whether to log requests. Defaults to False. |
False
|
creds_cache_path |
Path
|
the path to the credentials cache file.
Defaults to None. Overrides |
None
|
creds_cache_dir |
Path
|
the path to the credentials cache directory.
Overrides environment variable |
None
|
scopes |
list[str]
|
the scopes to request when authenticating. Defaults to None. |
None
|
oauth_login_redirect_host |
str
|
the host to redirect to after authenticating. Defaults to "localhost". |
'localhost'
|
oauth_redirect_uri_override |
str
|
override the redirect URI specified in the OAuth flow. Defaults to None. |
None
|
headless_auth_link_callback |
Callable[[str], None]
|
callback to send the auth link to when running in headless mode. Defaults to None. |
None
|
use_existing_credentials_only |
bool
|
whether to only use existing credentials, and not attempt to authenticate. Defaults to False. |
False
|
access_token_endpoint |
str
|
the endpoint to use to get an access token. Defaults to None. |
None
|
auth_link_base |
str
|
the base URL to use to generate the auth link. Defaults to None. |
None
|
base_url |
str
|
the base URL to use for API requests. Defaults to None. |
None
|
validate_request_success |
bool
|
whether to validate that the request was successful. Defaults to True. |
True
|
Source code in wg_utilities/clients/oauth_client.py
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 |
|
delete_creds_file()
Delete the local creds file.
Source code in wg_utilities/clients/oauth_client.py
357 358 359 |
|
refresh_access_token()
Refresh access token.
Source code in wg_utilities/clients/oauth_client.py
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 |
|
run_first_time_login()
Run the first time login process.
This is a blocking call which will not return until the user has authenticated with the OAuth provider.
Raises:
Type | Description |
---|---|
RuntimeError
|
if |
ValueError
|
if the state token returned by the OAuth provider does not match |
Source code in wg_utilities/clients/oauth_client.py
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 |
|
SpotifyClient
Bases: OAuthClient[SpotifyEntityJson]
Custom client for interacting with Spotify's Web API.
For authentication purposes either an already-instantiated OAuth manager or the relevant credentials must be provided
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_id |
str
|
the application's client ID |
None
|
client_secret |
str
|
the application's client secret |
None
|
log_requests |
bool
|
flag for choosing if to log all requests made |
False
|
creds_cache_path |
str
|
path at which to save cached credentials |
None
|
Source code in wg_utilities/clients/spotify.py
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 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 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 |
|
current_user: User
property
Get the current user's info.
Returns:
Name | Type | Description |
---|---|---|
User |
User
|
an instance of the current Spotify user |
add_tracks_to_playlist(tracks, playlist, *, log_responses=False, force_add=False, update_instance_tracklist=True)
Add one or more tracks to a playlist.
If force_add
is False, a check is made against the Playlist's tracklist to
ensure that the track isn't already in the playlist. This can be slow if it's
a (new) big playlist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tracks |
list
|
a list of Track instances to be added to the given playlist |
required |
playlist |
Playlist
|
the playlist being updated |
required |
log_responses |
bool
|
log each individual response |
False
|
force_add |
bool
|
flag for adding the track even if it's in the playlist already |
False
|
update_instance_tracklist |
bool
|
appends the track to the Playlist's tracklist. Can be slow if it's a big playlist as it might have to get the tracklist first |
True
|
Source code in wg_utilities/clients/spotify.py
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 |
|
create_playlist(*, name, description='', public=False, collaborative=False)
Create a new playlist under the current user's account.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the new playlist |
required |
description |
str
|
the description of the new playlist |
''
|
public |
bool
|
determines if the playlist is publicly accessible |
False
|
collaborative |
bool
|
allows other people to add tracks when True |
False
|
Returns:
Name | Type | Description |
---|---|---|
Playlist |
Playlist
|
an instance of the Playlist class containing the new playlist's metadata |
Source code in wg_utilities/clients/spotify.py
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 |
|
get_album_by_id(id_)
Get an album from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the album |
required |
Returns:
Name | Type | Description |
---|---|---|
Album |
Album
|
an instantiated Album, from the API's response |
Source code in wg_utilities/clients/spotify.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
get_artist_by_id(id_)
Get an artist from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the artist |
required |
Returns:
Name | Type | Description |
---|---|---|
Artist |
Artist
|
an instantiated Artist, from the API's response |
Source code in wg_utilities/clients/spotify.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
get_items(url, *, params=None, hard_limit=1000000, limit_func=None, top_level_key=None, list_key='items')
Retrieve a list of items from a given URL, including pagination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
the API endpoint which we're listing |
required |
params |
dict
|
any params to pass with the API request |
None
|
hard_limit |
int
|
a hard limit to apply to the number of items returned (as opposed to the "soft" limit of 50 imposed by the API) |
1000000
|
limit_func |
Callable
|
a function which is used to evaluate each item in turn: if it returns False, the item is added to the output list; if it returns True then the iteration stops and the list is returned as-is |
None
|
top_level_key |
str
|
an optional key to use when the items in the response are nested 1 level deeper than normal |
None
|
list_key |
Literal['devices', 'items']
|
the key in the response which contains the list of items |
'items'
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[SpotifyEntityJson]
|
a list of dicts representing the Spotify items |
Source code in wg_utilities/clients/spotify.py
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 |
|
get_playlist_by_id(id_)
Get a playlist from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the playlist |
required |
Returns:
Name | Type | Description |
---|---|---|
Playlist |
Playlist
|
an instantiated Playlist, from the API's response |
Source code in wg_utilities/clients/spotify.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
get_track_by_id(id_)
Get a track from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the track |
required |
Returns:
Name | Type | Description |
---|---|---|
Track |
Track
|
an instantiated Track, from the API's response |
Source code in wg_utilities/clients/spotify.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
search(search_term, *, entity_types=(), get_best_match_only=False)
Search Spotify for a given search term.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_term |
str
|
the term to use as the base of the search |
required |
entity_types |
str
|
the types of entity to search for. Must be one of SpotifyClient.SEARCH_TYPES |
()
|
get_best_match_only |
bool
|
return a single entity from the top of the list, rather than all matches |
False
|
Returns:
Name | Type | Description |
---|---|---|
Artist | Playlist | Track | Album | None | ParsedSearchResponse
|
Artist | Playlist | Track | Album: a single entity if the best match flag is set |
|
dict |
Artist | Playlist | Track | Album | None | ParsedSearchResponse
|
a dict of entities, by type |
Raises:
Type | Description |
---|---|
ValueError
|
if multiple entity types have been requested but the best match flag is true |
ValueError
|
if one of entity_types is an invalid value |
Source code in wg_utilities/clients/spotify.py
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 |
|
TrueLayerClient
Bases: OAuthClient[dict[Literal['results'], list[TrueLayerEntityJson]]]
Custom client for interacting with TrueLayer's APIs.
Source code in wg_utilities/clients/truelayer.py
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 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
|
get_account_by_id(account_id)
Get an Account instance based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
account_id |
str
|
the ID of the card |
required |
Returns:
Name | Type | Description |
---|---|---|
Account |
Account | None
|
an Account instance, with all relevant info |
Source code in wg_utilities/clients/truelayer.py
687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
get_card_by_id(card_id)
Get a Card instance based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
card_id |
str
|
the ID of the card |
required |
Returns:
Name | Type | Description |
---|---|---|
Card |
Card | None
|
a Card instance, with all relevant info |
Source code in wg_utilities/clients/truelayer.py
701 702 703 704 705 706 707 708 709 710 711 712 713 |
|
list_accounts()
List all accounts under the given bank account.
Returns:
Type | Description |
---|---|
list[Account]
|
list[Account]: Account instances, containing all related info |
Source code in wg_utilities/clients/truelayer.py
715 716 717 718 719 720 721 |
|
list_cards()
List all accounts under the given bank account.
Returns:
Type | Description |
---|---|
list[Card]
|
list[Account]: Account instances, containing all related info |
Source code in wg_utilities/clients/truelayer.py
723 724 725 726 727 728 729 |
|
google_calendar
Custom client for interacting with Google's Calendar API.
Calendar
Bases: GoogleCalendarEntity
Class for Google calendar instances.
Source code in wg_utilities/clients/google_calendar.py
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 |
|
__str__()
Return the calendar name.
Source code in wg_utilities/clients/google_calendar.py
351 352 353 |
|
get_event_by_id(event_id)
Get an event by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
str
|
ID of the event to get |
required |
Returns:
Name | Type | Description |
---|---|---|
Event |
Event
|
Event object |
Source code in wg_utilities/clients/google_calendar.py
274 275 276 277 278 279 280 281 282 283 284 |
|
get_events(page_size=500, order_by='updated', from_datetime=None, to_datetime=None, day_limit=None, *, combine_recurring_events=False)
Retrieve events from the calendar according to a set of criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_size |
int
|
the number of records to return on a single response page |
500
|
order_by |
Literal['updated', 'startTime']
|
the order of the events returned within the result |
'updated'
|
from_datetime |
datetime
|
lower bound (exclusive) for an event's end time to filter by. Defaults to 90 days ago. |
None
|
to_datetime |
datetime
|
upper bound (exclusive) for an event's start time to filter by. Defaults to now. |
None
|
combine_recurring_events |
bool
|
whether to expand recurring events into instances and only return single one-off events and instances of recurring events, but not the underlying recurring events themselves |
False
|
day_limit |
int
|
the maximum number of days to return events for. |
None
|
Returns:
Type | Description |
---|---|
list[Event]
|
List[Event]: a list of Event instances |
Raises:
Type | Description |
---|---|
ValueError
|
if the time parameters are invalid |
Source code in wg_utilities/clients/google_calendar.py
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 |
|
serialize_timezone(tz)
Serialize the timezone to a string.
Source code in wg_utilities/clients/google_calendar.py
268 269 270 271 272 |
|
validate_timezone(value)
classmethod
Convert the timezone string into a tzinfo object.
Source code in wg_utilities/clients/google_calendar.py
259 260 261 262 263 264 265 266 |
|
CalendarJson
Bases: TypedDict
JSON representation of a Calendar.
Source code in wg_utilities/clients/google_calendar.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
Event
Bases: GoogleCalendarEntity
Class for Google Calendar events.
Source code in wg_utilities/clients/google_calendar.py
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 |
|
response_status: ResponseStatus
property
User's response status.
Returns:
Name | Type | Description |
---|---|---|
ResponseStatus |
ResponseStatus
|
the response status for the authenticated user |
__gt__(other)
Compare two events by their start time, end time, or name.
Source code in wg_utilities/clients/google_calendar.py
471 472 473 474 475 476 477 478 479 480 481 |
|
__lt__(other)
Compare two events by their start time, end time, or name.
Source code in wg_utilities/clients/google_calendar.py
483 484 485 486 487 488 489 490 491 492 493 |
|
__str__()
Return the event's summary and start/end datetimes.
Source code in wg_utilities/clients/google_calendar.py
495 496 497 498 499 500 501 |
|
delete()
Delete the event from the host calendar.
Source code in wg_utilities/clients/google_calendar.py
450 451 452 |
|
EventJson
Bases: TypedDict
JSON representation of an Event.
Source code in wg_utilities/clients/google_calendar.py
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 |
|
EventType
Bases: StrEnum
Enumeration for event types.
Source code in wg_utilities/clients/google_calendar.py
37 38 39 40 41 42 |
|
GoogleCalendarClient
Bases: GoogleClient[GoogleCalendarEntityJson]
Custom client specifically for Google's Calendar API.
Source code in wg_utilities/clients/google_calendar.py
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 |
|
calendar_list: list[Calendar]
property
List of calendars.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Calendar]
|
a list of Calendar instances that the user has access to |
primary_calendar: Calendar
property
Primary calendar for the user.
Returns:
Name | Type | Description |
---|---|---|
Calendar |
Calendar
|
the current user's primary calendar |
create_event(summary, start_datetime, end_datetime, tz=None, calendar=None, extra_params=None)
Create an event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
summary |
str
|
the summary (title) of the event |
required |
start_datetime |
Union[datetime, date]
|
when the event starts |
required |
end_datetime |
Union[datetime, date]
|
when the event ends |
required |
tz |
str
|
the timezone which the event is in (IANA database name) |
None
|
calendar |
Calendar
|
the calendar to add the event to |
None
|
extra_params |
dict
|
any extra params to pass in the request |
None
|
Returns:
Name | Type | Description |
---|---|---|
Event |
Event
|
a new event instance, fresh out of the oven |
Raises:
Type | Description |
---|---|
TypeError
|
if the start/end datetime params are not the correct type |
Source code in wg_utilities/clients/google_calendar.py
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 |
|
delete_event_by_id(event_id, calendar=None)
Delete an event from a calendar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
str
|
the ID of the event to delete |
required |
calendar |
Calendar
|
the calendar being updated |
None
|
Source code in wg_utilities/clients/google_calendar.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
|
get_event_by_id(event_id, *, calendar=None)
Get a specific event by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
str
|
the ID of the event to delete |
required |
calendar |
Calendar
|
the calendar being updated |
None
|
Returns:
Name | Type | Description |
---|---|---|
Event |
Event
|
an Event instance with all relevant attributes |
Source code in wg_utilities/clients/google_calendar.py
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 |
|
GoogleCalendarEntity
Bases: BaseModelWithConfig
Base class for Google Calendar entities.
Source code in wg_utilities/clients/google_calendar.py
165 166 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 |
|
__eq__(other)
Compare two GoogleCalendarEntity objects by ID.
Source code in wg_utilities/clients/google_calendar.py
195 196 197 198 199 200 |
|
from_json_response(value, google_client, calendar=None)
classmethod
Create a Calendar/Event from a JSON response.
Source code in wg_utilities/clients/google_calendar.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
ResponseStatus
Bases: StrEnum
Enumeration for event attendee response statuses.
Source code in wg_utilities/clients/google_calendar.py
27 28 29 30 31 32 33 34 |
|
google_drive
Custom client for interacting with Google's Drive API.
Directory
Bases: File
, _CanHaveChildren
A Google Drive directory - basically a File with extended functionality.
Source code in wg_utilities/clients/google_drive.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
|
__repr__()
Return a string representation of the directory.
Source code in wg_utilities/clients/google_drive.py
895 896 897 |
|
Drive
Bases: _CanHaveChildren
A Google Drive: Drive - basically a Directory with extended functionality.
Source code in wg_utilities/clients/google_drive.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 |
|
all_directories: list[Directory]
property
Get all directories in the Drive.
all_files: list[File]
property
Get all files in the Drive.
all_known_descendents: list[Directory | File]
property
__repr__()
Return a string representation of the directory.
Source code in wg_utilities/clients/google_drive.py
1359 1360 1361 |
|
get_directory_by_id(directory_id)
Get a directory by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory_id |
str
|
the ID of the directory to get |
required |
Returns:
Name | Type | Description |
---|---|---|
Directory |
Directory
|
the directory with the given ID |
Source code in wg_utilities/clients/google_drive.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
|
get_file_by_id(file_id)
Get a file by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_id |
str
|
the ID of the file to get |
required |
Returns:
Name | Type | Description |
---|---|---|
File |
File
|
the file with the given ID |
Source code in wg_utilities/clients/google_drive.py
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
|
map(map_type=EntityType.FILE)
Traverse the entire Drive to map its content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
map_type |
EntityType
|
the type of entity to map. Defaults to EntityType.FILE. |
FILE
|
Source code in wg_utilities/clients/google_drive.py
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
|
search(term, /, *, entity_type=None, max_results=50, exact_match=False, created_range=None)
Search for files and directories in the Drive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
term |
str
|
the term to search for |
required |
entity_type |
EntityType | None
|
the type of entity to search for. Defaults to None. |
None
|
max_results |
int
|
the maximum number of results to return. Defaults to 50. |
50
|
exact_match |
bool
|
whether to only return results that exactly match the search term. Defaults to False. |
False
|
created_range |
tuple[datetime, datetime]
|
a tuple containing the start and end of the date range to search in. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
list[File | Directory]
|
list[File | Directory]: the files and directories that match the search term |
Raises:
Type | Description |
---|---|
ValueError
|
if the given entity type is not supported |
Source code in wg_utilities/clients/google_drive.py
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 |
|
EntityKind
Bases: StrEnum
Enum for the different kinds of entities that can be returned by the API.
Source code in wg_utilities/clients/google_drive.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
EntityType
Bases: StrEnum
Enum for the different entity types contained within a Drive.
Source code in wg_utilities/clients/google_drive.py
44 45 46 47 48 |
|
File
Bases: _GoogleDriveEntity
A file object within Google Drive.
Source code in wg_utilities/clients/google_drive.py
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 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
|
parent: Directory | Drive
property
__getattribute__(name)
Override the default __getattribute__
to allow for lazy metadata loading.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the attribute to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The value of the attribute. |
Source code in wg_utilities/clients/google_drive.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
|
__gt__(other)
Compare two files by name.
Source code in wg_utilities/clients/google_drive.py
849 850 851 |
|
__lt__(other)
Compare two files by name.
Source code in wg_utilities/clients/google_drive.py
853 854 855 |
|
__repr__()
Return a string representation of the file.
Source code in wg_utilities/clients/google_drive.py
857 858 859 |
|
describe(*, force_update=False)
Describe the file by requesting all available fields from the Drive API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_update |
bool
|
re-pull the description from Google Drive, even if we already have the description locally |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
JSONObj
|
the description JSON for this file |
Raises:
Type | Description |
---|---|
ValueError
|
if an unexpected field is returned from the Google Drive API. |
Source code in wg_utilities/clients/google_drive.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
|
GoogleDriveClient
Bases: GoogleClient[JSONObj]
Custom client specifically for Google's Drive API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scopes |
list
|
a list of scopes the client can be given |
None
|
creds_cache_path |
str
|
file path for where to cache credentials |
None
|
Source code in wg_utilities/clients/google_drive.py
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 |
|
ItemMetadataRetrieval
Bases: StrEnum
The type of metadata retrieval to use for items.
Attributes:
Name | Type | Description |
---|---|---|
ON_DEMAND |
str
|
only retrieves single metadata items on demand. Best for reducing memory usage but makes most HTTP requests. |
ON_FIRST_REQUEST |
str
|
retrieves all metadata items on the first request for any metadata value. Nice middle ground between memory usage and HTTP requests. |
ON_INIT |
str
|
retrieves metadata on instance initialisation. Increases memory
usage, makes the fewest HTTP requests. If combined with a |
Source code in wg_utilities/clients/google_drive.py
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 |
|
google_fit
Custom client for interacting with Google's Fit API.
DataSource
Class for interacting with Google Fit Data Sources.
An example of a data source is Strava, Google Fit, MyFitnessPal, etc. The ID is something like "...weight", "...calories burnt".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source_id |
str
|
the unique ID of the data source |
required |
google_client |
GoogleClient
|
a GoogleClient instance, needed for getting DataSource info |
required |
Source code in wg_utilities/clients/google_fit.py
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 |
|
data_point_value_key: Literal['fpVal', 'intVal']
property
Key to use when looking up the value of a data point.
Returns:
Name | Type | Description |
---|---|---|
str |
Literal['fpVal', 'intVal']
|
the key to use when extracting data from a data point |
data_type_field_format: Literal['floatPoint', 'integer']
property
Field format of the data type.
Original return type on here was as follows, think it was for other endpoints I haven't implemented
Literal[
"blob", "floatList", "floatPoint", "integer", "integerList", "map", "string"
]
Returns:
Name | Type | Description |
---|---|---|
str |
Literal['floatPoint', 'integer']
|
the field format of this data source (i.e. "integer" or "floatPoint") |
Raises:
Type | Description |
---|---|
Exception
|
if more than 1 dataType field value is found |
description: _DataSourceDescriptionInfo
property
Description of the data source, in JSON format.
Returns:
Name | Type | Description |
---|---|---|
dict |
_DataSourceDescriptionInfo
|
the JSON description of this data source |
DataPointValueKeyLookupInfo
Bases: TypedDict
Typing info for the Data Point lookup dict.
Source code in wg_utilities/clients/google_fit.py
57 58 59 60 61 |
|
sum_data_points_in_range(from_datetime=None, to_datetime=None)
Get the sum of data points in the given range.
If no from_datetime
is provided, it defaults to the start of today; if no
to_datetime
is provided then it defaults to now.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_datetime |
datetime
|
lower boundary for step count. Defaults to start of today. |
None
|
to_datetime |
datetime
|
upper boundary for step count. Defaults to now. |
None
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
a sum of data points in the given range |
Source code in wg_utilities/clients/google_fit.py
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 |
|
GoogleFitClient
Bases: GoogleClient[Any]
Custom client for interacting with the Google Fit API.
See Also
GoogleClient: the base Google client, used for authentication and common functions
Source code in wg_utilities/clients/google_fit.py
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 |
|
data_sources: dict[str, DataSource]
property
Data sources available to this client.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, DataSource]
|
a dict of data sources, keyed by their UID |
get_data_source(data_source_id)
Get a data source based on its UID.
DataSource instances are cached for the lifetime of the GoogleClient instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source_id |
str
|
the UID of the data source |
required |
Returns:
Name | Type | Description |
---|---|---|
DataSource |
DataSource
|
an instance, ready to use! |
Source code in wg_utilities/clients/google_fit.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
google_photos
Custom client for interacting with Google's Photos API.
Album
Bases: GooglePhotosEntity
Class for Google Photos albums and their metadata/content.
Source code in wg_utilities/clients/google_photos.py
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 |
|
media_items: list[MediaItem]
property
List all media items in the album.
Returns:
Name | Type | Description |
---|---|---|
list |
list[MediaItem]
|
a list of MediaItem instances, representing the contents of the album |
__contains__(item)
Check if the album contains the given media item.
Source code in wg_utilities/clients/google_photos.py
158 159 160 161 |
|
AlbumJson
Bases: _GooglePhotosEntityJson
JSON representation of an Album.
Source code in wg_utilities/clients/google_photos.py
103 104 105 106 107 108 109 110 111 |
|
GooglePhotosClient
Bases: GoogleClient[GooglePhotosEntityJson]
Custom client for interacting with the Google Photos API.
See Also
GoogleClient: the base Google client, used for authentication and common functions
Source code in wg_utilities/clients/google_photos.py
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 |
|
albums: list[Album]
property
List all albums in the active Google account.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Album]
|
a list of Album instances |
get_album_by_id(album_id)
Get an album by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
album_id |
str
|
the ID of the album to fetch |
required |
Returns:
Name | Type | Description |
---|---|---|
Album |
Album
|
the album with the given ID |
Source code in wg_utilities/clients/google_photos.py
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 |
|
get_album_by_name(album_name)
Get an album definition from the Google API based on the album name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
album_name |
str
|
the name of the album to find |
required |
Returns:
Name | Type | Description |
---|---|---|
Album |
Album
|
an Album instance, with all metadata etc. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
if the client can't find an album with the correct name |
Source code in wg_utilities/clients/google_photos.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
GooglePhotosEntity
Bases: BaseModelWithConfig
Generic base class for Google Photos entities.
Source code in wg_utilities/clients/google_photos.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
from_json_response(value, *, google_client)
classmethod
Create an entity from a JSON response.
Source code in wg_utilities/clients/google_photos.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
MediaItem
Bases: GooglePhotosEntity
Class for representing a MediaItem and its metadata/content.
Source code in wg_utilities/clients/google_photos.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 |
|
binary_content: bytes
property
MediaItem binary content.
Opens the local copy of the file (downloading it first if necessary) and reads the binary content of it
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
the binary content of the file |
creation_datetime: datetime
property
The datetime when the media item was created.
height: int
property
MediaItem height.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the media item's height |
is_downloaded: bool
property
Whether the media item has been downloaded locally.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the media item has been downloaded locally |
local_path: Path
property
The path which the is/would be stored at locally.
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
where the file is/will be stored |
media_type: MediaType
property
Determines the media item's file type from the JSON.
Returns:
Name | Type | Description |
---|---|---|
MediaType |
MediaType
|
the media type (image, video, etc.) for this item |
width: int
property
MediaItem width.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
the media item's width |
as_bytes(*, height_override=0, width_override=0)
MediaItem binary content - without the download.
Source code in wg_utilities/clients/google_photos.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
download(target_directory='', *, file_name_override=None, width_override=0, height_override=0, force_download=False)
Download the media item to local storage.
Notes
The width/height overrides do not apply to videos.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_directory |
Path or str
|
the directory to download the file to. Defaults to the current working directory. |
''
|
file_name_override |
str
|
the file name to use when downloading the file |
None
|
width_override |
int
|
the width override to use when downloading the file |
0
|
height_override |
int
|
the height override to use when downloading the file |
0
|
force_download |
bool
|
flag for forcing a download, even if it exists locally already |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
Path
|
the path to the downloaded file (self.local_path) |
Source code in wg_utilities/clients/google_photos.py
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 |
|
MediaItemJson
Bases: _GooglePhotosEntityJson
JSON representation of a Media Item (photo or video).
Source code in wg_utilities/clients/google_photos.py
164 165 166 167 168 169 170 171 172 |
|
MediaType
Bases: Enum
Enum for all potential media types.
Source code in wg_utilities/clients/google_photos.py
63 64 65 66 67 68 |
|
json_api_client
Generic no-auth JSON API client to simplify interactions.
JsonApiClient
Bases: Generic[GetJsonResponse]
Generic no-auth JSON API client to simplify interactions.
Sort of an SDK?
Source code in wg_utilities/clients/json_api_client.py
22 23 24 25 26 27 28 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 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 |
|
request_headers: dict[str, str]
property
Header to be used in requests to the API.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str]
|
auth headers for HTTP requests |
get_json_response(url, /, *, params=None, header_overrides=None, timeout=None, json=None, data=None)
Get a simple JSON object from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
the API endpoint to GET |
required |
params |
dict
|
the parameters to be passed in the HTTP request |
None
|
header_overrides |
dict
|
headers to add to/overwrite the headers in
|
None
|
timeout |
float
|
How many seconds to wait for the server to send data before giving up |
None
|
json |
dict
|
a JSON payload to pass in the request |
None
|
data |
dict
|
a data payload to pass in the request |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
GetJsonResponse
|
the JSON from the response |
Source code in wg_utilities/clients/json_api_client.py
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 |
|
post_json_response(url, /, *, params=None, header_overrides=None, timeout=None, json=None, data=None)
Get a simple JSON object from a URL from a POST request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
the API endpoint to GET |
required |
params |
dict
|
the parameters to be passed in the HTTP request |
None
|
header_overrides |
dict
|
headers to add to/overwrite the headers in
|
None
|
timeout |
float
|
How many seconds to wait for the server to send data before giving up |
None
|
json |
dict
|
a JSON payload to pass in the request |
None
|
data |
dict
|
a data payload to pass in the request |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
GetJsonResponse
|
the JSON from the response |
Source code in wg_utilities/clients/json_api_client.py
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 |
|
monzo
Custom client for interacting with Monzo's API.
Account
Bases: BaseModelWithConfig
Class for managing individual bank accounts.
Source code in wg_utilities/clients/monzo.py
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 |
|
balance: int | None
property
Current balance of the account, in pence.
Returns:
Name | Type | Description |
---|---|---|
float |
int | None
|
the currently available balance of the account |
balance_including_flexible_savings: int | None
property
Balance including flexible savings, in pence.
Returns:
Name | Type | Description |
---|---|---|
float |
int | None
|
the currently available balance of the account, including flexible savings pots |
balance_variables: BalanceVariables
property
The balance variables for the account.
Returns:
Name | Type | Description |
---|---|---|
BalanceVariables |
BalanceVariables
|
the balance variables |
spend_today: int | None
property
Amount spent today, in pence.
Returns:
Name | Type | Description |
---|---|---|
int |
int | None
|
the amount spent from this account today (considered from approx 4am onwards) |
total_balance: int | None
property
Total balance of the account, in pence.
Returns:
Name | Type | Description |
---|---|---|
str |
int | None
|
the sum of the currently available balance of the account and the combined total of all the user's pots |
__eq__(other)
Check if two accounts are equal.
Source code in wg_utilities/clients/monzo.py
390 391 392 393 394 395 |
|
__repr__()
Representation of the account.
Source code in wg_utilities/clients/monzo.py
397 398 399 |
|
from_json_response(value, monzo_client)
classmethod
Create an account from a JSON response.
Source code in wg_utilities/clients/monzo.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
list_transactions(from_datetime=None, to_datetime=None, limit=100)
List transactions for the account.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_datetime |
datetime
|
the start of the time period to list transactions for. Defaults to None. |
None
|
to_datetime |
datetime
|
the end of the time period to list transactions for. Defaults to None. |
None
|
limit |
int
|
the maximum number of transactions to return. Defaults to 100. |
100
|
Returns:
Type | Description |
---|---|
list[Transaction]
|
list[dict[str, object]]: the list of transactions |
Source code in wg_utilities/clients/monzo.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 |
|
update_balance_variables()
Update the balance-related instance attributes.
Latest values from the API are used. This is called automatically when
a balance property is accessed and the last update was more than
balance_update_threshold
minutes ago, or if it is None. Can also be called
manually if required.
Source code in wg_utilities/clients/monzo.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
validate_sort_code(sort_code)
classmethod
Ensure that the sort code is a 6-digit integer.
Represented as a string so leading zeroes aren't lost.
Source code in wg_utilities/clients/monzo.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
AccountJson
Bases: TypedDict
JSON representation of a Monzo account.
Source code in wg_utilities/clients/monzo.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
AccountOwner
Bases: TypedDict
The owner of a Monzo account.
Source code in wg_utilities/clients/monzo.py
207 208 209 210 211 212 |
|
BalanceVariables
Bases: BaseModelWithConfig
Variables for an account's balance summary.
Source code in wg_utilities/clients/monzo.py
194 195 196 197 198 199 200 201 202 203 204 |
|
MonzoClient
Bases: OAuthClient[MonzoGJR]
Custom client for interacting with Monzo's API.
Source code in wg_utilities/clients/monzo.py
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 |
|
current_account: Account
property
Get the main account for the Monzo user.
We assume there'll only be one main account per user.
Returns:
Name | Type | Description |
---|---|---|
Account |
Account
|
the user's main account, instantiated |
request_headers: dict[str, str]
property
Header to be used in requests to the API.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str]
|
auth headers for HTTP requests |
deposit_into_pot(pot, amount_pence, dedupe_id=None)
Move money from the user's account into one of their pots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pot |
Pot
|
the target pot |
required |
amount_pence |
int
|
the amount of money to deposit, in pence |
required |
dedupe_id |
str
|
unique string used to de-duplicate deposits. Will be created if not provided |
None
|
Source code in wg_utilities/clients/monzo.py
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 |
|
get_pot_by_id(pot_id)
Get a pot from its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pot_id |
str
|
the ID of the pot to find |
required |
Returns:
Name | Type | Description |
---|---|---|
Pot |
Pot | None
|
the Pot instance |
Source code in wg_utilities/clients/monzo.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
get_pot_by_name(pot_name, *, exact_match=False, include_deleted=False)
Get a pot from its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pot_name |
str
|
the name of the pot to find |
required |
exact_match |
bool
|
if False, all pot names will be cleansed before evaluation |
False
|
include_deleted |
bool
|
whether to include deleted pots in the response |
False
|
Returns:
Name | Type | Description |
---|---|---|
Pot |
Pot | None
|
the Pot instance |
Source code in wg_utilities/clients/monzo.py
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 |
|
list_accounts(*, include_closed=False, account_type=None)
Get a list of the user's accounts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_closed |
bool
|
whether to include closed accounts in the response |
False
|
account_type |
str
|
the type of account(s) to find; submitted as param in request |
None
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[Account]
|
Account instances, containing all related info |
Source code in wg_utilities/clients/monzo.py
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 |
|
list_pots(*, include_deleted=False)
Get a list of the user's pots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_deleted |
bool
|
whether to include deleted pots in the response |
False
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[Pot]
|
Pot instances, containing all related info |
Source code in wg_utilities/clients/monzo.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|
MonzoGJR
Bases: TypedDict
The response type for MonzoClient.get_json_response
.
Source code in wg_utilities/clients/monzo.py
430 431 432 433 434 435 |
|
Pot
Bases: BaseModelWithConfig
Read-only class for Monzo pots.
Source code in wg_utilities/clients/monzo.py
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 |
|
PotJson
Bases: TypedDict
JSON representation of a pot.
Yes, this and the Pot
class could've been replaced by Pydantic's
create_model_from_typeddict
, but it doesn't play nice with mypy :(
Source code in wg_utilities/clients/monzo.py
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 |
|
Transaction
Bases: BaseModelWithConfig
Pydantic representation of a transaction.
Source code in wg_utilities/clients/monzo.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 |
|
TransactionJson
Bases: TypedDict
JSON representation of a transaction.
Same as above RE: Pydantic's create_model_from_typeddict
.
Source code in wg_utilities/clients/monzo.py
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 |
|
oauth_client
Generic OAuth client to allow for reusable authentication flows/checks etc.
BaseModelWithConfig
Bases: BaseModel
Reusable BaseModel
with Config to apply to all subclasses.
Source code in wg_utilities/clients/oauth_client.py
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 |
|
model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=True, exclude_unset=True, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)
Create a dictionary representation of the model.
Overrides the standard BaseModel.dict
method, so we can always return the
dict with the same field names it came in with, and exclude any null values
that have been added when parsing
Original documentation is here
- https://docs.pydantic.dev/latest/usage/serialization/#modelmodel_dump
Overridden Parameters
by_alias: False -> True exclude_unset: False -> True
Source code in wg_utilities/clients/oauth_client.py
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 |
|
model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=True, exclude_unset=True, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)
Create a JSON string representation of the model.
Overrides the standard BaseModel.json
method, so we can always return the
dict with the same field names it came in with, and exclude any null values
that have been added when parsing
Original documentation is here
- https://docs.pydantic.dev/latest/usage/serialization/#modelmodel_dump_json
Overridden Parameters
by_alias: False -> True exclude_unset: False -> True
Source code in wg_utilities/clients/oauth_client.py
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 |
|
OAuthClient
Bases: JsonApiClient[GetJsonResponse]
Custom client for interacting with OAuth APIs.
Includes all necessary/basic authentication functionality
Source code in wg_utilities/clients/oauth_client.py
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 |
|
access_token: str | None
property
Access token.
Returns:
Name | Type | Description |
---|---|---|
str |
str | None
|
the access token for this bank's API |
access_token_has_expired: bool
property
Decode the JWT access token and evaluates the expiry time.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
has the access token expired? |
client_id: str
property
Client ID for the Google API.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the current client ID |
client_secret: str | None
property
Client secret.
Returns:
Name | Type | Description |
---|---|---|
str |
str | None
|
the current client secret |
credentials: OAuthCredentials
property
writable
Get creds as necessary (including first time setup) and authenticates them.
Returns:
Name | Type | Description |
---|---|---|
OAuthCredentials |
OAuthCredentials
|
the credentials for the chosen bank |
Raises:
Type | Description |
---|---|
ValueError
|
if the state token returned from the request doesn't match the expected value |
creds_cache_path: Path
property
Path to the credentials cache file.
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
the path to the credentials cache file |
Raises:
Type | Description |
---|---|
ValueError
|
if the path to the credentials cache file is not set, and can't be generated due to a lack of client ID |
refresh_token: str
property
Refresh token.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the API refresh token |
request_headers: dict[str, str]
property
Header to be used in requests to the API.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, str]
|
auth headers for HTTP requests |
temp_auth_server: TempAuthServer
property
Create a temporary HTTP server for the auth flow.
Returns:
Name | Type | Description |
---|---|---|
TempAuthServer |
TempAuthServer
|
the temporary server |
__init__(*, client_id=None, client_secret=None, log_requests=False, creds_cache_path=None, creds_cache_dir=None, scopes=None, oauth_login_redirect_host='localhost', oauth_redirect_uri_override=None, headless_auth_link_callback=None, use_existing_credentials_only=False, access_token_endpoint=None, auth_link_base=None, base_url=None, validate_request_success=True)
Initialise the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_id |
str
|
the client ID for the API. Defaults to None. |
None
|
client_secret |
str
|
the client secret for the API. Defaults to None. |
None
|
log_requests |
bool
|
whether to log requests. Defaults to False. |
False
|
creds_cache_path |
Path
|
the path to the credentials cache file.
Defaults to None. Overrides |
None
|
creds_cache_dir |
Path
|
the path to the credentials cache directory.
Overrides environment variable |
None
|
scopes |
list[str]
|
the scopes to request when authenticating. Defaults to None. |
None
|
oauth_login_redirect_host |
str
|
the host to redirect to after authenticating. Defaults to "localhost". |
'localhost'
|
oauth_redirect_uri_override |
str
|
override the redirect URI specified in the OAuth flow. Defaults to None. |
None
|
headless_auth_link_callback |
Callable[[str], None]
|
callback to send the auth link to when running in headless mode. Defaults to None. |
None
|
use_existing_credentials_only |
bool
|
whether to only use existing credentials, and not attempt to authenticate. Defaults to False. |
False
|
access_token_endpoint |
str
|
the endpoint to use to get an access token. Defaults to None. |
None
|
auth_link_base |
str
|
the base URL to use to generate the auth link. Defaults to None. |
None
|
base_url |
str
|
the base URL to use for API requests. Defaults to None. |
None
|
validate_request_success |
bool
|
whether to validate that the request was successful. Defaults to True. |
True
|
Source code in wg_utilities/clients/oauth_client.py
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 |
|
delete_creds_file()
Delete the local creds file.
Source code in wg_utilities/clients/oauth_client.py
357 358 359 |
|
refresh_access_token()
Refresh access token.
Source code in wg_utilities/clients/oauth_client.py
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 |
|
run_first_time_login()
Run the first time login process.
This is a blocking call which will not return until the user has authenticated with the OAuth provider.
Raises:
Type | Description |
---|---|
RuntimeError
|
if |
ValueError
|
if the state token returned by the OAuth provider does not match |
Source code in wg_utilities/clients/oauth_client.py
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 |
|
OAuthCredentials
Bases: BaseModelWithConfig
Typing info for OAuth credentials.
Source code in wg_utilities/clients/oauth_client.py
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 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 |
|
is_expired: bool
property
Check if the access token is expired.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the token is expired, False otherwise |
parse_first_time_login(value)
classmethod
Parse the response from a first time login into a credentials object.
The following fields are returned per API: +---------------+--------+-------+---------+-----------+ | | Google | Monzo | Spotify | TrueLayer | +===============+========+=======+=========+===========+ | access_token | X | X | X | X | | client_id | X | X | X | X | | expiry_epoch | X | X | X | X | | refresh_token | X | X | X | X | | scope | X | X | X | X | | token_type | X | X | X | X | | client_secret | X | | X | | | user_id | | X | | | | token | X | | | | | token_uri | X | | | | | scopes | X | | | | +---------------+--------+-------+---------+-----------+
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
dict[str, Any]
|
the response from the API |
required |
Returns:
Name | Type | Description |
---|---|---|
OAuthCredentials |
OAuthCredentials
|
an OAuthCredentials instance |
Raises:
Type | Description |
---|---|
ValueError
|
if |
Source code in wg_utilities/clients/oauth_client.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 |
|
update_access_token(new_token, expires_in, refresh_token=None)
Update the access token and expiry time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_token |
str
|
the newly refreshed access token |
required |
expires_in |
int
|
the number of seconds until the token expires |
required |
refresh_token |
str
|
a new refresh token. Defaults to unset. |
None
|
Source code in wg_utilities/clients/oauth_client.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
spotify
Custom client for interacting with Spotify's Web API.
Album
Bases: SpotifyEntity[AlbumSummaryJson]
An album on Spotify.
Source code in wg_utilities/clients/spotify.py
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 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 |
|
album_type: AlbumType
property
Convert the album type string to an enum value.
artists: list[Artist]
property
Return a list of artists who contributed to the track.
Returns:
Name | Type | Description |
---|---|---|
list |
Artist
|
a list of the artists who contributed to this track |
tracks: list[Track]
property
List of tracks on the album.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Track]
|
a list of tracks on this album |
validate_release_date(value, info)
classmethod
Convert the release date string to a date object.
Source code in wg_utilities/clients/spotify.py
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
|
AlbumType
Bases: StrEnum
Enum for the different types of album Spotify supports.
Source code in wg_utilities/clients/spotify.py
71 72 73 74 75 76 |
|
Artist
Bases: SpotifyEntity[ArtistSummaryJson]
An artist on Spotify.
Source code in wg_utilities/clients/spotify.py
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
|
albums: list[Album]
property
Return a list of albums by this artist.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Album]
|
A list of albums this artist has contributed to |
Device
Bases: BaseModelWithConfig
Model for a Spotify device.
Source code in wg_utilities/clients/spotify.py
79 80 81 82 83 84 85 86 87 88 |
|
ParsedSearchResponse
Bases: TypedDict
The return type of SpotifyClient.search
.
Source code in wg_utilities/clients/spotify.py
62 63 64 65 66 67 68 |
|
Playlist
Bases: SpotifyEntity[PlaylistSummaryJson]
A Spotify playlist.
Source code in wg_utilities/clients/spotify.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
|
live_snapshot_id: str
property
The live snapshot ID of the playlist.
The value is cached for a minute before being refreshed.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the live snapshot ID of the playlist |
owner: User
property
tracks: list[Track]
property
Return a list of tracks in the playlist.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Track]
|
a list of tracks in this playlist |
updates_available: bool
property
Check if the playlist has updates available.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
whether the playlist has updates available |
__contains__(track)
Check if a track is in the playlist.
Source code in wg_utilities/clients/spotify.py
1084 1085 1086 |
|
__gt__(other)
Compare two playlists by name and ID.
Source code in wg_utilities/clients/spotify.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
|
__iter__()
Iterate over the tracks in the playlist.
Source code in wg_utilities/clients/spotify.py
1101 1102 1103 |
|
__lt__(other)
Compare two playlists by name and ID.
Source code in wg_utilities/clients/spotify.py
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
|
remove_local_tracks(tracks_json)
classmethod
Remove local tracks from the playlist's tracklist.
Source code in wg_utilities/clients/spotify.py
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 |
|
SpotifyClient
Bases: OAuthClient[SpotifyEntityJson]
Custom client for interacting with Spotify's Web API.
For authentication purposes either an already-instantiated OAuth manager or the relevant credentials must be provided
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_id |
str
|
the application's client ID |
None
|
client_secret |
str
|
the application's client secret |
None
|
log_requests |
bool
|
flag for choosing if to log all requests made |
False
|
creds_cache_path |
str
|
path at which to save cached credentials |
None
|
Source code in wg_utilities/clients/spotify.py
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 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 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 |
|
current_user: User
property
Get the current user's info.
Returns:
Name | Type | Description |
---|---|---|
User |
User
|
an instance of the current Spotify user |
add_tracks_to_playlist(tracks, playlist, *, log_responses=False, force_add=False, update_instance_tracklist=True)
Add one or more tracks to a playlist.
If force_add
is False, a check is made against the Playlist's tracklist to
ensure that the track isn't already in the playlist. This can be slow if it's
a (new) big playlist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tracks |
list
|
a list of Track instances to be added to the given playlist |
required |
playlist |
Playlist
|
the playlist being updated |
required |
log_responses |
bool
|
log each individual response |
False
|
force_add |
bool
|
flag for adding the track even if it's in the playlist already |
False
|
update_instance_tracklist |
bool
|
appends the track to the Playlist's tracklist. Can be slow if it's a big playlist as it might have to get the tracklist first |
True
|
Source code in wg_utilities/clients/spotify.py
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 |
|
create_playlist(*, name, description='', public=False, collaborative=False)
Create a new playlist under the current user's account.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the new playlist |
required |
description |
str
|
the description of the new playlist |
''
|
public |
bool
|
determines if the playlist is publicly accessible |
False
|
collaborative |
bool
|
allows other people to add tracks when True |
False
|
Returns:
Name | Type | Description |
---|---|---|
Playlist |
Playlist
|
an instance of the Playlist class containing the new playlist's metadata |
Source code in wg_utilities/clients/spotify.py
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 |
|
get_album_by_id(id_)
Get an album from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the album |
required |
Returns:
Name | Type | Description |
---|---|---|
Album |
Album
|
an instantiated Album, from the API's response |
Source code in wg_utilities/clients/spotify.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
get_artist_by_id(id_)
Get an artist from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the artist |
required |
Returns:
Name | Type | Description |
---|---|---|
Artist |
Artist
|
an instantiated Artist, from the API's response |
Source code in wg_utilities/clients/spotify.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
get_items(url, *, params=None, hard_limit=1000000, limit_func=None, top_level_key=None, list_key='items')
Retrieve a list of items from a given URL, including pagination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
the API endpoint which we're listing |
required |
params |
dict
|
any params to pass with the API request |
None
|
hard_limit |
int
|
a hard limit to apply to the number of items returned (as opposed to the "soft" limit of 50 imposed by the API) |
1000000
|
limit_func |
Callable
|
a function which is used to evaluate each item in turn: if it returns False, the item is added to the output list; if it returns True then the iteration stops and the list is returned as-is |
None
|
top_level_key |
str
|
an optional key to use when the items in the response are nested 1 level deeper than normal |
None
|
list_key |
Literal['devices', 'items']
|
the key in the response which contains the list of items |
'items'
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[SpotifyEntityJson]
|
a list of dicts representing the Spotify items |
Source code in wg_utilities/clients/spotify.py
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 |
|
get_playlist_by_id(id_)
Get a playlist from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the playlist |
required |
Returns:
Name | Type | Description |
---|---|---|
Playlist |
Playlist
|
an instantiated Playlist, from the API's response |
Source code in wg_utilities/clients/spotify.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
get_track_by_id(id_)
Get a track from Spotify based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
str
|
the Spotify ID which is used to find the track |
required |
Returns:
Name | Type | Description |
---|---|---|
Track |
Track
|
an instantiated Track, from the API's response |
Source code in wg_utilities/clients/spotify.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
search(search_term, *, entity_types=(), get_best_match_only=False)
Search Spotify for a given search term.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_term |
str
|
the term to use as the base of the search |
required |
entity_types |
str
|
the types of entity to search for. Must be one of SpotifyClient.SEARCH_TYPES |
()
|
get_best_match_only |
bool
|
return a single entity from the top of the list, rather than all matches |
False
|
Returns:
Name | Type | Description |
---|---|---|
Artist | Playlist | Track | Album | None | ParsedSearchResponse
|
Artist | Playlist | Track | Album: a single entity if the best match flag is set |
|
dict |
Artist | Playlist | Track | Album | None | ParsedSearchResponse
|
a dict of entities, by type |
Raises:
Type | Description |
---|---|
ValueError
|
if multiple entity types have been requested but the best match flag is true |
ValueError
|
if one of entity_types is an invalid value |
Source code in wg_utilities/clients/spotify.py
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 |
|
SpotifyEntity
Bases: BaseModelWithConfig
, Generic[SJ]
Base model for Spotify entities.
Source code in wg_utilities/clients/spotify.py
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 |
|
url: str
property
URL of the entity.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the URL of this entity |
__eq__(other)
Check if two entities are equal.
Source code in wg_utilities/clients/spotify.py
633 634 635 636 637 |
|
__gt__(other)
Check if this entity is greater than another.
Source code in wg_utilities/clients/spotify.py
639 640 641 642 643 |
|
__hash__()
Get the hash of this entity.
Source code in wg_utilities/clients/spotify.py
645 646 647 |
|
__lt__(other)
Check if this entity is less than another.
Source code in wg_utilities/clients/spotify.py
649 650 651 652 653 |
|
__repr__()
Get a string representation of this entity.
Source code in wg_utilities/clients/spotify.py
655 656 657 |
|
__str__()
Get the string representation of this entity.
Source code in wg_utilities/clients/spotify.py
659 660 661 |
|
from_json_response(value, spotify_client, additional_fields=None, metadata=None)
classmethod
Parse a JSON response from the API into the given entity type model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
dict[str, object]
|
the JSON response from the API |
required |
spotify_client |
SpotifyClient
|
the client to use for future API calls |
required |
additional_fields |
dict[str, object] | None
|
additional fields to add to the model |
None
|
metadata |
dict[str, object] | None
|
additional metadata to add to the model |
None
|
Returns:
Name | Type | Description |
---|---|---|
SpotifyEntity |
Self
|
the model for the given entity type |
Source code in wg_utilities/clients/spotify.py
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 |
|
Track
Bases: SpotifyEntity[TrackFullJson]
A track on Spotify.
Source code in wg_utilities/clients/spotify.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
|
album: Album
property
artist: Artist
property
Track's parent artist.
Returns:
Name | Type | Description |
---|---|---|
Artist |
Artist
|
the main artist which this track is from |
artists: list[Artist]
property
Return a list of artists who contributed to the track.
Returns:
Name | Type | Description |
---|---|---|
list |
Artist
|
a list of the artists who contributed to this track |
audio_features: TrackAudioFeatures | None
property
Audio features of the track.
Returns:
Name | Type | Description |
---|---|---|
dict |
TrackAudioFeatures | None
|
the JSON response from the Spotify /audio-features endpoint |
Raises:
Type | Description |
---|---|
HTTPError
|
if |
release_date: date
property
Album release date.
Returns:
Name | Type | Description |
---|---|---|
date |
date
|
the date the track's album was first released |
tempo: float | None
property
Tempo of the track in BPM.
Returns:
Name | Type | Description |
---|---|---|
float |
float | None
|
the tempo of the track, in BPM |
TrackAudioFeatures
Bases: BaseModelWithConfig
Audio feature information for a single track.
Source code in wg_utilities/clients/spotify.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
User
Bases: SpotifyEntity[UserSummaryJson]
A Spotify user, usually just the current user.
Source code in wg_utilities/clients/spotify.py
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 |
|
albums: list[Album]
property
List of albums in the user's library.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Album]
|
a list of albums owned by the current user |
artists: list[Artist]
property
List of artists in the user's library.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Artist]
|
a list of artists owned by the current user |
current_playlist: Playlist | None
property
Get the current playlist for the given user.
Returns:
Name | Type | Description |
---|---|---|
Playlist |
Playlist | None
|
the playlist currently being listened to |
current_track: Track | None
property
Get the currently playing track for the given user.
Returns:
Name | Type | Description |
---|---|---|
Track |
Track | None
|
the track currently being listened to |
devices: list[Device]
property
Return a list of devices that the user currently has access to.
Returns:
Type | Description |
---|---|
list[Device]
|
list[Device]: a list of devices available to the user |
playlists: list[Playlist]
property
Return a list of playlists owned by the current user.
If self.PLAYLIST_REFRESH_INTERVAL has elapsed, a new call to the API will be made to refresh the list of playlists. Only new playlists will be added to the list, preserving previous instances.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Playlist]
|
a list of playlists owned by the current user |
top_artists: tuple[Artist, ...]
property
Top artists for the user.
Returns:
Type | Description |
---|---|
tuple[Artist, ...]
|
tuple[Artist, ...]: the top artists for the user |
top_tracks: tuple[Track, ...]
property
The top tracks for the user.
Returns:
Type | Description |
---|---|
tuple[Track, ...]
|
tuple[Track]: the top tracks for the user |
tracks: list[Track]
property
Liked Songs.
Returns:
Name | Type | Description |
---|---|---|
list |
list[Track]
|
a list of tracks owned by the current user |
get_playlists_by_name(name, *, return_all=False)
Get Playlist instance(s) which have the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the target playlist(s) |
required |
return_all |
bool
|
playlist names aren't unique - but most people keep them unique within their own Sequence of playlists. This boolean can be used to return either a list of all matching playlists, or just the single found playlist |
False
|
Returns:
Name | Type | Description |
---|---|---|
Union |
[list, Playlist]
|
the matched playlist(s) |
Source code in wg_utilities/clients/spotify.py
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
|
get_recently_liked_tracks(track_limit=100, *, day_limit=0.0)
Get a list of songs which were liked by the current user in the past N days.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track_limit |
int
|
the number of tracks to return |
100
|
day_limit |
float
|
the number of days (N) to go back in time for |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[Track]
|
a list of Track instances |
Source code in wg_utilities/clients/spotify.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 |
|
reset_properties(property_names=None)
Reset all list properties.
Source code in wg_utilities/clients/spotify.py
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 |
|
save(entity)
Save an entity to the user's library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity |
Album | Artist | Playlist | Track
|
the entity to save |
required |
Raises:
Type | Description |
---|---|
TypeError
|
if the entity is not of a supported type |
Source code in wg_utilities/clients/spotify.py
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 |
|
set_user_name_value(value, info)
classmethod
Set the user's name
field to the display name if it is not set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
the display name |
required |
info |
ValidationInfo
|
Object for extra validation information/data. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the display name |
Source code in wg_utilities/clients/spotify.py
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
|
unsave(entity)
Remove an entity from the user's library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity |
Album | Artist | Playlist | Track
|
the entity to remove |
required |
Raises:
Type | Description |
---|---|
TypeError
|
if the entity is not of a supported type |
Source code in wg_utilities/clients/spotify.py
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
|
truelayer
Custom client for interacting with TrueLayer's API.
Account
Bases: TrueLayerEntity
Class for managing individual bank accounts.
Source code in wg_utilities/clients/truelayer.py
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 |
|
overdraft: float | None
property
Overdraft limit for the account.
Returns:
Name | Type | Description |
---|---|---|
float |
float | None
|
the overdraft limit of the account |
validate_account_type(value)
classmethod
Validate account_type
and parse it into an AccountType
instance.
Source code in wg_utilities/clients/truelayer.py
465 466 467 468 469 470 471 472 473 474 475 |
|
AccountJson
Bases: _TrueLayerBaseEntityJson
JSON representation of a TrueLayer Account.
Source code in wg_utilities/clients/truelayer.py
153 154 155 156 157 |
|
AccountType
Bases: StrEnum
Possible TrueLayer account types.
Source code in wg_utilities/clients/truelayer.py
35 36 37 38 39 40 41 |
|
BalanceVariables
Bases: BaseModelWithConfig
Variables for an account's balance summary.
Source code in wg_utilities/clients/truelayer.py
171 172 173 174 175 176 177 178 179 180 181 |
|
Bank
Bases: StrEnum
Enum for all banks supported by TrueLayer.
Source code in wg_utilities/clients/truelayer.py
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 |
|
Card
Bases: TrueLayerEntity
Class for managing individual cards.
Source code in wg_utilities/clients/truelayer.py
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 |
|
credit_limit: float | None
property
Credit limit of the account.
Returns:
Name | Type | Description |
---|---|---|
float |
float | None
|
the credit limit available to the customer |
last_statement_balance: float | None
property
Balance of the account at the last statement date.
Returns:
Name | Type | Description |
---|---|---|
float |
float | None
|
the balance on the last statement |
last_statement_date: date | None
property
Date of the last statement.
Returns:
Name | Type | Description |
---|---|---|
date |
date | None
|
the date the last statement was issued on |
payment_due: float | None
property
Amount due on the next statement.
Returns:
Name | Type | Description |
---|---|---|
float |
float | None
|
the amount of any due payment |
payment_due_date: date | None
property
Date of the next statement.
Returns:
Name | Type | Description |
---|---|---|
date |
date | None
|
the date on which the next payment is due |
CardJson
Bases: _TrueLayerBaseEntityJson
JSON representation of a Card.
Source code in wg_utilities/clients/truelayer.py
160 161 162 163 164 165 166 167 168 |
|
Transaction
Bases: BaseModelWithConfig
Class for individual transactions for data manipulation etc.
Source code in wg_utilities/clients/truelayer.py
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 |
|
__str__()
Return a string representation of the transaction.
Source code in wg_utilities/clients/truelayer.py
447 448 449 |
|
validate_transaction_category(v)
classmethod
Validate the transaction category.
The default Enum assignment doesn't work for some reason, so we have to do it here.
This also helps to provide a meaningful error message if the category is invalid; Pydantic's doesn't include the invalid value unfortunately.
Source code in wg_utilities/clients/truelayer.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
TransactionCategory
Bases: Enum
Enum for TrueLayer transaction types.
init method is overridden to allow setting a description as well as the main value.
Source code in wg_utilities/clients/truelayer.py
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 |
|
TrueLayerClient
Bases: OAuthClient[dict[Literal['results'], list[TrueLayerEntityJson]]]
Custom client for interacting with TrueLayer's APIs.
Source code in wg_utilities/clients/truelayer.py
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 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
|
get_account_by_id(account_id)
Get an Account instance based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
account_id |
str
|
the ID of the card |
required |
Returns:
Name | Type | Description |
---|---|---|
Account |
Account | None
|
an Account instance, with all relevant info |
Source code in wg_utilities/clients/truelayer.py
687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
get_card_by_id(card_id)
Get a Card instance based on the ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
card_id |
str
|
the ID of the card |
required |
Returns:
Name | Type | Description |
---|---|---|
Card |
Card | None
|
a Card instance, with all relevant info |
Source code in wg_utilities/clients/truelayer.py
701 702 703 704 705 706 707 708 709 710 711 712 713 |
|
list_accounts()
List all accounts under the given bank account.
Returns:
Type | Description |
---|---|
list[Account]
|
list[Account]: Account instances, containing all related info |
Source code in wg_utilities/clients/truelayer.py
715 716 717 718 719 720 721 |
|
list_cards()
List all accounts under the given bank account.
Returns:
Type | Description |
---|---|
list[Card]
|
list[Account]: Account instances, containing all related info |
Source code in wg_utilities/clients/truelayer.py
723 724 725 726 727 728 729 |
|
TrueLayerEntity
Bases: BaseModelWithConfig
Parent class for all TrueLayer entities (accounts, cards, etc.).
Source code in wg_utilities/clients/truelayer.py
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 |
|
available_balance: float | None
property
Available balance for the entity.
Returns:
Name | Type | Description |
---|---|---|
float |
float | None
|
the amount of money available to the bank account holder |
balance: float
property
Get the available balance, or current if available is not available.
current_balance: float
property
Current balance of the account.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the total amount of money in the account, including pending transactions |
__str__()
Return a string representation of the entity.
Source code in wg_utilities/clients/truelayer.py
409 410 411 |
|
from_json_response(value, *, truelayer_client)
classmethod
Create an account from a JSON response.
Source code in wg_utilities/clients/truelayer.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
get_transactions(from_datetime=None, to_datetime=None)
Get transactions for this entity.
Polls the TL API to get all transactions under the given entity. If only one datetime parameter is provided, then the other is given a default value which maximises the range of results returned
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_datetime |
datetime
|
lower range of transaction date range query |
None
|
to_datetime |
datetime
|
upper range of transaction date range query |
None
|
Returns:
Type | Description |
---|---|
list[Transaction]
|
list[Transaction]: one instance per tx, including all metadata etc. |
Source code in wg_utilities/clients/truelayer.py
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 |
|
update_balance_values()
Update the balance-related instance attributes.
Uses the latest values from the API. This is called automatically when
the balance-related attributes are accessed (if the attribute is None or
was updated more than self.balance_update_threshold
minutes ago), but
can also be called manually.
Source code in wg_utilities/clients/truelayer.py
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 |
|