lunchmoney-python-async 2.10.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. lunchmoney/__init__.py +205 -0
  2. lunchmoney/api/__init__.py +16 -0
  3. lunchmoney/api/categories_api.py +1499 -0
  4. lunchmoney/api/manual_accounts_api.py +1479 -0
  5. lunchmoney/api/me_api.py +293 -0
  6. lunchmoney/api/plaid_accounts_api.py +909 -0
  7. lunchmoney/api/recurring_items_api.py +702 -0
  8. lunchmoney/api/summary_api.py +434 -0
  9. lunchmoney/api/tags_api.py +1465 -0
  10. lunchmoney/api/transactions_api.py +914 -0
  11. lunchmoney/api/transactions_bulk_api.py +1527 -0
  12. lunchmoney/api/transactions_files_api.py +891 -0
  13. lunchmoney/api/transactions_group_api.py +601 -0
  14. lunchmoney/api/transactions_split_api.py +616 -0
  15. lunchmoney/api_client.py +808 -0
  16. lunchmoney/api_response.py +21 -0
  17. lunchmoney/configuration.py +616 -0
  18. lunchmoney/exceptions.py +217 -0
  19. lunchmoney/models/__init__.py +84 -0
  20. lunchmoney/models/account_type_enum.py +46 -0
  21. lunchmoney/models/aligned_category_totals_object.py +108 -0
  22. lunchmoney/models/aligned_summary_category_object.py +110 -0
  23. lunchmoney/models/aligned_summary_response_object.py +104 -0
  24. lunchmoney/models/category_object.py +146 -0
  25. lunchmoney/models/child_category_object.py +141 -0
  26. lunchmoney/models/child_transaction_object.py +219 -0
  27. lunchmoney/models/create_category_request_object.py +137 -0
  28. lunchmoney/models/create_category_request_object_children_inner.py +159 -0
  29. lunchmoney/models/create_manual_account_request_object.py +138 -0
  30. lunchmoney/models/create_manual_account_request_object_balance.py +145 -0
  31. lunchmoney/models/create_new_transactions_request.py +103 -0
  32. lunchmoney/models/create_tag_request_object.py +112 -0
  33. lunchmoney/models/currency_enum.py +198 -0
  34. lunchmoney/models/delete_category_response_with_dependencies.py +94 -0
  35. lunchmoney/models/delete_category_response_with_dependencies_dependents.py +98 -0
  36. lunchmoney/models/delete_tag_response_with_dependencies.py +94 -0
  37. lunchmoney/models/delete_tag_response_with_dependencies_dependents.py +90 -0
  38. lunchmoney/models/delete_transactions_request.py +89 -0
  39. lunchmoney/models/error_response_object.py +98 -0
  40. lunchmoney/models/error_response_object_errors_inner.py +101 -0
  41. lunchmoney/models/get_all_categories200_response.py +96 -0
  42. lunchmoney/models/get_all_manual_accounts200_response.py +96 -0
  43. lunchmoney/models/get_all_plaid_accounts200_response.py +96 -0
  44. lunchmoney/models/get_all_recurring200_response.py +96 -0
  45. lunchmoney/models/get_all_tags200_response.py +96 -0
  46. lunchmoney/models/get_all_transactions200_response.py +100 -0
  47. lunchmoney/models/get_all_transactions_created_since_parameter.py +145 -0
  48. lunchmoney/models/get_budget_summary200_response.py +138 -0
  49. lunchmoney/models/get_transaction_attachment_url200_response.py +91 -0
  50. lunchmoney/models/group_transactions_request.py +122 -0
  51. lunchmoney/models/insert_transaction_object.py +164 -0
  52. lunchmoney/models/insert_transaction_object_amount.py +145 -0
  53. lunchmoney/models/insert_transactions_response_object.py +106 -0
  54. lunchmoney/models/manual_account_object.py +158 -0
  55. lunchmoney/models/non_aligned_category_totals_object.py +94 -0
  56. lunchmoney/models/non_aligned_summary_category_object.py +94 -0
  57. lunchmoney/models/non_aligned_summary_response_object.py +104 -0
  58. lunchmoney/models/plaid_account_object.py +168 -0
  59. lunchmoney/models/recurring_object.py +143 -0
  60. lunchmoney/models/recurring_object_matches.py +105 -0
  61. lunchmoney/models/recurring_object_matches_found_transactions_inner.py +91 -0
  62. lunchmoney/models/recurring_object_overrides.py +92 -0
  63. lunchmoney/models/recurring_object_transaction_criteria.py +149 -0
  64. lunchmoney/models/skipped_existing_external_id_object.py +108 -0
  65. lunchmoney/models/split_transaction_object.py +102 -0
  66. lunchmoney/models/split_transaction_object_amount.py +145 -0
  67. lunchmoney/models/split_transaction_request.py +97 -0
  68. lunchmoney/models/summary_category_occurrence_object.py +126 -0
  69. lunchmoney/models/summary_recurring_transaction_object.py +100 -0
  70. lunchmoney/models/summary_rollover_pool_adjustment_object.py +98 -0
  71. lunchmoney/models/summary_rollover_pool_object.py +98 -0
  72. lunchmoney/models/summary_totals_breakdown_object.py +98 -0
  73. lunchmoney/models/summary_totals_object.py +97 -0
  74. lunchmoney/models/tag_object.py +125 -0
  75. lunchmoney/models/transaction_attachment_object.py +106 -0
  76. lunchmoney/models/transaction_object.py +229 -0
  77. lunchmoney/models/update_category_request_object.py +156 -0
  78. lunchmoney/models/update_manual_account_request_object.py +156 -0
  79. lunchmoney/models/update_manual_account_request_object_balance.py +145 -0
  80. lunchmoney/models/update_tag_request_object.py +126 -0
  81. lunchmoney/models/update_transaction_object.py +228 -0
  82. lunchmoney/models/update_transaction_object_amount.py +145 -0
  83. lunchmoney/models/update_transactions200_response.py +96 -0
  84. lunchmoney/models/update_transactions_request.py +97 -0
  85. lunchmoney/models/update_transactions_request_transactions_inner.py +228 -0
  86. lunchmoney/models/user_object.py +106 -0
  87. lunchmoney/py.typed +0 -0
  88. lunchmoney/rest.py +195 -0
  89. lunchmoney_python_async-2.10.0.dist-info/METADATA +287 -0
  90. lunchmoney_python_async-2.10.0.dist-info/RECORD +92 -0
  91. lunchmoney_python_async-2.10.0.dist-info/WHEEL +5 -0
  92. lunchmoney_python_async-2.10.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+ class ApiResponse(BaseModel, Generic[T]):
10
+ """
11
+ API response object
12
+ """
13
+
14
+ status_code: StrictInt = Field(description="HTTP status code")
15
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
+ data: T = Field(description="Deserialized data given the data type")
17
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
+
19
+ model_config = {
20
+ "arbitrary_types_allowed": True
21
+ }
@@ -0,0 +1,616 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Lunch Money API - v2
5
+
6
+ Welcome to the Lunch Money v2 API. A working version of this API is now available through these docs, or directly at: `https://api.lunchmoney.dev/v2` <span class=\"red-text\"><strong>This is in alpha launch of a major API update. It is still subject to change during this alpha review period and bugs may still exist. Users are strongly encouraged to use the mock service or to create a test budget with example data as the first step to interacting with the v2 API.</strong></span> See the [Getting Started Guide](https://alpha.lunchmoney.dev/v2/getting-started) for more information on using a test budget.<br<br> If you are new to the v2 API, you may wish to review the [v2 API Overview of Changes](https://alpha.lunchmoney.dev/v2/changelog). ### Static Mock Server You may also use these docs to explore the API using a static mock server endpoint.<p> This enables users to become familiar with the API without having to create an access token, and eliminates the possibility of modifying real data. <p> To access this endpoint select the second endpoint in the the \"Server\" dropdown to the right. When selected you should see \"Static Mock v2 Lunch Money API Server\".<br> When using this server, set your Bearer token to any string with 11 or more characters. ### Migrating from V1 The v2 API is NOT backwards compatible with the v1 API. Developers are encouraged to review the [Migration Guide](https://alpha.lunchmoney.dev/v2/migration-guide) to understand the changes and plan their migration. ### Acknowledgments If you have been providing feedback on the API during our iterative design process, **THANK YOU**. We are happy to provide the opportunity to finally interact with the working API that was built based on your feedback. ### Useful links: - [Getting Started](https://alpha.lunchmoney.dev/v2/getting-started) - [v2 API Changelog](https://alpha.lunchmoney.dev/v2/changelog) - [Migration Guide](https://alpha.lunchmoney.dev/v2/migration-guide) - [Rate Limits](https://alpha.lunchmoney.dev/v2/rate-limits) - [Current v1 Lunch Money API Documentation](https://lunchmoney.dev) - [Awesome Lunch Money Projects](https://github.com/lunch-money/awesome-lunchmoney?tab=readme-ov-file)
7
+
8
+ The version of the OpenAPI document: 2.8.4
9
+ Contact: devsupport@lunchmoney.app
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ import copy
17
+ import http.client as httplib
18
+ import logging
19
+ from logging import FileHandler
20
+ import sys
21
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
22
+ from typing_extensions import NotRequired, Self
23
+
24
+ import urllib3
25
+
26
+
27
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
28
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
29
+ 'minimum', 'exclusiveMinimum', 'maxLength',
30
+ 'minLength', 'pattern', 'maxItems', 'minItems'
31
+ }
32
+
33
+ ServerVariablesT = Dict[str, str]
34
+
35
+ GenericAuthSetting = TypedDict(
36
+ "GenericAuthSetting",
37
+ {
38
+ "type": str,
39
+ "in": str,
40
+ "key": str,
41
+ "value": str,
42
+ },
43
+ )
44
+
45
+
46
+ OAuth2AuthSetting = TypedDict(
47
+ "OAuth2AuthSetting",
48
+ {
49
+ "type": Literal["oauth2"],
50
+ "in": Literal["header"],
51
+ "key": Literal["Authorization"],
52
+ "value": str,
53
+ },
54
+ )
55
+
56
+
57
+ APIKeyAuthSetting = TypedDict(
58
+ "APIKeyAuthSetting",
59
+ {
60
+ "type": Literal["api_key"],
61
+ "in": str,
62
+ "key": str,
63
+ "value": Optional[str],
64
+ },
65
+ )
66
+
67
+
68
+ BasicAuthSetting = TypedDict(
69
+ "BasicAuthSetting",
70
+ {
71
+ "type": Literal["basic"],
72
+ "in": Literal["header"],
73
+ "key": Literal["Authorization"],
74
+ "value": Optional[str],
75
+ },
76
+ )
77
+
78
+
79
+ BearerFormatAuthSetting = TypedDict(
80
+ "BearerFormatAuthSetting",
81
+ {
82
+ "type": Literal["bearer"],
83
+ "in": Literal["header"],
84
+ "format": Literal["JWT"],
85
+ "key": Literal["Authorization"],
86
+ "value": str,
87
+ },
88
+ )
89
+
90
+
91
+ BearerAuthSetting = TypedDict(
92
+ "BearerAuthSetting",
93
+ {
94
+ "type": Literal["bearer"],
95
+ "in": Literal["header"],
96
+ "key": Literal["Authorization"],
97
+ "value": str,
98
+ },
99
+ )
100
+
101
+
102
+ HTTPSignatureAuthSetting = TypedDict(
103
+ "HTTPSignatureAuthSetting",
104
+ {
105
+ "type": Literal["http-signature"],
106
+ "in": Literal["header"],
107
+ "key": Literal["Authorization"],
108
+ "value": None,
109
+ },
110
+ )
111
+
112
+
113
+ AuthSettings = TypedDict(
114
+ "AuthSettings",
115
+ {
116
+ "bearerSecurity": BearerFormatAuthSetting,
117
+ "cookieAuth": APIKeyAuthSetting,
118
+ },
119
+ total=False,
120
+ )
121
+
122
+
123
+ class HostSettingVariable(TypedDict):
124
+ description: str
125
+ default_value: str
126
+ enum_values: List[str]
127
+
128
+
129
+ class HostSetting(TypedDict):
130
+ url: str
131
+ description: str
132
+ variables: NotRequired[Dict[str, HostSettingVariable]]
133
+
134
+
135
+ class Configuration:
136
+ """This class contains various settings of the API client.
137
+
138
+ :param host: Base url.
139
+ :param ignore_operation_servers
140
+ Boolean to ignore operation servers for the API client.
141
+ Config will use `host` as the base url regardless of the operation servers.
142
+ :param api_key: Dict to store API key(s).
143
+ Each entry in the dict specifies an API key.
144
+ The dict key is the name of the security scheme in the OAS specification.
145
+ The dict value is the API key secret.
146
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
147
+ The dict key is the name of the security scheme in the OAS specification.
148
+ The dict value is an API key prefix when generating the auth data.
149
+ :param username: Username for HTTP basic authentication.
150
+ :param password: Password for HTTP basic authentication.
151
+ :param access_token: Access token.
152
+ :param server_index: Index to servers configuration.
153
+ :param server_variables: Mapping with string values to replace variables in
154
+ templated server configuration. The validation of enums is performed for
155
+ variables with defined enum values before.
156
+ :param server_operation_index: Mapping from operation ID to an index to server
157
+ configuration.
158
+ :param server_operation_variables: Mapping from operation ID to a mapping with
159
+ string values to replace variables in templated server configuration.
160
+ The validation of enums is performed for variables with defined enum
161
+ values before.
162
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
163
+ in PEM format.
164
+ :param retries: Number of retries for API requests.
165
+ :param ca_cert_data: verify the peer using concatenated CA certificate data
166
+ in PEM (str) or DER (bytes) format.
167
+ :param cert_file: the path to a client certificate file, for mTLS.
168
+ :param key_file: the path to a client key file, for mTLS.
169
+
170
+ :Example:
171
+
172
+ API Key Authentication Example.
173
+ Given the following security scheme in the OpenAPI specification:
174
+ components:
175
+ securitySchemes:
176
+ cookieAuth: # name for the security scheme
177
+ type: apiKey
178
+ in: cookie
179
+ name: JSESSIONID # cookie name
180
+
181
+ You can programmatically set the cookie:
182
+
183
+ conf = lunchmoney.Configuration(
184
+ api_key={'cookieAuth': 'abc123'}
185
+ api_key_prefix={'cookieAuth': 'JSESSIONID'}
186
+ )
187
+
188
+ The following cookie will be added to the HTTP request:
189
+ Cookie: JSESSIONID abc123
190
+ """
191
+
192
+ _default: ClassVar[Optional[Self]] = None
193
+
194
+ def __init__(
195
+ self,
196
+ host: Optional[str]=None,
197
+ api_key: Optional[Dict[str, str]]=None,
198
+ api_key_prefix: Optional[Dict[str, str]]=None,
199
+ username: Optional[str]=None,
200
+ password: Optional[str]=None,
201
+ access_token: Optional[str]=None,
202
+ server_index: Optional[int]=None,
203
+ server_variables: Optional[ServerVariablesT]=None,
204
+ server_operation_index: Optional[Dict[int, int]]=None,
205
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
206
+ ignore_operation_servers: bool=False,
207
+ ssl_ca_cert: Optional[str]=None,
208
+ retries: Optional[int] = None,
209
+ ca_cert_data: Optional[Union[str, bytes]] = None,
210
+ cert_file: Optional[str]=None,
211
+ key_file: Optional[str]=None,
212
+ *,
213
+ debug: Optional[bool] = None,
214
+ ) -> None:
215
+ """Constructor
216
+ """
217
+ self._base_path = "https://api.lunchmoney.dev/v2" if host is None else host
218
+ """Default Base url
219
+ """
220
+ self.server_index = 0 if server_index is None and host is None else server_index
221
+ self.server_operation_index = server_operation_index or {}
222
+ """Default server index
223
+ """
224
+ self.server_variables = server_variables or {}
225
+ self.server_operation_variables = server_operation_variables or {}
226
+ """Default server variables
227
+ """
228
+ self.ignore_operation_servers = ignore_operation_servers
229
+ """Ignore operation servers
230
+ """
231
+ self.temp_folder_path = None
232
+ """Temp file folder for downloading files
233
+ """
234
+ # Authentication Settings
235
+ self.api_key = {}
236
+ if api_key:
237
+ self.api_key = api_key
238
+ """dict to store API key(s)
239
+ """
240
+ self.api_key_prefix = {}
241
+ if api_key_prefix:
242
+ self.api_key_prefix = api_key_prefix
243
+ """dict to store API prefix (e.g. Bearer)
244
+ """
245
+ self.refresh_api_key_hook = None
246
+ """function hook to refresh API key if expired
247
+ """
248
+ self.username = username
249
+ """Username for HTTP basic authentication
250
+ """
251
+ self.password = password
252
+ """Password for HTTP basic authentication
253
+ """
254
+ self.access_token = access_token
255
+ """Access token
256
+ """
257
+ self.logger = {}
258
+ """Logging Settings
259
+ """
260
+ self.logger["package_logger"] = logging.getLogger("lunchmoney")
261
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
262
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
263
+ """Log format
264
+ """
265
+ self.logger_stream_handler = None
266
+ """Log stream handler
267
+ """
268
+ self.logger_file_handler: Optional[FileHandler] = None
269
+ """Log file handler
270
+ """
271
+ self.logger_file = None
272
+ """Debug file location
273
+ """
274
+ if debug is not None:
275
+ self.debug = debug
276
+ else:
277
+ self.__debug = False
278
+ """Debug switch
279
+ """
280
+
281
+ self.verify_ssl = True
282
+ """SSL/TLS verification
283
+ Set this to false to skip verifying SSL certificate when calling API
284
+ from https server.
285
+ """
286
+ self.ssl_ca_cert = ssl_ca_cert
287
+ """Set this to customize the certificate file to verify the peer.
288
+ """
289
+ self.ca_cert_data = ca_cert_data
290
+ """Set this to verify the peer using PEM (str) or DER (bytes)
291
+ certificate data.
292
+ """
293
+ self.cert_file = cert_file
294
+ """client certificate file
295
+ """
296
+ self.key_file = key_file
297
+ """client key file
298
+ """
299
+ self.assert_hostname = None
300
+ """Set this to True/False to enable/disable SSL hostname verification.
301
+ """
302
+ self.tls_server_name = None
303
+ """SSL/TLS Server Name Indication (SNI)
304
+ Set this to the SNI value expected by the server.
305
+ """
306
+
307
+ self.connection_pool_maxsize = 100
308
+ """This value is passed to the aiohttp to limit simultaneous connections.
309
+ Default values is 100, None means no-limit.
310
+ """
311
+
312
+ self.proxy: Optional[str] = None
313
+ """Proxy URL
314
+ """
315
+ self.proxy_headers = None
316
+ """Proxy headers
317
+ """
318
+ self.safe_chars_for_path_param = ''
319
+ """Safe chars for path_param
320
+ """
321
+ self.retries = retries
322
+ """Adding retries to override urllib3 default value 3
323
+ """
324
+ # Enable client side validation
325
+ self.client_side_validation = True
326
+
327
+ self.socket_options = None
328
+ """Options to pass down to the underlying urllib3 socket
329
+ """
330
+
331
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
332
+ """datetime format
333
+ """
334
+
335
+ self.date_format = "%Y-%m-%d"
336
+ """date format
337
+ """
338
+
339
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
340
+ cls = self.__class__
341
+ result = cls.__new__(cls)
342
+ memo[id(self)] = result
343
+ for k, v in self.__dict__.items():
344
+ if k not in ('logger', 'logger_file_handler'):
345
+ setattr(result, k, copy.deepcopy(v, memo))
346
+ # shallow copy of loggers
347
+ result.logger = copy.copy(self.logger)
348
+ # use setters to configure loggers
349
+ result.logger_file = self.logger_file
350
+ result.debug = self.debug
351
+ return result
352
+
353
+ def __setattr__(self, name: str, value: Any) -> None:
354
+ object.__setattr__(self, name, value)
355
+
356
+ @classmethod
357
+ def set_default(cls, default: Optional[Self]) -> None:
358
+ """Set default instance of configuration.
359
+
360
+ It stores default configuration, which can be
361
+ returned by get_default_copy method.
362
+
363
+ :param default: object of Configuration
364
+ """
365
+ cls._default = default
366
+
367
+ @classmethod
368
+ def get_default_copy(cls) -> Self:
369
+ """Deprecated. Please use `get_default` instead.
370
+
371
+ Deprecated. Please use `get_default` instead.
372
+
373
+ :return: The configuration object.
374
+ """
375
+ return cls.get_default()
376
+
377
+ @classmethod
378
+ def get_default(cls) -> Self:
379
+ """Return the default configuration.
380
+
381
+ This method returns newly created, based on default constructor,
382
+ object of Configuration class or returns a copy of default
383
+ configuration.
384
+
385
+ :return: The configuration object.
386
+ """
387
+ if cls._default is None:
388
+ cls._default = cls()
389
+ return cls._default
390
+
391
+ @property
392
+ def logger_file(self) -> Optional[str]:
393
+ """The logger file.
394
+
395
+ If the logger_file is None, then add stream handler and remove file
396
+ handler. Otherwise, add file handler and remove stream handler.
397
+
398
+ :param value: The logger_file path.
399
+ :type: str
400
+ """
401
+ return self.__logger_file
402
+
403
+ @logger_file.setter
404
+ def logger_file(self, value: Optional[str]) -> None:
405
+ """The logger file.
406
+
407
+ If the logger_file is None, then add stream handler and remove file
408
+ handler. Otherwise, add file handler and remove stream handler.
409
+
410
+ :param value: The logger_file path.
411
+ :type: str
412
+ """
413
+ self.__logger_file = value
414
+ if self.__logger_file:
415
+ # If set logging file,
416
+ # then add file handler and remove stream handler.
417
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
418
+ self.logger_file_handler.setFormatter(self.logger_formatter)
419
+ for _, logger in self.logger.items():
420
+ logger.addHandler(self.logger_file_handler)
421
+
422
+ @property
423
+ def debug(self) -> bool:
424
+ """Debug status
425
+
426
+ :param value: The debug status, True or False.
427
+ :type: bool
428
+ """
429
+ return self.__debug
430
+
431
+ @debug.setter
432
+ def debug(self, value: bool) -> None:
433
+ """Debug status
434
+
435
+ :param value: The debug status, True or False.
436
+ :type: bool
437
+ """
438
+ self.__debug = value
439
+ if self.__debug:
440
+ # if debug status is True, turn on debug logging
441
+ for _, logger in self.logger.items():
442
+ logger.setLevel(logging.DEBUG)
443
+ # turn on httplib debug
444
+ httplib.HTTPConnection.debuglevel = 1
445
+ else:
446
+ # if debug status is False, turn off debug logging,
447
+ # setting log level to default `logging.WARNING`
448
+ for _, logger in self.logger.items():
449
+ logger.setLevel(logging.WARNING)
450
+ # turn off httplib debug
451
+ httplib.HTTPConnection.debuglevel = 0
452
+
453
+ @property
454
+ def logger_format(self) -> str:
455
+ """The logger format.
456
+
457
+ The logger_formatter will be updated when sets logger_format.
458
+
459
+ :param value: The format string.
460
+ :type: str
461
+ """
462
+ return self.__logger_format
463
+
464
+ @logger_format.setter
465
+ def logger_format(self, value: str) -> None:
466
+ """The logger format.
467
+
468
+ The logger_formatter will be updated when sets logger_format.
469
+
470
+ :param value: The format string.
471
+ :type: str
472
+ """
473
+ self.__logger_format = value
474
+ self.logger_formatter = logging.Formatter(self.__logger_format)
475
+
476
+ def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
477
+ """Gets API key (with prefix if set).
478
+
479
+ :param identifier: The identifier of apiKey.
480
+ :param alias: The alternative identifier of apiKey.
481
+ :return: The token for api key authentication.
482
+ """
483
+ if self.refresh_api_key_hook is not None:
484
+ self.refresh_api_key_hook(self)
485
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
486
+ if key:
487
+ prefix = self.api_key_prefix.get(identifier)
488
+ if prefix:
489
+ return "%s %s" % (prefix, key)
490
+ else:
491
+ return key
492
+
493
+ return None
494
+
495
+ def get_basic_auth_token(self) -> Optional[str]:
496
+ """Gets HTTP basic authentication header (string).
497
+
498
+ :return: The token for basic HTTP authentication.
499
+ """
500
+ username = ""
501
+ if self.username is not None:
502
+ username = self.username
503
+ password = ""
504
+ if self.password is not None:
505
+ password = self.password
506
+ return urllib3.util.make_headers(
507
+ basic_auth=username + ':' + password
508
+ ).get('authorization')
509
+
510
+ def auth_settings(self)-> AuthSettings:
511
+ """Gets Auth Settings dict for api client.
512
+
513
+ :return: The Auth Settings information dict.
514
+ """
515
+ auth: AuthSettings = {}
516
+ if self.access_token is not None:
517
+ auth['bearerSecurity'] = {
518
+ 'type': 'bearer',
519
+ 'in': 'header',
520
+ 'format': 'JWT',
521
+ 'key': 'Authorization',
522
+ 'value': 'Bearer ' + self.access_token
523
+ }
524
+ if 'cookieAuth' in self.api_key:
525
+ auth['cookieAuth'] = {
526
+ 'type': 'api_key',
527
+ 'in': 'cookie',
528
+ 'key': '_lm_access_token',
529
+ 'value': self.get_api_key_with_prefix(
530
+ 'cookieAuth',
531
+ ),
532
+ }
533
+ return auth
534
+
535
+ def to_debug_report(self) -> str:
536
+ """Gets the essential information for debugging.
537
+
538
+ :return: The report for debugging.
539
+ """
540
+ return "Python SDK Debug Report:\n"\
541
+ "OS: {env}\n"\
542
+ "Python Version: {pyversion}\n"\
543
+ "Version of the API: 2.8.4\n"\
544
+ "SDK Package Version: 2.10.0".\
545
+ format(env=sys.platform, pyversion=sys.version)
546
+
547
+ def get_host_settings(self) -> List[HostSetting]:
548
+ """Gets an array of host settings
549
+
550
+ :return: An array of host settings
551
+ """
552
+ return [
553
+ {
554
+ 'url': "https://api.lunchmoney.dev/v2",
555
+ 'description': "v2 Lunch Money API Server - modifies real data!",
556
+ },
557
+ {
558
+ 'url': "https://mock.lunchmoney.dev/v2",
559
+ 'description': "Static Mock v2 Lunch Money API Server",
560
+ }
561
+ ]
562
+
563
+ def get_host_from_settings(
564
+ self,
565
+ index: Optional[int],
566
+ variables: Optional[ServerVariablesT]=None,
567
+ servers: Optional[List[HostSetting]]=None,
568
+ ) -> str:
569
+ """Gets host URL based on the index and variables
570
+ :param index: array index of the host settings
571
+ :param variables: hash of variable and the corresponding value
572
+ :param servers: an array of host settings or None
573
+ :return: URL based on host settings
574
+ """
575
+ if index is None:
576
+ return self._base_path
577
+
578
+ variables = {} if variables is None else variables
579
+ servers = self.get_host_settings() if servers is None else servers
580
+
581
+ try:
582
+ server = servers[index]
583
+ except IndexError:
584
+ raise ValueError(
585
+ "Invalid index {0} when selecting the host settings. "
586
+ "Must be less than {1}".format(index, len(servers)))
587
+
588
+ url = server['url']
589
+
590
+ # go through variables and replace placeholders
591
+ for variable_name, variable in server.get('variables', {}).items():
592
+ used_value = variables.get(
593
+ variable_name, variable['default_value'])
594
+
595
+ if 'enum_values' in variable \
596
+ and used_value not in variable['enum_values']:
597
+ raise ValueError(
598
+ "The variable `{0}` in the host URL has invalid value "
599
+ "{1}. Must be {2}.".format(
600
+ variable_name, variables[variable_name],
601
+ variable['enum_values']))
602
+
603
+ url = url.replace("{" + variable_name + "}", used_value)
604
+
605
+ return url
606
+
607
+ @property
608
+ def host(self) -> str:
609
+ """Return generated host."""
610
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
611
+
612
+ @host.setter
613
+ def host(self, value: str) -> None:
614
+ """Fix base path."""
615
+ self._base_path = value
616
+ self.server_index = None