ofxtools 1.0.0__tar.gz → 1.1.0__tar.gz

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 (108) hide show
  1. {ofxtools-1.0.0/ofxtools.egg-info → ofxtools-1.1.0}/PKG-INFO +17 -14
  2. {ofxtools-1.0.0 → ofxtools-1.1.0}/README.rst +13 -13
  3. {ofxtools-1.0.0 → ofxtools-1.1.0}/docs/conf.py +3 -3
  4. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/Client.py +129 -142
  5. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/Parser.py +18 -21
  6. ofxtools-1.1.0/ofxtools/Types.py +671 -0
  7. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/config/__init__.py +8 -5
  8. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/config/fi.cfg +4 -0
  9. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/header.py +8 -16
  10. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/msgsets.py +10 -5
  11. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/stmt.py +10 -8
  12. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/stmtend.py +3 -1
  13. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/base.py +168 -240
  14. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/__init__.py +2 -2
  15. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/common.py +8 -6
  16. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/common.py +2 -3
  17. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/email.py +5 -4
  18. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/i18n.py +10 -9
  19. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/msgsets.py +6 -4
  20. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/securities.py +9 -8
  21. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/stmt.py +12 -13
  22. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/ofx.py +9 -6
  23. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/profile.py +5 -4
  24. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/signon.py +9 -13
  25. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/signup.py +7 -7
  26. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/tax1099.py +23 -21
  27. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/scripts/ofxget.py +87 -57
  28. ofxtools-1.1.0/ofxtools/utils.py +366 -0
  29. {ofxtools-1.0.0 → ofxtools-1.1.0/ofxtools.egg-info}/PKG-INFO +17 -14
  30. {ofxtools-1.0.0 → ofxtools-1.1.0}/pyproject.toml +6 -2
  31. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_client.py +6 -5
  32. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_base.py +44 -28
  33. ofxtools-1.1.0/tests/test_models_i18n.py +100 -0
  34. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_msgsets.py +15 -0
  35. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_ofxget.py +34 -0
  36. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_parser.py +6 -4
  37. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_spec_tax1099.py +36 -0
  38. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_types.py +16 -8
  39. ofxtools-1.1.0/tests/test_utils.py +388 -0
  40. ofxtools-1.0.0/ofxtools/Types.py +0 -821
  41. ofxtools-1.0.0/ofxtools/utils.py +0 -406
  42. ofxtools-1.0.0/tests/test_models_i18n.py +0 -52
  43. ofxtools-1.0.0/tests/test_utils.py +0 -96
  44. {ofxtools-1.0.0 → ofxtools-1.1.0}/LICENSE +0 -0
  45. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/__init__.py +0 -0
  46. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/config/ofxget_example.cfg +0 -0
  47. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/lib.py +0 -0
  48. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/__init__.py +0 -0
  49. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/__init__.py +0 -0
  50. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/interxfer.py +0 -0
  51. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/mail.py +0 -0
  52. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/recur.py +0 -0
  53. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/stpchk.py +0 -0
  54. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/sync.py +0 -0
  55. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/wire.py +0 -0
  56. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/bank/xfer.py +0 -0
  57. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/list.py +0 -0
  58. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/mail.py +0 -0
  59. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/msgsets.py +0 -0
  60. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/pmt.py +0 -0
  61. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/recur.py +0 -0
  62. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/billpay/sync.py +0 -0
  63. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/__init__.py +0 -0
  64. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/acct.py +0 -0
  65. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/mail.py +0 -0
  66. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/openorders.py +0 -0
  67. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/positions.py +0 -0
  68. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/invest/transactions.py +0 -0
  69. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/models/wrapperbases.py +0 -0
  70. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/py.typed +0 -0
  71. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools/scripts/__init__.py +0 -0
  72. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools.egg-info/SOURCES.txt +0 -0
  73. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools.egg-info/dependency_links.txt +0 -0
  74. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools.egg-info/entry_points.txt +0 -0
  75. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools.egg-info/requires.txt +0 -0
  76. {ofxtools-1.0.0 → ofxtools-1.1.0}/ofxtools.egg-info/top_level.txt +0 -0
  77. {ofxtools-1.0.0 → ofxtools-1.1.0}/setup.cfg +0 -0
  78. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/base.py +0 -0
  79. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_header.py +0 -0
  80. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_interxfer.py +0 -0
  81. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_mail.py +0 -0
  82. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_recur.py +0 -0
  83. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_stmt.py +0 -0
  84. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_stmtend.py +0 -0
  85. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_stpchk.py +0 -0
  86. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_sync.py +0 -0
  87. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_wire.py +0 -0
  88. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_bank_xfer.py +0 -0
  89. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_billpay_common.py +0 -0
  90. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_billpay_list.py +0 -0
  91. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_billpay_mail.py +0 -0
  92. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_billpay_pmt.py +0 -0
  93. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_billpay_recur.py +0 -0
  94. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_billpay_sync.py +0 -0
  95. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_common.py +0 -0
  96. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_email.py +0 -0
  97. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_invest.py +0 -0
  98. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_invest_oo.py +0 -0
  99. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_invest_transactions.py +0 -0
  100. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_ofx.py +0 -0
  101. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_profile.py +0 -0
  102. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_securities.py +0 -0
  103. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_signon.py +0 -0
  104. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_models_signup.py +0 -0
  105. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_spec_bank.py +0 -0
  106. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_spec_billpay.py +0 -0
  107. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_spec_invest.py +0 -0
  108. {ofxtools-1.0.0 → ofxtools-1.1.0}/tests/test_spec_signon.py +0 -0
@@ -1,10 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ofxtools
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: Library for working with Open Financial Exchange (OFX) data
5
5
  Author-email: Christopher Singley <csingley@gmail.com>
6
6
  License-Expression: GPL-3.0-only
7
7
  Project-URL: Homepage, https://github.com/csingley/ofxtools
8
+ Project-URL: Documentation, https://ofxtools.readthedocs.io/
9
+ Project-URL: Source, https://github.com/csingley/ofxtools
10
+ Project-URL: Bug Tracker, https://github.com/csingley/ofxtools/issues
8
11
  Keywords: ofx,Open Financial Exchange
9
12
  Classifier: Development Status :: 5 - Production/Stable
10
13
  Classifier: Intended Audience :: Developers
@@ -51,16 +54,20 @@ Open Financial Exchange (OFX) Tools for Python
51
54
  :target: https://coveralls.io/github/csingley/ofxtools?branch=master
52
55
 
53
56
  .. image:: https://img.shields.io/badge/dependencies-None-green.svg
54
- :target: https://github.com/csingley/ofxtools/blob/master/requirements.txt
57
+ :target: https://github.com/csingley/ofxtools/blob/master/pyproject.toml
55
58
 
56
59
  .. image:: https://badge.fury.io/py/ofxtools.svg
57
60
  :target: https://badge.fury.io/py/ofxtools
58
61
 
62
+ .. image:: https://static.pepy.tech/badge/ofxtools
63
+ :alt: Total PyPI downloads
64
+ :target: https://pepy.tech/projects/ofxtools
65
+
59
66
  ``ofxtools`` is a Python library for working with Open Financial Exchange (OFX)
60
67
  data - the standard format for downloading financial information from banks
61
68
  and stockbrokers. OFX data is widely provided by financial institutions so
62
69
  that their customers can import transactions into financial management
63
- software such as Quicken, Microsoft Money, or GnuCash.
70
+ software such as Quicken or GnuCash.
64
71
 
65
72
  If you want to download your transaction data outside of one of these
66
73
  programs - if you wish to develop a Python application to use this data -
@@ -90,15 +97,15 @@ It targets compliance with the `OFX specification`_, specifically OFX versions
90
97
  * Section 11 (banking)
91
98
  * Section 12 (bill pay)
92
99
  * Section 13 (investments)
100
+ * OFX tax extensions (1099 forms)
93
101
 
94
102
  This should cover the great majority of real-world OFX use cases. A particular
95
103
  focus of ``ofxtools`` is full support of the OFX investment message set,
96
104
  which has been somewhat neglected by the Python community.
97
105
 
98
- The major item remaining on the ``ofxtools`` "to do" list is to implement the
99
- tax schemas. It's currently a low priority to implement Section 14 (bill
100
- presentment) or the extensions contained in OFX versions beyond 2.03, but
101
- you're welcome to contribute code if you need these.
106
+ It's currently a low priority to implement Section 14 (bill presentment) or
107
+ the extensions contained in OFX versions beyond 2.03, but you're welcome to
108
+ contribute code if you need these.
102
109
 
103
110
  Some care has been taken with the data model to make it easily maintainable
104
111
  and extensible. The ``ofxtools.models`` subpackage contains simple, direct
@@ -121,16 +128,12 @@ a `bug tracker`_.
121
128
 
122
129
  Installation Dependencies
123
130
  -------------------------
124
- ``ofxtools`` requires Python version 3.8+, and depends only on the standard
125
- libary (no external dependencies).
126
-
127
- **NOTE: As of version 0.6, ofxtools no longer supports Python version 2,
128
- which went EOL 2020-01-01.**
131
+ ``ofxtools`` requires Python version 3.10+, and depends only on the standard
132
+ library (no external dependencies).
129
133
 
130
134
 
131
135
  .. _OFX specification: https://financialdataexchange.org/ofx
132
- .. _Requests: http://docs.python-requests.org/en/master/
133
136
  .. _Read the Docs: https://ofxtools.readthedocs.io/
134
137
  .. _GitHub: https://github.com/csingley/ofxtools
135
138
  .. _bug tracker: https://github.com/csingley/ofxtools/issues
136
- .. _PyPI: https://pypi.python.org/pypi/ofxtools
139
+ .. _PyPI: https://pypi.org/project/ofxtools/
@@ -9,16 +9,20 @@ Open Financial Exchange (OFX) Tools for Python
9
9
  :target: https://coveralls.io/github/csingley/ofxtools?branch=master
10
10
 
11
11
  .. image:: https://img.shields.io/badge/dependencies-None-green.svg
12
- :target: https://github.com/csingley/ofxtools/blob/master/requirements.txt
12
+ :target: https://github.com/csingley/ofxtools/blob/master/pyproject.toml
13
13
 
14
14
  .. image:: https://badge.fury.io/py/ofxtools.svg
15
15
  :target: https://badge.fury.io/py/ofxtools
16
16
 
17
+ .. image:: https://static.pepy.tech/badge/ofxtools
18
+ :alt: Total PyPI downloads
19
+ :target: https://pepy.tech/projects/ofxtools
20
+
17
21
  ``ofxtools`` is a Python library for working with Open Financial Exchange (OFX)
18
22
  data - the standard format for downloading financial information from banks
19
23
  and stockbrokers. OFX data is widely provided by financial institutions so
20
24
  that their customers can import transactions into financial management
21
- software such as Quicken, Microsoft Money, or GnuCash.
25
+ software such as Quicken or GnuCash.
22
26
 
23
27
  If you want to download your transaction data outside of one of these
24
28
  programs - if you wish to develop a Python application to use this data -
@@ -48,15 +52,15 @@ It targets compliance with the `OFX specification`_, specifically OFX versions
48
52
  * Section 11 (banking)
49
53
  * Section 12 (bill pay)
50
54
  * Section 13 (investments)
55
+ * OFX tax extensions (1099 forms)
51
56
 
52
57
  This should cover the great majority of real-world OFX use cases. A particular
53
58
  focus of ``ofxtools`` is full support of the OFX investment message set,
54
59
  which has been somewhat neglected by the Python community.
55
60
 
56
- The major item remaining on the ``ofxtools`` "to do" list is to implement the
57
- tax schemas. It's currently a low priority to implement Section 14 (bill
58
- presentment) or the extensions contained in OFX versions beyond 2.03, but
59
- you're welcome to contribute code if you need these.
61
+ It's currently a low priority to implement Section 14 (bill presentment) or
62
+ the extensions contained in OFX versions beyond 2.03, but you're welcome to
63
+ contribute code if you need these.
60
64
 
61
65
  Some care has been taken with the data model to make it easily maintainable
62
66
  and extensible. The ``ofxtools.models`` subpackage contains simple, direct
@@ -79,16 +83,12 @@ a `bug tracker`_.
79
83
 
80
84
  Installation Dependencies
81
85
  -------------------------
82
- ``ofxtools`` requires Python version 3.8+, and depends only on the standard
83
- libary (no external dependencies).
84
-
85
- **NOTE: As of version 0.6, ofxtools no longer supports Python version 2,
86
- which went EOL 2020-01-01.**
86
+ ``ofxtools`` requires Python version 3.10+, and depends only on the standard
87
+ library (no external dependencies).
87
88
 
88
89
 
89
90
  .. _OFX specification: https://financialdataexchange.org/ofx
90
- .. _Requests: http://docs.python-requests.org/en/master/
91
91
  .. _Read the Docs: https://ofxtools.readthedocs.io/
92
92
  .. _GitHub: https://github.com/csingley/ofxtools
93
93
  .. _bug tracker: https://github.com/csingley/ofxtools/issues
94
- .. _PyPI: https://pypi.python.org/pypi/ofxtools
94
+ .. _PyPI: https://pypi.org/project/ofxtools/
@@ -10,7 +10,7 @@ _meta = metadata("ofxtools")
10
10
  # -- Project information -----------------------------------------------------
11
11
  project = _meta["Name"]
12
12
  author = _meta["Author-email"].split("<")[0].strip()
13
- copyright = f"2010 {author}"
13
+ copyright = f"2010–2026 {author}"
14
14
  version = release = _meta["Version"]
15
15
 
16
16
 
@@ -20,14 +20,14 @@ extensions = []
20
20
  templates_path = ["_templates"]
21
21
  source_suffix = ".rst"
22
22
  master_doc = "index"
23
- language = None
23
+ language = "en"
24
24
  exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
25
25
  pygments_style = None
26
26
 
27
27
 
28
28
  # -- Options for HTML output -------------------------------------------------
29
29
 
30
- html_theme = "sphinxdoc"
30
+ html_theme = "sphinx_rtd_theme"
31
31
  html_static_path = ["_static"]
32
32
 
33
33
 
@@ -52,11 +52,11 @@ import logging
52
52
  import urllib.request as urllib_request
53
53
  import uuid
54
54
  import xml.etree.ElementTree as ET
55
- from collections.abc import Iterator
56
- from functools import singledispatch
55
+ from collections.abc import Iterable, Iterator
57
56
  from io import BytesIO
58
57
  from operator import attrgetter, itemgetter
59
58
  from typing import (
59
+ Any,
60
60
  BinaryIO,
61
61
  NamedTuple,
62
62
  )
@@ -115,9 +115,9 @@ from ofxtools.models.tax1099 import (
115
115
  TAX1099TRNRQ,
116
116
  )
117
117
  from ofxtools.Parser import OFXTree
118
- from ofxtools.utils import UTC, classproperty
118
+ from ofxtools.utils import UTC
119
119
 
120
- AUTH_PLACEHOLDER = "{:0<32}".format("anonymous")
120
+ AUTH_PLACEHOLDER = f"{'anonymous':0<32}"
121
121
 
122
122
 
123
123
  logger = logging.getLogger(__name__)
@@ -187,6 +187,7 @@ class CcStmtEndRq(NamedTuple):
187
187
  # TYPE ALIASES
188
188
  RequestParam = StmtRq | CcStmtRq | InvStmtRq | StmtEndRq | CcStmtEndRq
189
189
  Request = STMTRQ | CCSTMTRQ | INVSTMTRQ | STMTENDRQ | CCSTMTENDRQ
190
+ TrnRequest = STMTTRNRQ | CCSTMTTRNRQ | INVSTMTTRNRQ | STMTENDTRNRQ | CCSTMTENDTRNRQ
190
191
  Message = BANKMSGSRQV1 | CREDITCARDMSGSRQV1 | INVSTMTMSGSRQV1
191
192
  MsgsetClass = (
192
193
  type[SIGNONMSGSET]
@@ -206,7 +207,34 @@ MsgsetClass = (
206
207
 
207
208
  class OFXClient:
208
209
  """
209
- Basic OFX client to download statement and profile requests.
210
+ OFX client that composes, transmits, and receives OFX messages.
211
+
212
+ Configure an instance with the server URL and financial-institution
213
+ parameters (``org``, ``fid``, ``version``, etc.), then call request
214
+ methods such as ``request_statements()`` or ``request_profile()`` to
215
+ retrieve data. Each request method returns a file-like object containing
216
+ the raw OFX response, which can be passed directly to ``OFXTree.parse()``.
217
+
218
+ Statement requests are described by lightweight named-tuple containers:
219
+ ``StmtRq``, ``CcStmtRq``, ``InvStmtRq``, ``StmtEndRq``, ``CcStmtEndRq``.
220
+
221
+ Example::
222
+
223
+ from ofxtools.Client import OFXClient, StmtRq
224
+ import ofxtools.utils
225
+
226
+ client = OFXClient(
227
+ "https://ofx.example.com",
228
+ userid="jsmith",
229
+ org="MYBANK",
230
+ fid="12345",
231
+ version=220,
232
+ bankid="111000614",
233
+ )
234
+ import datetime
235
+ dtstart = datetime.datetime(2024, 1, 1, tzinfo=ofxtools.utils.UTC)
236
+ rq = StmtRq(acctid="123456789", accttype="CHECKING", dtstart=dtstart)
237
+ response = client.request_statements("s3cr3t", rq)
210
238
  """
211
239
 
212
240
  # OFX header/signon defaults
@@ -288,14 +316,9 @@ class OFXClient:
288
316
  # subsequent STMTRQ or what have you.
289
317
  self.cookiejar = http.cookiejar.CookieJar()
290
318
 
291
- @classproperty
292
319
  @classmethod
293
320
  def uuid(cls) -> str:
294
- """
295
- Return a new UUID each time called.
296
-
297
- Wrapper we can mock for testing.
298
- """
321
+ """Return a new UUID each time called. Wrapper we can mock for testing."""
299
322
  return str(uuid.uuid4()).upper()
300
323
 
301
324
  @property
@@ -320,6 +343,25 @@ class OFXClient:
320
343
  """
321
344
  return datetime.datetime.now(UTC)
322
345
 
346
+ def _url_from_profile(
347
+ self,
348
+ dryrun: bool,
349
+ skip_profile: bool,
350
+ timeout: float | None,
351
+ gen_newfileuid: bool,
352
+ ) -> str:
353
+ if dryrun:
354
+ return ""
355
+ if skip_profile:
356
+ return self.url
357
+ RqCls2url = self._get_service_urls(
358
+ timeout=timeout, gen_newfileuid=gen_newfileuid
359
+ )
360
+ urls = set(RqCls2url.values())
361
+ if len(urls) != 1:
362
+ raise ValueError(f"Expected 1 service URL, got {len(urls)}: {urls}")
363
+ return str(urls.pop())
364
+
323
365
  def request_statements(
324
366
  self,
325
367
  password: str,
@@ -333,26 +375,9 @@ class OFXClient:
333
375
  Package and send OFX statement requests
334
376
  (STMTRQ/CCSTMTRQ/INVSTMTRQ/STMTENDRQ/CCSTMTENDRQ).
335
377
  """
336
- if dryrun:
337
- url = ""
338
- logger.info("Dry run for statement request")
339
- elif skip_profile:
340
- url = self.url
341
- logger.info(f"Skipping profile request; using url='{url}'")
342
- else:
343
- logger.info("Requesting OFX profile to extract service URLs")
344
- RqCls2url = self._get_service_urls(
345
- timeout=timeout,
346
- gen_newfileuid=gen_newfileuid,
347
- )
348
-
349
- # HACK FIXME
350
- # As a simplification, we assume that FIs handle all classes
351
- # of statement request from a single URL.
352
- urls = set(RqCls2url.values())
353
- assert len(urls) == 1
354
- url = urls.pop()
355
- logger.info(f"Received service url={url} from OFX profile response")
378
+ url = self._url_from_profile(dryrun, skip_profile, timeout, gen_newfileuid)
379
+ if url:
380
+ logger.info(f"Service url={url}")
356
381
 
357
382
  logger.info(f"Creating statement requests for {requests}")
358
383
  # Group requests by type and pass to the appropriate *TRNRQ handler
@@ -373,7 +398,7 @@ class OFXClient:
373
398
  # trnrqs is a pair of (models.*MSGSRQV1, [*TRNRQ])
374
399
  # Can't sort *MSGSRQV1 by class, either, so we use the same trick
375
400
  # of sorting by class name and grouping by class.
376
- def trnSortKey(pair):
401
+ def trnSortKey(pair: Any) -> Any:
377
402
  return pair[0].__name__
378
403
 
379
404
  trnGroupKey = itemgetter(0)
@@ -385,7 +410,7 @@ class OFXClient:
385
410
  msgcls: type[BANKMSGSRQV1]
386
411
  | type[CREDITCARDMSGSRQV1]
387
412
  | type[INVSTMTMSGSRQV1],
388
- trnrqs: Iterator[Request],
413
+ trnrqs: Iterator[tuple[type[Message], list[TrnRequest]]],
389
414
  ) -> tuple[str, Message]:
390
415
  trnrqs_ = list(itertools.chain.from_iterable(t[1] for t in trnrqs))
391
416
  attr_name = msgcls.__name__.lower()
@@ -400,10 +425,7 @@ class OFXClient:
400
425
  signon = self.signon(password)
401
426
  ofx = OFX(signonmsgsrqv1=signon, **msgs)
402
427
 
403
- if gen_newfileuid:
404
- newfileuid = self.uuid
405
- else:
406
- newfileuid = None
428
+ newfileuid = self.uuid() if gen_newfileuid else None
407
429
 
408
430
  return self.download(
409
431
  ofx,
@@ -417,7 +439,7 @@ class OFXClient:
417
439
  self,
418
440
  timeout: float | None = None,
419
441
  gen_newfileuid: bool = True,
420
- ) -> dict:
442
+ ) -> dict[Any, Any]:
421
443
  """Query OFX profile endpoint to construct mapping of statement request
422
444
  data container to URL providing that service.
423
445
  """
@@ -445,7 +467,7 @@ class OFXClient:
445
467
  def map_stmtendrq_urls(
446
468
  msgsetCls: MsgsetClass,
447
469
  stmtendrqCls: type[StmtEndRq] | type[CcStmtEndRq],
448
- ):
470
+ ) -> None:
449
471
  try:
450
472
  index = [type(msgset) for msgset in msgsetlist].index(msgsetCls)
451
473
  except ValueError:
@@ -520,12 +542,19 @@ class OFXClient:
520
542
  # aggregate <PROFTRNRS>.
521
543
  proftrnrs = ofx.profmsgsrsv1[0]
522
544
  if proftrnrs.status.code == 1:
523
- assert profrs is not None
545
+ if profrs is None:
546
+ raise ValueError("Profile response required but not provided")
524
547
  response = profrs
525
548
  else:
526
- assert proftrnrs.status.code == 0
549
+ if proftrnrs.status.code != 0:
550
+ raise ValueError(
551
+ f"Profile response status code {proftrnrs.status.code}"
552
+ )
527
553
  dtprofup_server = proftrnrs.profrs.dtprofup
528
- assert dtprofup is None or dtprofup <= dtprofup_server
554
+ if dtprofup is not None and dtprofup > dtprofup_server:
555
+ raise ValueError(
556
+ f"Profile update date {dtprofup} is newer than server's {dtprofup_server}"
557
+ )
529
558
 
530
559
  # Cache the updated PROFRS sent by the server
531
560
  response.seek(0)
@@ -554,7 +583,7 @@ class OFXClient:
554
583
  if dtprofup is None:
555
584
  dtprofup = datetime.datetime(1990, 1, 1, tzinfo=UTC)
556
585
  profrq = PROFRQ(clientrouting="NONE", dtprofup=dtprofup)
557
- proftrnrq = PROFTRNRQ(trnuid=self.uuid, profrq=profrq)
586
+ proftrnrq = PROFTRNRQ(trnuid=self.uuid(), profrq=profrq)
558
587
 
559
588
  logger.debug(f"Wrapped profile request: {proftrnrq}")
560
589
 
@@ -563,10 +592,7 @@ class OFXClient:
563
592
 
564
593
  ofx = OFX(signonmsgsrqv1=signon, profmsgsrqv1=PROFMSGSRQV1(proftrnrq))
565
594
 
566
- if gen_newfileuid:
567
- newfileuid = self.uuid
568
- else:
569
- newfileuid = None
595
+ newfileuid = self.uuid() if gen_newfileuid else None
570
596
 
571
597
  return self.download(
572
598
  ofx,
@@ -592,38 +618,19 @@ class OFXClient:
592
618
  """
593
619
  Package and send OFX account info requests (ACCTINFORQ)
594
620
  """
595
- if dryrun:
596
- url = ""
597
- elif skip_profile:
598
- url = self.url
599
- else:
600
- RqCls2url = self._get_service_urls(
601
- timeout=timeout,
602
- gen_newfileuid=gen_newfileuid,
603
- )
604
-
605
- # HACK FIXME
606
- # As a simplification, we assume that FIs handle all classes
607
- # of statement request from a single URL.
608
- urls = set(RqCls2url.values())
609
- assert len(urls) == 1
610
- url = urls.pop()
611
-
621
+ url = self._url_from_profile(dryrun, skip_profile, timeout, gen_newfileuid)
612
622
  logger.info("Creating account info request")
613
623
  signon = self.signon(password)
614
624
 
615
625
  acctinforq = ACCTINFORQ(dtacctup=dtacctup)
616
- acctinfotrnrq = ACCTINFOTRNRQ(trnuid=self.uuid, acctinforq=acctinforq)
626
+ acctinfotrnrq = ACCTINFOTRNRQ(trnuid=self.uuid(), acctinforq=acctinforq)
617
627
  msgs = SIGNUPMSGSRQV1(acctinfotrnrq)
618
628
 
619
629
  logger.debug(f"Wrapped account info request messages: {msgs}")
620
630
 
621
631
  ofx = OFX(signonmsgsrqv1=signon, signupmsgsrqv1=msgs)
622
632
 
623
- if gen_newfileuid:
624
- newfileuid = self.uuid
625
- else:
626
- newfileuid = None
633
+ newfileuid = self.uuid() if gen_newfileuid else None
627
634
 
628
635
  return self.download(
629
636
  ofx,
@@ -647,37 +654,18 @@ class OFXClient:
647
654
  """
648
655
  Request US federal income tax form 1099 (TAX1099RQ)
649
656
  """
650
- if dryrun:
651
- url = ""
652
- elif skip_profile:
653
- url = self.url
654
- else:
655
- RqCls2url = self._get_service_urls(
656
- timeout=timeout,
657
- gen_newfileuid=gen_newfileuid,
658
- )
659
-
660
- # HACK FIXME
661
- # As a simplification, we assume that FIs handle all classes
662
- # of statement request from a single URL.
663
- urls = set(RqCls2url.values())
664
- assert len(urls) == 1
665
- url = urls.pop()
666
-
657
+ url = self._url_from_profile(dryrun, skip_profile, timeout, gen_newfileuid)
667
658
  logger.info("Creating tax 1099 request")
668
659
  signon = self.signon(password)
669
660
 
670
661
  rq = TAX1099RQ(*taxyears, recid=recid or None)
671
- msgs = TAX1099MSGSRQV1(TAX1099TRNRQ(trnuid=self.uuid, tax1099rq=rq))
662
+ msgs = TAX1099MSGSRQV1(TAX1099TRNRQ(trnuid=self.uuid(), tax1099rq=rq))
672
663
 
673
664
  logger.debug(f"Wrapped tax 1099 request messages: {msgs}")
674
665
 
675
666
  ofx = OFX(signonmsgsrqv1=signon, tax1099msgsrqv1=msgs)
676
667
 
677
- if gen_newfileuid:
678
- newfileuid = self.uuid
679
- else:
680
- newfileuid = None
668
+ newfileuid = self.uuid() if gen_newfileuid else None
681
669
 
682
670
  return self.download(
683
671
  ofx,
@@ -734,7 +722,7 @@ class OFXClient:
734
722
  acct = BANKACCTFROM(bankid=bankid, acctid=acctid, accttype=accttype)
735
723
  inctran_ = INCTRAN(dtstart=dtstart, dtend=dtend, include=inctran)
736
724
  stmtrq = STMTRQ(bankacctfrom=acct, inctran=inctran_)
737
- trnuid = self.uuid
725
+ trnuid = self.uuid()
738
726
  return STMTTRNRQ(trnuid=trnuid, stmtrq=stmtrq)
739
727
 
740
728
  def stmtendtrnrq(
@@ -748,7 +736,7 @@ class OFXClient:
748
736
  """Construct STMTENDRQ; package in STMTENDTRNRQ"""
749
737
  acct = BANKACCTFROM(bankid=bankid, acctid=acctid, accttype=accttype)
750
738
  stmtrq = STMTENDRQ(bankacctfrom=acct, dtstart=dtstart, dtend=dtend)
751
- trnuid = self.uuid
739
+ trnuid = self.uuid()
752
740
  return STMTENDTRNRQ(trnuid=trnuid, stmtendrq=stmtrq)
753
741
 
754
742
  def ccstmttrnrq(
@@ -762,7 +750,7 @@ class OFXClient:
762
750
  acct = CCACCTFROM(acctid=acctid)
763
751
  inctran_ = INCTRAN(dtstart=dtstart, dtend=dtend, include=inctran)
764
752
  stmtrq = CCSTMTRQ(ccacctfrom=acct, inctran=inctran_)
765
- trnuid = self.uuid
753
+ trnuid = self.uuid()
766
754
  return CCSTMTTRNRQ(trnuid=trnuid, ccstmtrq=stmtrq)
767
755
 
768
756
  def ccstmtendtrnrq(
@@ -774,7 +762,7 @@ class OFXClient:
774
762
  """Construct CCSTMTENDRQ; package in CCSTMTENDTRNRQ"""
775
763
  acct = CCACCTFROM(acctid=acctid)
776
764
  stmtrq = CCSTMTENDRQ(ccacctfrom=acct, dtstart=dtstart, dtend=dtend)
777
- trnuid = self.uuid
765
+ trnuid = self.uuid()
778
766
  return CCSTMTENDTRNRQ(trnuid=trnuid, ccstmtendrq=stmtrq)
779
767
 
780
768
  def invstmttrnrq(
@@ -805,7 +793,7 @@ class OFXClient:
805
793
  incpos=incpos_,
806
794
  incbal=incbal,
807
795
  )
808
- trnuid = self.uuid
796
+ trnuid = self.uuid()
809
797
  return INVSTMTTRNRQ(trnuid=trnuid, invstmtrq=stmtrq)
810
798
 
811
799
  def download(
@@ -863,21 +851,20 @@ class OFXClient:
863
851
  ) -> bytes:
864
852
  """Separated out to facilitate mocking in unit tests."""
865
853
  if timeout in (None, False):
866
- # timeout = socket._GLOBAL_DEFAULT_TIMEOUT # type: ignore
867
854
  timeout = 10.0
868
855
 
869
856
  if USE_REQUESTS:
870
857
  logger.info("Using requests lib to post request")
871
858
  with requests.Session() as sess:
872
859
  if self.persist_cookies:
873
- sess.cookies = self.cookiejar # type: ignore
860
+ sess.cookies = self.cookiejar # type: ignore[assignment]
874
861
 
875
862
  # Replace session default headers entirely rather than merging
876
863
  # via the headers= kwarg. Some FIs (e.g. Amex) validate HTTP
877
864
  # header ordering and reject requests where User-Agent is not
878
865
  # the first header — which happens when requests prepends its
879
866
  # own defaults before ours.
880
- sess.headers = self.http_headers # type: ignore
867
+ sess.headers = self.http_headers # type: ignore[assignment]
881
868
 
882
869
  response = sess.request(
883
870
  method="POST",
@@ -899,7 +886,7 @@ class OFXClient:
899
886
  )
900
887
 
901
888
  response = opener.open(req, timeout=timeout)
902
- return response.read() # type: ignore
889
+ return bytes(response.read())
903
890
 
904
891
  def serialize(
905
892
  self,
@@ -944,11 +931,11 @@ class OFXClient:
944
931
 
945
932
  tree = ofx.to_etree()
946
933
  if prettyprint:
947
- utils.indent(tree)
934
+ ET.indent(tree)
948
935
 
949
936
  # Some servers choke on OFXv1 requests including ending tags for
950
937
  # elements (which are optional per the spec).
951
- if close_elements is False:
938
+ if not close_elements:
952
939
  if version >= 200:
953
940
  raise ValueError(
954
941
  f"OFX version {version} requires ending tags for elements"
@@ -961,43 +948,43 @@ class OFXClient:
961
948
  return header + body
962
949
 
963
950
 
964
- @singledispatch
965
- def wrap_stmtrq(nt, rqs, client):
966
- raise ValueError(f"Not a *StmtRq/*StmtEndRq: {nt.__class__.__name__}")
967
-
968
-
969
- @wrap_stmtrq.register(StmtRq)
970
- def wrap_stmtrq_stmtrq(nt, rqs, client):
971
- return (
972
- BANKMSGSRQV1,
973
- [client.stmttrnrq(**dict(rq._asdict(), bankid=client.bankid)) for rq in rqs],
974
- )
975
-
976
-
977
- @wrap_stmtrq.register(CcStmtRq)
978
- def wrap_stmtrq_ccstmtrq(nt, rqs, client):
979
- return (CREDITCARDMSGSRQV1, [client.ccstmttrnrq(**rq._asdict()) for rq in rqs])
980
-
981
-
982
- @wrap_stmtrq.register(InvStmtRq)
983
- def wrap_stmtrq_invstmtrq(nt, rqs, client):
984
- return (
985
- INVSTMTMSGSRQV1,
986
- [
987
- client.invstmttrnrq(**dict(r._asdict(), brokerid=client.brokerid))
988
- for r in rqs
989
- ],
990
- )
991
-
992
-
993
- @wrap_stmtrq.register(StmtEndRq)
994
- def wrap_stmtrq_stmtendrq(nt, rqs, client):
995
- return (
996
- BANKMSGSRQV1,
997
- [client.stmtendtrnrq(**dict(rq._asdict(), bankid=client.bankid)) for rq in rqs],
998
- )
999
-
1000
-
1001
- @wrap_stmtrq.register(CcStmtEndRq)
1002
- def wrap_stmtrq_ccstmtendrq(nt, rqs, client):
1003
- return (CREDITCARDMSGSRQV1, [client.ccstmtendtrnrq(**rq._asdict()) for rq in rqs])
951
+ def wrap_stmtrq(
952
+ nt: RequestParam, rqs: Iterable[RequestParam], client: "OFXClient"
953
+ ) -> tuple[type[Message], list[TrnRequest]]:
954
+ match nt:
955
+ case StmtRq():
956
+ return (
957
+ BANKMSGSRQV1,
958
+ [
959
+ client.stmttrnrq(**dict(rq._asdict(), bankid=client.bankid))
960
+ for rq in rqs
961
+ ],
962
+ )
963
+ case CcStmtRq():
964
+ return (
965
+ CREDITCARDMSGSRQV1,
966
+ [client.ccstmttrnrq(**rq._asdict()) for rq in rqs],
967
+ )
968
+ case InvStmtRq():
969
+ return (
970
+ INVSTMTMSGSRQV1,
971
+ [
972
+ client.invstmttrnrq(**dict(r._asdict(), brokerid=client.brokerid))
973
+ for r in rqs
974
+ ],
975
+ )
976
+ case StmtEndRq():
977
+ return (
978
+ BANKMSGSRQV1,
979
+ [
980
+ client.stmtendtrnrq(**dict(rq._asdict(), bankid=client.bankid))
981
+ for rq in rqs
982
+ ],
983
+ )
984
+ case CcStmtEndRq():
985
+ return (
986
+ CREDITCARDMSGSRQV1,
987
+ [client.ccstmtendtrnrq(**rq._asdict()) for rq in rqs],
988
+ )
989
+ case _:
990
+ raise ValueError(f"Not a *StmtRq/*StmtEndRq: {nt.__class__.__name__}")