ofxstatement-nordigen 0.1__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.

Potentially problematic release.


This version of ofxstatement-nordigen might be problematic. Click here for more details.

File without changes
@@ -0,0 +1,61 @@
1
+ import json
2
+ from typing import Iterable
3
+
4
+ from ofxstatement.plugin import Plugin
5
+ from ofxstatement.parser import StatementParser
6
+ from ofxstatement.statement import Statement, StatementLine
7
+
8
+ from ofxstatement_nordigen.schemas import NordigenTransactionModel
9
+
10
+
11
+ class NordigenPlugin(Plugin):
12
+ """Retrieves Nordigen transactions and converts them to OFX format."""
13
+
14
+ def get_parser(self, filename: str) -> "NordigenParser":
15
+ return NordigenParser(filename)
16
+
17
+
18
+ class NordigenParser(StatementParser[str]):
19
+ def __init__(self, filename: str) -> None:
20
+ super().__init__()
21
+ if not filename.endswith(".json"):
22
+ raise ValueError("Only JSON files are supported")
23
+ self.filename = filename
24
+
25
+ def parse(self) -> Statement:
26
+ """Main entry point for parsers
27
+
28
+ super() implementation will call to split_records and parse_record to
29
+ process the file.
30
+ """
31
+ with open(self.filename, "r"):
32
+ return super().parse()
33
+
34
+ def split_records(self) -> Iterable[str]:
35
+ """Return iterable object consisting of a line per transaction"""
36
+ data = json.load(open(self.filename, "r"))
37
+ transactions = data.get("transactions", {})
38
+ booked_transactions = transactions.get("booked", [])
39
+ return [json.dumps(transaction) for transaction in booked_transactions]
40
+
41
+ def parse_record(self, line: str) -> StatementLine:
42
+ """Parse given transaction line and return StatementLine object"""
43
+
44
+ # TODO: Infer transaction type from transaction data
45
+ statement = StatementLine()
46
+ transaction = json.loads(line)
47
+ transaction_data = NordigenTransactionModel(**transaction)
48
+ statement.id = transaction_data.transactionId
49
+ statement.date = transaction_data.bookingDateTime
50
+ statement.amount = transaction_data.transactionAmount.amount
51
+ statement.memo = transaction_data.remittanceInformationUnstructured
52
+ statement.payee = transaction_data.creditorName or transaction_data.debtorName
53
+ statement.date_user = transaction_data.valueDateTime
54
+ statement.check_no = transaction_data.checkId
55
+ statement.refnum = transaction_data.internalTransactionId
56
+ statement.currency = transaction_data.transactionAmount.currency
57
+ if transaction_data.currencyExchange and hasattr(
58
+ transaction_data.currencyExchange, "sourceCurrency"
59
+ ):
60
+ statement.orig_currency = transaction_data.currencyExchange.sourceCurrency
61
+ return statement
@@ -0,0 +1,79 @@
1
+ from __future__ import annotations
2
+
3
+ import datetime
4
+ from ofxstatement.statement import Currency
5
+ from decimal import Decimal
6
+ from typing import List, Optional, Union
7
+
8
+ from pydantic import BaseModel, field_validator
9
+
10
+
11
+ class Amount(BaseModel):
12
+ amount: Decimal
13
+ currency: Currency
14
+
15
+ class Config:
16
+ arbitrary_types_allowed = True
17
+
18
+ @field_validator("currency", mode="before")
19
+ def validate_currency(cls, value):
20
+ if isinstance(value, str):
21
+ return Currency(value)
22
+ return value
23
+
24
+
25
+ class InstructedAmount(Amount):
26
+ targetCurrency: Optional[Currency] = None
27
+ sourceCurrency: Optional[Currency] = None
28
+ exchangeRate: Optional[float] = None
29
+
30
+ @field_validator("targetCurrency", "sourceCurrency", mode="before")
31
+ def validate_currency(cls, value):
32
+ if isinstance(value, str):
33
+ return Currency(value)
34
+ return value
35
+
36
+
37
+ class Account(BaseModel):
38
+ bban: Optional[str] = None
39
+
40
+
41
+ class ReportExchangeRate(BaseModel):
42
+ instructedAmount: Optional[InstructedAmount] = None
43
+
44
+
45
+ class NordigenTransactionModel(BaseModel):
46
+ """
47
+ Nordigen data transaction model.
48
+ """
49
+
50
+ balanceAfterTransaction: Optional[float] = None
51
+ bankTransactionCode: Optional[str] = None
52
+ bookingDate: Optional[datetime.date] = None
53
+ bookingDateTime: Optional[datetime.datetime] = None
54
+ checkId: Optional[str] = None
55
+ creditorAccount: Optional[Account] = None
56
+ creditorAgent: Optional[str] = None
57
+ creditorId: Optional[str] = None
58
+ creditorName: Optional[str] = None
59
+ currencyExchange: Optional[Union[ReportExchangeRate, InstructedAmount]] = None
60
+ debtorAccount: Optional[Account] = None
61
+ debtorAgent: Optional[str] = None
62
+ debtorName: Optional[str] = None
63
+ endToEndId: Optional[str] = None
64
+ entryReference: Optional[str] = None
65
+ internalTransactionId: Optional[str] = None
66
+ mandateId: Optional[str] = None
67
+ merchantCategoryCode: Optional[str] = None
68
+ proprietaryBankTransactionCode: Optional[str] = None
69
+ purposeCode: Optional[str] = None
70
+ remittanceInformationStructured: Optional[str] = None
71
+ remittanceInformationStructuredArray: Optional[List[str]] = None
72
+ remittanceInformationUnstructured: Optional[str] = None
73
+ remmittanceInformationUnstructuredArray: Optional[List[str]] = None
74
+ transactionAmount: Amount
75
+ transactionId: Optional[str] = None
76
+ ultimateCreditor: Optional[str] = None
77
+ ultimateDebtor: Optional[str] = None
78
+ valueDate: Optional[datetime.date] = None
79
+ valueDateTime: Optional[datetime.datetime] = None
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: ofxstatement-nordigen
3
+ Version: 0.1
4
+ Summary: ofxstatement plugin for Nordigen bank statements
5
+ Author-email: Jimmy Stammers <jimmy.stammers@gmail.com>
6
+ Project-URL: Homepage, https://github.com/jstammers/ofxstatement-nordigen/
7
+ Keywords: ofx,banking,statement,plugin,ofxstatement
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Natural Language :: English
11
+ Classifier: Topic :: Office/Business :: Financial :: Accounting
12
+ Classifier: Topic :: Utilities
13
+ Classifier: Environment :: Console
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/x-rst
18
+ Requires-Dist: ofxstatement
19
+ Requires-Dist: pydantic
20
+ Requires-Dist: requests
21
+ Requires-Dist: requests-cache
22
+
23
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24
+ ofxstatement-nordigen
25
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26
+
27
+ A plugin for `ofxstatement`_ to parse transaction data from GoCardless (previously known as Nordigen).
28
+
29
+ `ofxstatement`_ is a tool to convert proprietary bank statement to OFX format,
30
+ suitable for importing to GnuCash. Plugin for ofxstatement parses a
31
+ particular proprietary bank statement format and produces common data
32
+ structure, that is then formatted into an OFX file.
33
+
34
+ .. _ofxstatement: https://github.com/kedder/ofxstatement
35
+
36
+
37
+ Installation
38
+ ================
39
+
40
+ To install the plugin, you can use `pip`_:
41
+
42
+ .. _pip: https://pypi.org/project/pip/
43
+
44
+ .. code-block:: shell
45
+
46
+ pip install ofxstatement-nordigen
47
+
48
+ or, if you want to install it in editable mode (for development), use:
49
+
50
+ .. code-block:: shell
51
+
52
+ pip install -e ./
53
+
54
+ To verify that the plugin is installed correctly, you can run:
55
+
56
+ .. code-block:: shell
57
+
58
+ ofxstatement --list-plugins
59
+
60
+ This should list the `nordigen` plugin among other plugins.
61
+
62
+ Usage
63
+ ================
64
+
65
+ To use the plugin, you can run the `ofxstatement` command with the `--plugin` option:
66
+
67
+ .. code-block:: shell
68
+
69
+ ofxstatement convert -t nordigen <input_file> <output_file>
70
+
71
+ Replace `<input_file>` with the path to your input file and `<output_file>` with the desired output file name.
72
+
73
+ The input file should be a JSON of transactions from GoCardless that has the schema defined `here`_.
74
+
75
+ .. _here: https://developer.gocardless.com/bank-account-data/transactions
76
+
77
+ The output file will be an OFX file that can be imported into GnuCash or other financial software.
78
+
79
+ After you are done
80
+ ==================
81
+
82
+ After your plugin is ready, feel free to open an issue on `ofxstatement`_
83
+ project to include your plugin in "known plugin list". That would hopefully
84
+ make life of other clients of your bank easier.
@@ -0,0 +1,8 @@
1
+ ofxstatement_nordigen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ofxstatement_nordigen/plugin.py,sha256=P74OSBt-4SkXHuHa0MREMayd9Um_mwp0jKgPndMAhb0,2533
3
+ ofxstatement_nordigen/schemas.py,sha256=8n4iXQjnHHHrKF_ZdEJRs6zcKCbidWu61PQmyVfzUUI,2561
4
+ ofxstatement_nordigen-0.1.dist-info/METADATA,sha256=QNFTJR7YfNTr3Oiu2K06SFsRezFSaDIccqF0wSW0A1M,2676
5
+ ofxstatement_nordigen-0.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
6
+ ofxstatement_nordigen-0.1.dist-info/entry_points.txt,sha256=u2VbBVZyOs-NBZwsS0wBZMwiczusBhgkWBrhSrcckvA,70
7
+ ofxstatement_nordigen-0.1.dist-info/top_level.txt,sha256=gxcEQgvstWr0jhEqaT70JODD71i507SJ06YeA5KIUj4,22
8
+ ofxstatement_nordigen-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [ofxstatement]
2
+ nordigen = ofxstatement_nordigen.plugin:NordigenPlugin
@@ -0,0 +1 @@
1
+ ofxstatement_nordigen