ofxtools 1.0.1__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.
- {ofxtools-1.0.1/ofxtools.egg-info → ofxtools-1.1.0}/PKG-INFO +14 -8
- {ofxtools-1.0.1 → ofxtools-1.1.0}/README.rst +10 -7
- {ofxtools-1.0.1 → ofxtools-1.1.0}/docs/conf.py +2 -2
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/Client.py +34 -6
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/Parser.py +5 -4
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/Types.py +36 -33
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/config/fi.cfg +4 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/header.py +2 -2
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/msgsets.py +6 -4
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/stmt.py +10 -8
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/stmtend.py +3 -1
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/base.py +62 -67
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/common.py +2 -2
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/common.py +1 -1
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/email.py +3 -2
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/i18n.py +10 -9
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/msgsets.py +6 -4
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/securities.py +5 -4
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/stmt.py +9 -7
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/ofx.py +7 -5
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/profile.py +4 -2
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/signon.py +5 -4
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/signup.py +3 -3
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/tax1099.py +6 -6
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/scripts/ofxget.py +33 -27
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/utils.py +10 -7
- {ofxtools-1.0.1 → ofxtools-1.1.0/ofxtools.egg-info}/PKG-INFO +14 -8
- {ofxtools-1.0.1 → ofxtools-1.1.0}/pyproject.toml +6 -2
- {ofxtools-1.0.1 → ofxtools-1.1.0}/LICENSE +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/config/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/config/ofxget_example.cfg +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/lib.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/interxfer.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/mail.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/recur.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/stpchk.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/sync.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/wire.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/bank/xfer.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/list.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/mail.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/msgsets.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/pmt.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/recur.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/billpay/sync.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/acct.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/mail.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/openorders.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/positions.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/invest/transactions.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/models/wrapperbases.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/py.typed +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools/scripts/__init__.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools.egg-info/SOURCES.txt +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools.egg-info/dependency_links.txt +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools.egg-info/entry_points.txt +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools.egg-info/requires.txt +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/ofxtools.egg-info/top_level.txt +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/setup.cfg +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/base.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_client.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_header.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_interxfer.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_mail.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_recur.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_stmt.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_stmtend.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_stpchk.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_sync.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_wire.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_bank_xfer.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_base.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_billpay_common.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_billpay_list.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_billpay_mail.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_billpay_pmt.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_billpay_recur.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_billpay_sync.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_common.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_email.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_i18n.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_invest.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_invest_oo.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_invest_transactions.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_msgsets.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_ofx.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_profile.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_securities.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_signon.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_models_signup.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_ofxget.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_parser.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_spec_bank.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_spec_billpay.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_spec_invest.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_spec_signon.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_spec_tax1099.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_types.py +0 -0
- {ofxtools-1.0.1 → ofxtools-1.1.0}/tests/test_utils.py +0 -0
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ofxtools
|
|
3
|
-
Version: 1.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
|
|
@@ -56,11 +59,15 @@ Open Financial Exchange (OFX) Tools for Python
|
|
|
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
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
@@ -126,8 +133,7 @@ library (no external dependencies).
|
|
|
126
133
|
|
|
127
134
|
|
|
128
135
|
.. _OFX specification: https://financialdataexchange.org/ofx
|
|
129
|
-
.. _Requests: http://docs.python-requests.org/en/master/
|
|
130
136
|
.. _Read the Docs: https://ofxtools.readthedocs.io/
|
|
131
137
|
.. _GitHub: https://github.com/csingley/ofxtools
|
|
132
138
|
.. _bug tracker: https://github.com/csingley/ofxtools/issues
|
|
133
|
-
.. _PyPI: https://pypi.
|
|
139
|
+
.. _PyPI: https://pypi.org/project/ofxtools/
|
|
@@ -14,11 +14,15 @@ Open Financial Exchange (OFX) Tools for Python
|
|
|
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
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
@@ -84,8 +88,7 @@ library (no external dependencies).
|
|
|
84
88
|
|
|
85
89
|
|
|
86
90
|
.. _OFX specification: https://financialdataexchange.org/ofx
|
|
87
|
-
.. _Requests: http://docs.python-requests.org/en/master/
|
|
88
91
|
.. _Read the Docs: https://ofxtools.readthedocs.io/
|
|
89
92
|
.. _GitHub: https://github.com/csingley/ofxtools
|
|
90
93
|
.. _bug tracker: https://github.com/csingley/ofxtools/issues
|
|
91
|
-
.. _PyPI: https://pypi.
|
|
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
|
|
|
@@ -27,7 +27,7 @@ pygments_style = None
|
|
|
27
27
|
|
|
28
28
|
# -- Options for HTML output -------------------------------------------------
|
|
29
29
|
|
|
30
|
-
html_theme = "
|
|
30
|
+
html_theme = "sphinx_rtd_theme"
|
|
31
31
|
html_static_path = ["_static"]
|
|
32
32
|
|
|
33
33
|
|
|
@@ -56,6 +56,7 @@ from collections.abc import Iterable, Iterator
|
|
|
56
56
|
from io import BytesIO
|
|
57
57
|
from operator import attrgetter, itemgetter
|
|
58
58
|
from typing import (
|
|
59
|
+
Any,
|
|
59
60
|
BinaryIO,
|
|
60
61
|
NamedTuple,
|
|
61
62
|
)
|
|
@@ -206,7 +207,34 @@ MsgsetClass = (
|
|
|
206
207
|
|
|
207
208
|
class OFXClient:
|
|
208
209
|
"""
|
|
209
|
-
|
|
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
|
|
@@ -332,7 +360,7 @@ class OFXClient:
|
|
|
332
360
|
urls = set(RqCls2url.values())
|
|
333
361
|
if len(urls) != 1:
|
|
334
362
|
raise ValueError(f"Expected 1 service URL, got {len(urls)}: {urls}")
|
|
335
|
-
return urls.pop()
|
|
363
|
+
return str(urls.pop())
|
|
336
364
|
|
|
337
365
|
def request_statements(
|
|
338
366
|
self,
|
|
@@ -370,7 +398,7 @@ class OFXClient:
|
|
|
370
398
|
# trnrqs is a pair of (models.*MSGSRQV1, [*TRNRQ])
|
|
371
399
|
# Can't sort *MSGSRQV1 by class, either, so we use the same trick
|
|
372
400
|
# of sorting by class name and grouping by class.
|
|
373
|
-
def trnSortKey(pair):
|
|
401
|
+
def trnSortKey(pair: Any) -> Any:
|
|
374
402
|
return pair[0].__name__
|
|
375
403
|
|
|
376
404
|
trnGroupKey = itemgetter(0)
|
|
@@ -411,7 +439,7 @@ class OFXClient:
|
|
|
411
439
|
self,
|
|
412
440
|
timeout: float | None = None,
|
|
413
441
|
gen_newfileuid: bool = True,
|
|
414
|
-
) -> dict:
|
|
442
|
+
) -> dict[Any, Any]:
|
|
415
443
|
"""Query OFX profile endpoint to construct mapping of statement request
|
|
416
444
|
data container to URL providing that service.
|
|
417
445
|
"""
|
|
@@ -439,7 +467,7 @@ class OFXClient:
|
|
|
439
467
|
def map_stmtendrq_urls(
|
|
440
468
|
msgsetCls: MsgsetClass,
|
|
441
469
|
stmtendrqCls: type[StmtEndRq] | type[CcStmtEndRq],
|
|
442
|
-
):
|
|
470
|
+
) -> None:
|
|
443
471
|
try:
|
|
444
472
|
index = [type(msgset) for msgset in msgsetlist].index(msgsetCls)
|
|
445
473
|
except ValueError:
|
|
@@ -858,7 +886,7 @@ class OFXClient:
|
|
|
858
886
|
)
|
|
859
887
|
|
|
860
888
|
response = opener.open(req, timeout=timeout)
|
|
861
|
-
return response.read()
|
|
889
|
+
return bytes(response.read())
|
|
862
890
|
|
|
863
891
|
def serialize(
|
|
864
892
|
self,
|
|
@@ -31,6 +31,7 @@ import contextlib
|
|
|
31
31
|
import logging
|
|
32
32
|
import re
|
|
33
33
|
import xml.etree.ElementTree as ET
|
|
34
|
+
from typing import Any, cast
|
|
34
35
|
|
|
35
36
|
# local imports
|
|
36
37
|
from ofxtools.header import OFXHeaderType, parse_header
|
|
@@ -64,7 +65,7 @@ class OFXTree(ET.ElementTree):
|
|
|
64
65
|
the root node of the hierarchy.
|
|
65
66
|
"""
|
|
66
67
|
|
|
67
|
-
def parse(self, source, parser=None) -> ET.Element:
|
|
68
|
+
def parse(self, source: Any, parser: Any = None) -> ET.Element:
|
|
68
69
|
"""
|
|
69
70
|
Deserialize OFX document into tree of `ElementTree.Element` instances.
|
|
70
71
|
|
|
@@ -86,13 +87,13 @@ class OFXTree(ET.ElementTree):
|
|
|
86
87
|
# ElementTree.TreeBuilder.close() returns the root.
|
|
87
88
|
# Follow ElementTree API and stash as self._root (so all normal
|
|
88
89
|
# ElementTree methods e.g. find() work normally on our subclass).
|
|
89
|
-
self._root = parser.close()
|
|
90
|
+
self._root = cast(ET.Element, parser.close())
|
|
90
91
|
logger.debug(f"Parsed Element tree root: {self._root}")
|
|
91
92
|
|
|
92
93
|
return self._root
|
|
93
94
|
|
|
94
95
|
@staticmethod
|
|
95
|
-
def _read(source) -> tuple[OFXHeaderType, str]:
|
|
96
|
+
def _read(source: Any) -> tuple[OFXHeaderType, str]:
|
|
96
97
|
"""
|
|
97
98
|
Validate/convert OFX header and return it as an instance of
|
|
98
99
|
`ofxtools.header.OFXHeader{V1, V2}`, along with message body as `str`.
|
|
@@ -222,7 +223,7 @@ class TreeBuilder(ET.TreeBuilder):
|
|
|
222
223
|
return None
|
|
223
224
|
|
|
224
225
|
|
|
225
|
-
def main(*files):
|
|
226
|
+
def main(*files: str) -> None:
|
|
226
227
|
"""
|
|
227
228
|
Simple functional test for impatient developers.
|
|
228
229
|
"""
|
|
@@ -35,6 +35,7 @@ import datetime
|
|
|
35
35
|
import decimal
|
|
36
36
|
import re
|
|
37
37
|
import warnings
|
|
38
|
+
from typing import Any
|
|
38
39
|
from xml.sax import saxutils
|
|
39
40
|
|
|
40
41
|
# local imports
|
|
@@ -94,10 +95,10 @@ class Element:
|
|
|
94
95
|
return f"<{self.__class__.__name__} required={self.required}>"
|
|
95
96
|
|
|
96
97
|
# Descriptor protocol
|
|
97
|
-
def __set_name__(self, owner, name):
|
|
98
|
+
def __set_name__(self, owner: type, name: str) -> None:
|
|
98
99
|
self.name = name
|
|
99
100
|
|
|
100
|
-
def __get__(self, obj, objtype=None):
|
|
101
|
+
def __get__(self, obj: Any, objtype: Any = None) -> Any:
|
|
101
102
|
if obj is None:
|
|
102
103
|
return self
|
|
103
104
|
try:
|
|
@@ -105,26 +106,26 @@ class Element:
|
|
|
105
106
|
except KeyError:
|
|
106
107
|
raise AttributeError(self.name) from None
|
|
107
108
|
|
|
108
|
-
def __set__(self, obj, value) -> None:
|
|
109
|
+
def __set__(self, obj: Any, value: Any) -> None:
|
|
109
110
|
if value is None:
|
|
110
111
|
self.enforce_required(value)
|
|
111
112
|
obj.__dict__[self.name] = None
|
|
112
113
|
else:
|
|
113
114
|
obj.__dict__[self.name] = self.convert(value)
|
|
114
115
|
|
|
115
|
-
def convert(self, value):
|
|
116
|
+
def convert(self, value: Any) -> Any:
|
|
116
117
|
raise NotImplementedError
|
|
117
118
|
|
|
118
|
-
def unconvert(self, value):
|
|
119
|
+
def unconvert(self, value: Any) -> Any:
|
|
119
120
|
if value is None:
|
|
120
121
|
self.enforce_required(value)
|
|
121
122
|
return None
|
|
122
123
|
return self._unconvert(value)
|
|
123
124
|
|
|
124
|
-
def _unconvert(self, value):
|
|
125
|
+
def _unconvert(self, value: Any) -> Any:
|
|
125
126
|
raise NotImplementedError
|
|
126
127
|
|
|
127
|
-
def enforce_required(self, value) -> None:
|
|
128
|
+
def enforce_required(self, value: Any) -> None:
|
|
128
129
|
if value is None and self.required:
|
|
129
130
|
raise OFXSpecError(f"{self.__class__.__name__}: Value is required")
|
|
130
131
|
|
|
@@ -133,7 +134,7 @@ class Bool(Element):
|
|
|
133
134
|
mapping = {"Y": True, "N": False}
|
|
134
135
|
reverse_mapping = {True: "Y", False: "N"}
|
|
135
136
|
|
|
136
|
-
def convert(self, value):
|
|
137
|
+
def convert(self, value: Any) -> Any:
|
|
137
138
|
match value:
|
|
138
139
|
case bool():
|
|
139
140
|
return value
|
|
@@ -149,7 +150,7 @@ class Bool(Element):
|
|
|
149
150
|
f"{value} is not one of the allowed values {list(self.mapping)}"
|
|
150
151
|
)
|
|
151
152
|
|
|
152
|
-
def _unconvert(self, value):
|
|
153
|
+
def _unconvert(self, value: Any) -> Any:
|
|
153
154
|
match value:
|
|
154
155
|
case bool():
|
|
155
156
|
return self.reverse_mapping[value]
|
|
@@ -180,7 +181,7 @@ class String(Element):
|
|
|
180
181
|
warnings.warn(msg, category=OFXTypeWarning)
|
|
181
182
|
return value
|
|
182
183
|
|
|
183
|
-
def convert(self, value):
|
|
184
|
+
def convert(self, value: Any) -> Any:
|
|
184
185
|
match value:
|
|
185
186
|
case str():
|
|
186
187
|
if value == "":
|
|
@@ -196,7 +197,7 @@ class String(Element):
|
|
|
196
197
|
case _:
|
|
197
198
|
raise TypeError(f"{value!r} is not a str")
|
|
198
199
|
|
|
199
|
-
def _unconvert(self, value):
|
|
200
|
+
def _unconvert(self, value: Any) -> Any:
|
|
200
201
|
match value:
|
|
201
202
|
case str():
|
|
202
203
|
return self.enforce_length(value)
|
|
@@ -223,7 +224,7 @@ class OneOf(Element):
|
|
|
223
224
|
>>> opttype = OneOf("CALL", "PUT", required=True)
|
|
224
225
|
"""
|
|
225
226
|
|
|
226
|
-
def __init__(self, *valid, required: bool = False) -> None:
|
|
227
|
+
def __init__(self, *valid: Any, required: bool = False) -> None:
|
|
227
228
|
super().__init__(required=required)
|
|
228
229
|
self.valid = valid
|
|
229
230
|
|
|
@@ -232,20 +233,20 @@ class OneOf(Element):
|
|
|
232
233
|
f"<{self.__class__.__name__} valid={self.valid} required={self.required}>"
|
|
233
234
|
)
|
|
234
235
|
|
|
235
|
-
def _check(self, value):
|
|
236
|
+
def _check(self, value: Any) -> Any:
|
|
236
237
|
self.enforce_required(value)
|
|
237
238
|
if value is not None and value not in self.valid:
|
|
238
239
|
raise OFXSpecError(f"'{value}' is not OneOf {self.valid}")
|
|
239
240
|
return value
|
|
240
241
|
|
|
241
|
-
def convert(self, value):
|
|
242
|
+
def convert(self, value: Any) -> Any:
|
|
242
243
|
match value:
|
|
243
244
|
case str():
|
|
244
245
|
return self._check(value or None)
|
|
245
246
|
case _:
|
|
246
247
|
return self._check(value)
|
|
247
248
|
|
|
248
|
-
def _unconvert(self, value):
|
|
249
|
+
def _unconvert(self, value: Any) -> Any:
|
|
249
250
|
return self._check(value)
|
|
250
251
|
|
|
251
252
|
|
|
@@ -266,7 +267,7 @@ class Integer(Element):
|
|
|
266
267
|
)
|
|
267
268
|
return value
|
|
268
269
|
|
|
269
|
-
def convert(self, value):
|
|
270
|
+
def convert(self, value: Any) -> Any:
|
|
270
271
|
match value:
|
|
271
272
|
case int():
|
|
272
273
|
return self.enforce_length(value)
|
|
@@ -278,7 +279,7 @@ class Integer(Element):
|
|
|
278
279
|
case _:
|
|
279
280
|
return self.enforce_length(int(value))
|
|
280
281
|
|
|
281
|
-
def _unconvert(self, value):
|
|
282
|
+
def _unconvert(self, value: Any) -> Any:
|
|
282
283
|
match value:
|
|
283
284
|
case int():
|
|
284
285
|
return str(self.enforce_length(value))
|
|
@@ -309,7 +310,7 @@ class Decimal(Element):
|
|
|
309
310
|
f"<{self.__class__.__name__} scale={self.scale} required={self.required}>"
|
|
310
311
|
)
|
|
311
312
|
|
|
312
|
-
def convert(self, value):
|
|
313
|
+
def convert(self, value: Any) -> Any:
|
|
313
314
|
match value:
|
|
314
315
|
case decimal.Decimal():
|
|
315
316
|
if self.scale is not None:
|
|
@@ -327,7 +328,7 @@ class Decimal(Element):
|
|
|
327
328
|
case _:
|
|
328
329
|
return self.__type__(value)
|
|
329
330
|
|
|
330
|
-
def _unconvert(self, value):
|
|
331
|
+
def _unconvert(self, value: Any) -> Any:
|
|
331
332
|
match value:
|
|
332
333
|
case decimal.Decimal():
|
|
333
334
|
if self.scale is not None and not value.same_quantum(self.scale):
|
|
@@ -424,7 +425,7 @@ class DateTime(Element):
|
|
|
424
425
|
__type__: type[datetime.datetime] | type[datetime.time] = datetime.datetime
|
|
425
426
|
regex = DT_REGEX
|
|
426
427
|
|
|
427
|
-
def convert(self, value):
|
|
428
|
+
def convert(self, value: Any) -> Any:
|
|
428
429
|
match value:
|
|
429
430
|
case datetime.datetime():
|
|
430
431
|
if value.utcoffset() is None:
|
|
@@ -438,7 +439,7 @@ class DateTime(Element):
|
|
|
438
439
|
f"can't convert to {self.__type__}"
|
|
439
440
|
)
|
|
440
441
|
|
|
441
|
-
def _convert_str(self, value: str):
|
|
442
|
+
def _convert_str(self, value: str) -> datetime.datetime:
|
|
442
443
|
match = self.regex.match(value)
|
|
443
444
|
if match is None:
|
|
444
445
|
raise OFXSpecError(
|
|
@@ -476,10 +477,12 @@ class DateTime(Element):
|
|
|
476
477
|
|
|
477
478
|
return utils.gmt_offset(gmt_offset_hours, int(minutes or 0))
|
|
478
479
|
|
|
479
|
-
def _normalize_to_gmt(
|
|
480
|
+
def _normalize_to_gmt(
|
|
481
|
+
self, value: datetime.datetime, gmt_offset: datetime.timedelta
|
|
482
|
+
) -> datetime.datetime:
|
|
480
483
|
return (value - gmt_offset).replace(tzinfo=utils.UTC)
|
|
481
484
|
|
|
482
|
-
def _unconvert(self, value):
|
|
485
|
+
def _unconvert(self, value: Any) -> Any:
|
|
483
486
|
match value:
|
|
484
487
|
case datetime.datetime():
|
|
485
488
|
if value.utcoffset() is None:
|
|
@@ -531,7 +534,7 @@ class Time(DateTime):
|
|
|
531
534
|
__type__ = datetime.time
|
|
532
535
|
regex = TIME_REGEX
|
|
533
536
|
|
|
534
|
-
def convert(self, value):
|
|
537
|
+
def convert(self, value: Any) -> Any:
|
|
535
538
|
match value:
|
|
536
539
|
case datetime.time():
|
|
537
540
|
if value.utcoffset() is None:
|
|
@@ -545,7 +548,7 @@ class Time(DateTime):
|
|
|
545
548
|
f"can't convert to {self.__type__}"
|
|
546
549
|
)
|
|
547
550
|
|
|
548
|
-
def _normalize_to_gmt(
|
|
551
|
+
def _normalize_to_gmt( # type: ignore[override]
|
|
549
552
|
self, value: datetime.time, gmt_offset: datetime.timedelta
|
|
550
553
|
) -> datetime.time:
|
|
551
554
|
# Can't directly subtract datetime.timedelta from datetime.time
|
|
@@ -560,7 +563,7 @@ class Time(DateTime):
|
|
|
560
563
|
)
|
|
561
564
|
return (dt - gmt_offset).time().replace(tzinfo=utils.UTC)
|
|
562
565
|
|
|
563
|
-
def _unconvert(self, value):
|
|
566
|
+
def _unconvert(self, value: Any) -> Any:
|
|
564
567
|
match value:
|
|
565
568
|
case datetime.time():
|
|
566
569
|
if value.utcoffset() is None:
|
|
@@ -601,13 +604,13 @@ class ListElement(Element):
|
|
|
601
604
|
def __repr__(self) -> str:
|
|
602
605
|
return f"<{self.__class__.__name__} converter={self.converter!r} required={self.required}>"
|
|
603
606
|
|
|
604
|
-
def convert(self, value):
|
|
607
|
+
def convert(self, value: Any) -> Any:
|
|
605
608
|
if value is None:
|
|
606
609
|
self.enforce_required(value)
|
|
607
610
|
return None
|
|
608
611
|
return self.converter.convert(value)
|
|
609
612
|
|
|
610
|
-
def _unconvert(self, value):
|
|
613
|
+
def _unconvert(self, value: Any) -> Any:
|
|
611
614
|
return self.converter._unconvert(value)
|
|
612
615
|
|
|
613
616
|
|
|
@@ -633,7 +636,7 @@ class SubAggregate(Element):
|
|
|
633
636
|
def __repr__(self) -> str:
|
|
634
637
|
return f"<{self.__class__.__name__} type={self.aggregate_type.__name__} required={self.required}>"
|
|
635
638
|
|
|
636
|
-
def convert(self, value):
|
|
639
|
+
def convert(self, value: Any) -> Any:
|
|
637
640
|
if isinstance(value, self.aggregate_type):
|
|
638
641
|
return value
|
|
639
642
|
raise TypeError(f"'{value}' is not an instance of {self.aggregate_type}")
|
|
@@ -644,7 +647,7 @@ class ListAggregate(SubAggregate):
|
|
|
644
647
|
``SubAggregate`` that can be repeated on the parent ``Aggregate``.
|
|
645
648
|
"""
|
|
646
649
|
|
|
647
|
-
def _unconvert(self, value):
|
|
650
|
+
def _unconvert(self, value: Any) -> Any:
|
|
648
651
|
if not isinstance(value, self.aggregate_type):
|
|
649
652
|
raise TypeError(f"'{value!r}' is not an instance of {self.aggregate_type}")
|
|
650
653
|
return value
|
|
@@ -655,13 +658,13 @@ class Unsupported(Element):
|
|
|
655
658
|
Null Aggregate/Element - not implemented (yet)
|
|
656
659
|
"""
|
|
657
660
|
|
|
658
|
-
def __get__(self, obj, objtype):
|
|
661
|
+
def __get__(self, obj: Any, objtype: Any = None) -> Any:
|
|
659
662
|
return None
|
|
660
663
|
|
|
661
|
-
def __set__(self, obj, value) -> None:
|
|
664
|
+
def __set__(self, obj: Any, value: Any) -> None:
|
|
662
665
|
pass
|
|
663
666
|
|
|
664
|
-
def convert(self, value):
|
|
667
|
+
def convert(self, value: Any) -> Any:
|
|
665
668
|
return None
|
|
666
669
|
|
|
667
670
|
def __repr__(self) -> str:
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# Community-maintained database of US financial institutions known to speak OFX.
|
|
2
|
+
# Entries may be incomplete or stale — OFX endpoints change without notice.
|
|
3
|
+
# If you get a new server working, edit this file and submit a pull request.
|
|
4
|
+
# See also: https://ofxtools.readthedocs.io/en/latest/client.html
|
|
1
5
|
[NAMES]
|
|
2
6
|
[ing]
|
|
3
7
|
|
|
@@ -29,7 +29,7 @@ __all__ = [
|
|
|
29
29
|
# stdlib imports
|
|
30
30
|
import logging
|
|
31
31
|
import re
|
|
32
|
-
from typing import Any, BinaryIO, TypeAlias
|
|
32
|
+
from typing import Any, BinaryIO, TypeAlias, cast
|
|
33
33
|
|
|
34
34
|
# local imports
|
|
35
35
|
from ofxtools import Types
|
|
@@ -339,4 +339,4 @@ def make_header(
|
|
|
339
339
|
version, security=security, oldfileuid=oldfileuid, newfileuid=newfileuid
|
|
340
340
|
)
|
|
341
341
|
logger.debug(f"Made OFX header {header}")
|
|
342
|
-
return header
|
|
342
|
+
return cast(OFXHeaderType, header)
|
|
@@ -25,6 +25,8 @@ __all__ = [
|
|
|
25
25
|
]
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
28
30
|
# local imports
|
|
29
31
|
from ofxtools.models.bank.interxfer import INTERTRNRQ, INTERTRNRS
|
|
30
32
|
from ofxtools.models.bank.mail import BANKMAILTRNRQ, BANKMAILTRNRS
|
|
@@ -98,7 +100,7 @@ class BANKMSGSRQV1(Aggregate):
|
|
|
98
100
|
bankmailsyncrq = ListAggregate(BANKMAILSYNCRQ)
|
|
99
101
|
|
|
100
102
|
@property
|
|
101
|
-
def statements(self):
|
|
103
|
+
def statements(self) -> Any:
|
|
102
104
|
stmts = []
|
|
103
105
|
for trnrq in self:
|
|
104
106
|
stmtrq = None
|
|
@@ -127,7 +129,7 @@ class BANKMSGSRSV1(Aggregate):
|
|
|
127
129
|
bankmailsyncrs = ListAggregate(BANKMAILSYNCRS)
|
|
128
130
|
|
|
129
131
|
@property
|
|
130
|
-
def statements(self):
|
|
132
|
+
def statements(self) -> Any:
|
|
131
133
|
stmts = []
|
|
132
134
|
for trnrs in self:
|
|
133
135
|
stmtrs = None
|
|
@@ -204,7 +206,7 @@ class CREDITCARDMSGSRQV1(Aggregate):
|
|
|
204
206
|
ccstmtendtrnrq = ListAggregate(CCSTMTENDTRNRQ)
|
|
205
207
|
|
|
206
208
|
@property
|
|
207
|
-
def statements(self):
|
|
209
|
+
def statements(self) -> Any:
|
|
208
210
|
stmts = []
|
|
209
211
|
for trnrq in self:
|
|
210
212
|
stmtrq = None
|
|
@@ -225,7 +227,7 @@ class CREDITCARDMSGSRSV1(Aggregate):
|
|
|
225
227
|
ccstmtendtrnrs = ListAggregate(CCSTMTENDTRNRS)
|
|
226
228
|
|
|
227
229
|
@property
|
|
228
|
-
def statements(self):
|
|
230
|
+
def statements(self) -> Any:
|
|
229
231
|
stmts = []
|
|
230
232
|
for trnrs in self:
|
|
231
233
|
stmtrs = None
|
|
@@ -31,6 +31,8 @@ __all__ = [
|
|
|
31
31
|
]
|
|
32
32
|
|
|
33
33
|
|
|
34
|
+
from typing import Any
|
|
35
|
+
|
|
34
36
|
# local imports
|
|
35
37
|
from ofxtools.models.base import Aggregate
|
|
36
38
|
from ofxtools.models.common import BAL, SVCSTATUSES
|
|
@@ -250,15 +252,15 @@ class STMTRS(Aggregate):
|
|
|
250
252
|
mktginfo = String(360)
|
|
251
253
|
|
|
252
254
|
@property
|
|
253
|
-
def account(self):
|
|
255
|
+
def account(self) -> Any:
|
|
254
256
|
return self.bankacctfrom
|
|
255
257
|
|
|
256
258
|
@property
|
|
257
|
-
def transactions(self):
|
|
259
|
+
def transactions(self) -> Any:
|
|
258
260
|
return self.banktranlist
|
|
259
261
|
|
|
260
262
|
@property
|
|
261
|
-
def balance(self):
|
|
263
|
+
def balance(self) -> Any:
|
|
262
264
|
return self.ledgerbal
|
|
263
265
|
|
|
264
266
|
|
|
@@ -274,7 +276,7 @@ class STMTTRNRS(TrnRs):
|
|
|
274
276
|
stmtrs = SubAggregate(STMTRS)
|
|
275
277
|
|
|
276
278
|
@property
|
|
277
|
-
def statement(self):
|
|
279
|
+
def statement(self) -> Any:
|
|
278
280
|
return self.stmtrs
|
|
279
281
|
|
|
280
282
|
|
|
@@ -313,15 +315,15 @@ class CCSTMTRS(Aggregate):
|
|
|
313
315
|
mktginfo = String(360)
|
|
314
316
|
|
|
315
317
|
@property
|
|
316
|
-
def account(self):
|
|
318
|
+
def account(self) -> Any:
|
|
317
319
|
return self.ccacctfrom
|
|
318
320
|
|
|
319
321
|
@property
|
|
320
|
-
def transactions(self):
|
|
322
|
+
def transactions(self) -> Any:
|
|
321
323
|
return self.banktranlist
|
|
322
324
|
|
|
323
325
|
@property
|
|
324
|
-
def balance(self):
|
|
326
|
+
def balance(self) -> Any:
|
|
325
327
|
return self.ledgerbal
|
|
326
328
|
|
|
327
329
|
|
|
@@ -337,5 +339,5 @@ class CCSTMTTRNRS(TrnRs):
|
|
|
337
339
|
ccstmtrs = SubAggregate(CCSTMTRS)
|
|
338
340
|
|
|
339
341
|
@property
|
|
340
|
-
def statement(self):
|
|
342
|
+
def statement(self) -> Any:
|
|
341
343
|
return self.ccstmtrs
|
|
@@ -18,6 +18,8 @@ __all__ = [
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
# local imports
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
21
23
|
from ofxtools.models.bank.stmt import BANKACCTFROM, CCACCTFROM, REWARDINFO
|
|
22
24
|
from ofxtools.models.base import Aggregate
|
|
23
25
|
from ofxtools.models.i18n import CURRENCY, CURRENCY_CODES, ORIGCURRENCY, Origcurrency
|
|
@@ -153,5 +155,5 @@ class CCSTMTENDTRNRS(TrnRs):
|
|
|
153
155
|
ccstmtendrs = SubAggregate(CCSTMTENDRS)
|
|
154
156
|
|
|
155
157
|
@property
|
|
156
|
-
def statement(self):
|
|
158
|
+
def statement(self) -> Any:
|
|
157
159
|
return self.ccstmtendrs
|