beancount-gocardless 0.1.12__tar.gz → 0.1.14__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.
- beancount_gocardless-0.1.14/.github/workflows/ci.yml +32 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/.github/workflows/publish.yml +4 -2
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/.gitignore +0 -7
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/.pre-commit-config.yaml +2 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/.readthedocs.yaml +2 -3
- beancount_gocardless-0.1.14/LICENSE +21 -0
- beancount_gocardless-0.1.14/PKG-INFO +252 -0
- beancount_gocardless-0.1.14/README.md +224 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/importer.rst +14 -3
- beancount_gocardless-0.1.14/mise.toml +7 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/pyproject.toml +10 -5
- beancount_gocardless-0.1.14/src/beancount_gocardless/__main__.py +4 -0
- beancount_gocardless-0.1.14/src/beancount_gocardless/cli.py +641 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/src/beancount_gocardless/client.py +13 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/src/beancount_gocardless/importer.py +145 -76
- beancount_gocardless-0.1.14/src/beancount_gocardless/mock_client.py +220 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/src/beancount_gocardless/models.py +54 -9
- beancount_gocardless-0.1.14/src/beancount_gocardless/utils.py +39 -0
- beancount_gocardless-0.1.14/tests/conftest.py +50 -0
- beancount_gocardless-0.1.14/tests/test_cli.py +356 -0
- beancount_gocardless-0.1.14/tests/test_importer.py +358 -0
- beancount_gocardless-0.1.14/tests/test_models.py +128 -0
- beancount_gocardless-0.1.12/LICENSE +0 -24
- beancount_gocardless-0.1.12/PKG-INFO +0 -130
- beancount_gocardless-0.1.12/README.md +0 -103
- beancount_gocardless-0.1.12/src/beancount_gocardless/cli.py +0 -140
- beancount_gocardless-0.1.12/src/beancount_gocardless/tui.py +0 -669
- beancount_gocardless-0.1.12/tests/test_tui.py +0 -85
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/Makefile +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/cli.rst +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/client.rst +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/conf.py +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/index.rst +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/docs/make.bat +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/src/beancount_gocardless/__init__.py +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/src/beancount_gocardless/openapi/swagger.json +0 -0
- {beancount_gocardless-0.1.12 → beancount_gocardless-0.1.14}/tests/__init__.py +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test-lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Install uv
|
|
16
|
+
uses: astral-sh/setup-uv@v7
|
|
17
|
+
with:
|
|
18
|
+
version: "latest"
|
|
19
|
+
enable-cache: true
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
|
|
22
|
+
- name: Install mise
|
|
23
|
+
uses: jdx/mise-action@v2
|
|
24
|
+
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: mise run test
|
|
27
|
+
|
|
28
|
+
- name: Run lint
|
|
29
|
+
run: mise run lint
|
|
30
|
+
|
|
31
|
+
- name: Run format check
|
|
32
|
+
run: mise run fmt-check
|
|
@@ -2,7 +2,7 @@ name: Upload Python Package to PyPI when a Release is Created
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
release:
|
|
5
|
-
types: [
|
|
5
|
+
types: [published]
|
|
6
6
|
|
|
7
7
|
jobs:
|
|
8
8
|
pypi-publish:
|
|
@@ -28,7 +28,9 @@ jobs:
|
|
|
28
28
|
- name: Build package
|
|
29
29
|
run: uv build
|
|
30
30
|
- name: Publish package to PyPI
|
|
31
|
-
|
|
31
|
+
env:
|
|
32
|
+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
|
33
|
+
run: uv publish
|
|
32
34
|
- name: Build Sphinx documentation
|
|
33
35
|
run: |
|
|
34
36
|
uv run sphinx-build -b html docs/ docs/_build
|
|
@@ -100,13 +100,6 @@ ipython_config.py
|
|
|
100
100
|
# commonly ignored for libraries.
|
|
101
101
|
uv.lock
|
|
102
102
|
|
|
103
|
-
# poetry
|
|
104
|
-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
-
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
-
# commonly ignored for libraries.
|
|
107
|
-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
-
#poetry.lock
|
|
109
|
-
|
|
110
103
|
# pdm
|
|
111
104
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
105
|
#pdm.lock
|
|
@@ -6,9 +6,8 @@ build:
|
|
|
6
6
|
python: "3.12"
|
|
7
7
|
jobs:
|
|
8
8
|
post_create_environment:
|
|
9
|
-
- python -m pip install
|
|
10
|
-
|
|
11
|
-
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with dev
|
|
9
|
+
- python -m pip install uv
|
|
10
|
+
- uv sync --extra dev
|
|
12
11
|
|
|
13
12
|
sphinx:
|
|
14
13
|
configuration: docs/conf.py
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Patrick Ruckstuhl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: beancount-gocardless
|
|
3
|
+
Version: 0.1.14
|
|
4
|
+
License-Expression: MIT
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
8
|
+
Requires-Python: <4,>=3.12
|
|
9
|
+
Requires-Dist: beancount
|
|
10
|
+
Requires-Dist: beangulp
|
|
11
|
+
Requires-Dist: pre-commit>=4.5.1
|
|
12
|
+
Requires-Dist: pydantic>=2.0.0
|
|
13
|
+
Requires-Dist: pyyaml
|
|
14
|
+
Requires-Dist: questionary>=2.0.0
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: requests-cache
|
|
17
|
+
Requires-Dist: rich
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: myst-parser; extra == 'dev'
|
|
20
|
+
Requires-Dist: sphinx; extra == 'dev'
|
|
21
|
+
Requires-Dist: sphinx-rtd-theme; extra == 'dev'
|
|
22
|
+
Provides-Extra: lint
|
|
23
|
+
Requires-Dist: ruff>=0.9.8; extra == 'lint'
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest; extra == 'test'
|
|
26
|
+
Requires-Dist: pytest-asyncio; extra == 'test'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
[](https://pypi.org/project/beancount-gocardless/)
|
|
30
|
+
[](https://pypi.org/project/beancount-gocardless/)
|
|
31
|
+
[](https://pypi.org/project/beancount-gocardless/)
|
|
32
|
+
[](https://beancount-gocardless.readthedocs.io/en/latest/)
|
|
33
|
+
[](https://github.com/jodoox/beancount-gocardless/actions/workflows/publish.yml)
|
|
34
|
+
|
|
35
|
+
# beancount-gocardless
|
|
36
|
+
|
|
37
|
+
Python client for the GoCardless Bank Account Data API (formerly Nordigen), with Pydantic models recreated from the OpenAPI/Swagger spec, plus a Beancount importer.
|
|
38
|
+
|
|
39
|
+
Inspired by https://github.com/tarioch/beancounttools.
|
|
40
|
+
|
|
41
|
+
Documentation: https://beancount-gocardless.readthedocs.io/en/latest/
|
|
42
|
+
|
|
43
|
+
## Key features
|
|
44
|
+
|
|
45
|
+
- API client with typed Pydantic models for endpoints and data structures.
|
|
46
|
+
- Built-in HTTP caching via `requests-cache` (optional).
|
|
47
|
+
- CLI to manage bank authorization (list banks, create links, list accounts, delete links).
|
|
48
|
+
- Beancount importer: a `beangulp.Importer` implementation that fetches transactions and emits Beancount entries.
|
|
49
|
+
- Import-time metadata control (exclude fields, add custom fields), plus subclassing hooks for advanced needs.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install beancount-gocardless
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Prerequisites (credentials)
|
|
58
|
+
|
|
59
|
+
Create a GoCardless Bank Account Data account to get API credentials:
|
|
60
|
+
|
|
61
|
+
https://bankaccountdata.gocardless.com/overview/
|
|
62
|
+
|
|
63
|
+
You will need:
|
|
64
|
+
|
|
65
|
+
- `GOCARDLESS_SECRET_ID`
|
|
66
|
+
- `GOCARDLESS_SECRET_KEY`
|
|
67
|
+
|
|
68
|
+
## CLI usage (bank authorization)
|
|
69
|
+
|
|
70
|
+
The importer needs an authorized bank connection first. Use the CLI to create and manage connections.
|
|
71
|
+
|
|
72
|
+
Set credentials as environment variables:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
export GOCARDLESS_SECRET_ID="..."
|
|
76
|
+
export GOCARDLESS_SECRET_KEY="..."
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Launch the CLI:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
beancount-gocardless
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Options:
|
|
86
|
+
- List accounts: view connected accounts with expiry status (EXPIRED badge shown for expired connections), select an account to view details, check balances, or delete the link
|
|
87
|
+
- Add account: add a new bank connection by selecting country, choosing a bank, and creating an authorization link
|
|
88
|
+
- List banks: browse available banks by country and create links
|
|
89
|
+
|
|
90
|
+
Account expiry is shown in the list. Use --mock flag for testing without real credentials.
|
|
91
|
+
|
|
92
|
+
## Beancount usage
|
|
93
|
+
|
|
94
|
+
### 1) Create a YAML config
|
|
95
|
+
|
|
96
|
+
Create `gocardless.yaml`:
|
|
97
|
+
|
|
98
|
+
```yaml
|
|
99
|
+
secret_id: $GOCARDLESS_SECRET_ID
|
|
100
|
+
secret_key: $GOCARDLESS_SECRET_KEY
|
|
101
|
+
|
|
102
|
+
# Note: this project substitutes environment variables in YAML values at runtime.
|
|
103
|
+
|
|
104
|
+
cache_options: # if omitted, caching is disabled
|
|
105
|
+
cache_name: "gocardless"
|
|
106
|
+
backend: "sqlite"
|
|
107
|
+
expire_after: 3600
|
|
108
|
+
old_data_on_error: true
|
|
109
|
+
|
|
110
|
+
accounts:
|
|
111
|
+
- id: "<REDACTED_UUID>"
|
|
112
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
113
|
+
transaction_types: ["booked", "pending"] # optional, defaults to both
|
|
114
|
+
preferred_balance_type: "interimAvailable" # optional
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 2) Create an import script
|
|
118
|
+
|
|
119
|
+
Create `my.import`:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
#!/usr/bin/env python3
|
|
123
|
+
|
|
124
|
+
import beangulp
|
|
125
|
+
from beancount_gocardless import GoCardLessImporter
|
|
126
|
+
from smart_importer import PredictPayees, PredictPostings
|
|
127
|
+
|
|
128
|
+
importers = [
|
|
129
|
+
GoCardLessImporter(),
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
hooks = [
|
|
133
|
+
PredictPostings().hook,
|
|
134
|
+
PredictPayees().hook,
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
if __name__ == "__main__":
|
|
138
|
+
ingest = beangulp.Ingest(importers, hooks=hooks)
|
|
139
|
+
ingest()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 3) Run the import
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
python my.import extract ./gocardless.yaml --existing ./ledger.bean
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Customizing metadata
|
|
149
|
+
|
|
150
|
+
### Via YAML configuration
|
|
151
|
+
|
|
152
|
+
You can control metadata per account:
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
accounts:
|
|
156
|
+
- id: "<REDACTED_UUID>"
|
|
157
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
158
|
+
|
|
159
|
+
# Exclude specific default metadata fields.
|
|
160
|
+
exclude_default_metadata: ["bookingDate", "creditorName"]
|
|
161
|
+
|
|
162
|
+
# Add custom metadata fields using dotted paths.
|
|
163
|
+
metadata_fields:
|
|
164
|
+
payee: "creditorName"
|
|
165
|
+
cardScheme: "additionalDataStructured.cardInstrument.cardSchemeName"
|
|
166
|
+
balanceType: "balanceAfterTransaction.balance_type"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Supported options:
|
|
170
|
+
|
|
171
|
+
- `exclude_default_metadata` (default: `[]`) - Exclude specific default metadata fields.
|
|
172
|
+
- Default fields include: `nordref`, `creditorName`, `debtorName`, `bookingDate`
|
|
173
|
+
- `metadata_fields` (default: `null`) - Add or override metadata fields using dotted paths.
|
|
174
|
+
- Specify the output key as the dict key and the GoCardless path as the value.
|
|
175
|
+
- Example: `"cardScheme": "additionalDataStructured.cardInstrument.cardSchemeName"`
|
|
176
|
+
|
|
177
|
+
### Example configurations
|
|
178
|
+
|
|
179
|
+
**Use defaults with exclusions:**
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
accounts:
|
|
183
|
+
- id: "<REDACTED_UUID>"
|
|
184
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
185
|
+
exclude_default_metadata: ["bookingDate"] # Keep nordref, creditorName, debtorName
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Full customization with custom keys:**
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
accounts:
|
|
192
|
+
- id: "<REDACTED_UUID>"
|
|
193
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
194
|
+
exclude_default_metadata: [] # Keep all defaults
|
|
195
|
+
metadata_fields:
|
|
196
|
+
# Rename default field by using custom key name
|
|
197
|
+
payee: "creditorName"
|
|
198
|
+
# Add nested custom fields
|
|
199
|
+
cardScheme: "additionalDataStructured.cardInstrument.cardSchemeName"
|
|
200
|
+
mcc: "merchant_category_code"
|
|
201
|
+
ultimateCreditor: "ultimate_creditor"
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Via subclassing
|
|
205
|
+
|
|
206
|
+
For advanced customization, subclass `GoCardLessImporter` and override `add_metadata`:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from beancount_gocardless import GoCardLessImporter
|
|
210
|
+
|
|
211
|
+
class CustomImporter(GoCardLessImporter):
|
|
212
|
+
def add_metadata(self, transaction, custom_metadata, account_config=None):
|
|
213
|
+
metakv = super().add_metadata(transaction, custom_metadata, account_config)
|
|
214
|
+
|
|
215
|
+
if transaction.ultimate_creditor:
|
|
216
|
+
metakv["ultimateCreditor"] = transaction.ultimate_creditor
|
|
217
|
+
if transaction.merchant_category_code:
|
|
218
|
+
metakv["mcc"] = transaction.merchant_category_code
|
|
219
|
+
if transaction.bank_transaction_code:
|
|
220
|
+
metakv["bankCode"] = transaction.bank_transaction_code
|
|
221
|
+
|
|
222
|
+
return metakv
|
|
223
|
+
|
|
224
|
+
importers = [CustomImporter()]
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The `BankTransaction` model (see `models.py`) contains many optional fields you can expose as metadata, for example:
|
|
228
|
+
|
|
229
|
+
- `ultimate_creditor`, `ultimate_debtor`
|
|
230
|
+
- `bank_transaction_code`, `proprietary_bank_transaction_code`
|
|
231
|
+
- `merchant_category_code`, `creditor_id`, `mandate_id`
|
|
232
|
+
- `entry_reference`, `account_servicer_reference`
|
|
233
|
+
|
|
234
|
+
## Development
|
|
235
|
+
|
|
236
|
+
### API coverage and models
|
|
237
|
+
|
|
238
|
+
The GoCardless client aims to provide full API coverage with typed models for endpoints and data structures.
|
|
239
|
+
|
|
240
|
+
Models are manually recreated from the OpenAPI/Swagger spec to keep strong typing and stable semantics.
|
|
241
|
+
|
|
242
|
+
### Local development
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
git clone https://github.com/jodoox/beancount-gocardless.git
|
|
246
|
+
cd beancount-gocardless
|
|
247
|
+
python -m venv .venv
|
|
248
|
+
source .venv/bin/activate
|
|
249
|
+
pip install -U pip
|
|
250
|
+
pip install -e ".[dev]"
|
|
251
|
+
pytest
|
|
252
|
+
```
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
[](https://pypi.org/project/beancount-gocardless/)
|
|
2
|
+
[](https://pypi.org/project/beancount-gocardless/)
|
|
3
|
+
[](https://pypi.org/project/beancount-gocardless/)
|
|
4
|
+
[](https://beancount-gocardless.readthedocs.io/en/latest/)
|
|
5
|
+
[](https://github.com/jodoox/beancount-gocardless/actions/workflows/publish.yml)
|
|
6
|
+
|
|
7
|
+
# beancount-gocardless
|
|
8
|
+
|
|
9
|
+
Python client for the GoCardless Bank Account Data API (formerly Nordigen), with Pydantic models recreated from the OpenAPI/Swagger spec, plus a Beancount importer.
|
|
10
|
+
|
|
11
|
+
Inspired by https://github.com/tarioch/beancounttools.
|
|
12
|
+
|
|
13
|
+
Documentation: https://beancount-gocardless.readthedocs.io/en/latest/
|
|
14
|
+
|
|
15
|
+
## Key features
|
|
16
|
+
|
|
17
|
+
- API client with typed Pydantic models for endpoints and data structures.
|
|
18
|
+
- Built-in HTTP caching via `requests-cache` (optional).
|
|
19
|
+
- CLI to manage bank authorization (list banks, create links, list accounts, delete links).
|
|
20
|
+
- Beancount importer: a `beangulp.Importer` implementation that fetches transactions and emits Beancount entries.
|
|
21
|
+
- Import-time metadata control (exclude fields, add custom fields), plus subclassing hooks for advanced needs.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install beancount-gocardless
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Prerequisites (credentials)
|
|
30
|
+
|
|
31
|
+
Create a GoCardless Bank Account Data account to get API credentials:
|
|
32
|
+
|
|
33
|
+
https://bankaccountdata.gocardless.com/overview/
|
|
34
|
+
|
|
35
|
+
You will need:
|
|
36
|
+
|
|
37
|
+
- `GOCARDLESS_SECRET_ID`
|
|
38
|
+
- `GOCARDLESS_SECRET_KEY`
|
|
39
|
+
|
|
40
|
+
## CLI usage (bank authorization)
|
|
41
|
+
|
|
42
|
+
The importer needs an authorized bank connection first. Use the CLI to create and manage connections.
|
|
43
|
+
|
|
44
|
+
Set credentials as environment variables:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
export GOCARDLESS_SECRET_ID="..."
|
|
48
|
+
export GOCARDLESS_SECRET_KEY="..."
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Launch the CLI:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
beancount-gocardless
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Options:
|
|
58
|
+
- List accounts: view connected accounts with expiry status (EXPIRED badge shown for expired connections), select an account to view details, check balances, or delete the link
|
|
59
|
+
- Add account: add a new bank connection by selecting country, choosing a bank, and creating an authorization link
|
|
60
|
+
- List banks: browse available banks by country and create links
|
|
61
|
+
|
|
62
|
+
Account expiry is shown in the list. Use --mock flag for testing without real credentials.
|
|
63
|
+
|
|
64
|
+
## Beancount usage
|
|
65
|
+
|
|
66
|
+
### 1) Create a YAML config
|
|
67
|
+
|
|
68
|
+
Create `gocardless.yaml`:
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
secret_id: $GOCARDLESS_SECRET_ID
|
|
72
|
+
secret_key: $GOCARDLESS_SECRET_KEY
|
|
73
|
+
|
|
74
|
+
# Note: this project substitutes environment variables in YAML values at runtime.
|
|
75
|
+
|
|
76
|
+
cache_options: # if omitted, caching is disabled
|
|
77
|
+
cache_name: "gocardless"
|
|
78
|
+
backend: "sqlite"
|
|
79
|
+
expire_after: 3600
|
|
80
|
+
old_data_on_error: true
|
|
81
|
+
|
|
82
|
+
accounts:
|
|
83
|
+
- id: "<REDACTED_UUID>"
|
|
84
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
85
|
+
transaction_types: ["booked", "pending"] # optional, defaults to both
|
|
86
|
+
preferred_balance_type: "interimAvailable" # optional
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 2) Create an import script
|
|
90
|
+
|
|
91
|
+
Create `my.import`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
#!/usr/bin/env python3
|
|
95
|
+
|
|
96
|
+
import beangulp
|
|
97
|
+
from beancount_gocardless import GoCardLessImporter
|
|
98
|
+
from smart_importer import PredictPayees, PredictPostings
|
|
99
|
+
|
|
100
|
+
importers = [
|
|
101
|
+
GoCardLessImporter(),
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
hooks = [
|
|
105
|
+
PredictPostings().hook,
|
|
106
|
+
PredictPayees().hook,
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
ingest = beangulp.Ingest(importers, hooks=hooks)
|
|
111
|
+
ingest()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 3) Run the import
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
python my.import extract ./gocardless.yaml --existing ./ledger.bean
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Customizing metadata
|
|
121
|
+
|
|
122
|
+
### Via YAML configuration
|
|
123
|
+
|
|
124
|
+
You can control metadata per account:
|
|
125
|
+
|
|
126
|
+
```yaml
|
|
127
|
+
accounts:
|
|
128
|
+
- id: "<REDACTED_UUID>"
|
|
129
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
130
|
+
|
|
131
|
+
# Exclude specific default metadata fields.
|
|
132
|
+
exclude_default_metadata: ["bookingDate", "creditorName"]
|
|
133
|
+
|
|
134
|
+
# Add custom metadata fields using dotted paths.
|
|
135
|
+
metadata_fields:
|
|
136
|
+
payee: "creditorName"
|
|
137
|
+
cardScheme: "additionalDataStructured.cardInstrument.cardSchemeName"
|
|
138
|
+
balanceType: "balanceAfterTransaction.balance_type"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Supported options:
|
|
142
|
+
|
|
143
|
+
- `exclude_default_metadata` (default: `[]`) - Exclude specific default metadata fields.
|
|
144
|
+
- Default fields include: `nordref`, `creditorName`, `debtorName`, `bookingDate`
|
|
145
|
+
- `metadata_fields` (default: `null`) - Add or override metadata fields using dotted paths.
|
|
146
|
+
- Specify the output key as the dict key and the GoCardless path as the value.
|
|
147
|
+
- Example: `"cardScheme": "additionalDataStructured.cardInstrument.cardSchemeName"`
|
|
148
|
+
|
|
149
|
+
### Example configurations
|
|
150
|
+
|
|
151
|
+
**Use defaults with exclusions:**
|
|
152
|
+
|
|
153
|
+
```yaml
|
|
154
|
+
accounts:
|
|
155
|
+
- id: "<REDACTED_UUID>"
|
|
156
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
157
|
+
exclude_default_metadata: ["bookingDate"] # Keep nordref, creditorName, debtorName
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Full customization with custom keys:**
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
accounts:
|
|
164
|
+
- id: "<REDACTED_UUID>"
|
|
165
|
+
asset_account: "Assets:Banks:Revolut:Checking"
|
|
166
|
+
exclude_default_metadata: [] # Keep all defaults
|
|
167
|
+
metadata_fields:
|
|
168
|
+
# Rename default field by using custom key name
|
|
169
|
+
payee: "creditorName"
|
|
170
|
+
# Add nested custom fields
|
|
171
|
+
cardScheme: "additionalDataStructured.cardInstrument.cardSchemeName"
|
|
172
|
+
mcc: "merchant_category_code"
|
|
173
|
+
ultimateCreditor: "ultimate_creditor"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Via subclassing
|
|
177
|
+
|
|
178
|
+
For advanced customization, subclass `GoCardLessImporter` and override `add_metadata`:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from beancount_gocardless import GoCardLessImporter
|
|
182
|
+
|
|
183
|
+
class CustomImporter(GoCardLessImporter):
|
|
184
|
+
def add_metadata(self, transaction, custom_metadata, account_config=None):
|
|
185
|
+
metakv = super().add_metadata(transaction, custom_metadata, account_config)
|
|
186
|
+
|
|
187
|
+
if transaction.ultimate_creditor:
|
|
188
|
+
metakv["ultimateCreditor"] = transaction.ultimate_creditor
|
|
189
|
+
if transaction.merchant_category_code:
|
|
190
|
+
metakv["mcc"] = transaction.merchant_category_code
|
|
191
|
+
if transaction.bank_transaction_code:
|
|
192
|
+
metakv["bankCode"] = transaction.bank_transaction_code
|
|
193
|
+
|
|
194
|
+
return metakv
|
|
195
|
+
|
|
196
|
+
importers = [CustomImporter()]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The `BankTransaction` model (see `models.py`) contains many optional fields you can expose as metadata, for example:
|
|
200
|
+
|
|
201
|
+
- `ultimate_creditor`, `ultimate_debtor`
|
|
202
|
+
- `bank_transaction_code`, `proprietary_bank_transaction_code`
|
|
203
|
+
- `merchant_category_code`, `creditor_id`, `mandate_id`
|
|
204
|
+
- `entry_reference`, `account_servicer_reference`
|
|
205
|
+
|
|
206
|
+
## Development
|
|
207
|
+
|
|
208
|
+
### API coverage and models
|
|
209
|
+
|
|
210
|
+
The GoCardless client aims to provide full API coverage with typed models for endpoints and data structures.
|
|
211
|
+
|
|
212
|
+
Models are manually recreated from the OpenAPI/Swagger spec to keep strong typing and stable semantics.
|
|
213
|
+
|
|
214
|
+
### Local development
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
git clone https://github.com/jodoox/beancount-gocardless.git
|
|
218
|
+
cd beancount-gocardless
|
|
219
|
+
python -m venv .venv
|
|
220
|
+
source .venv/bin/activate
|
|
221
|
+
pip install -U pip
|
|
222
|
+
pip install -e ".[dev]"
|
|
223
|
+
pytest
|
|
224
|
+
```
|
|
@@ -23,6 +23,8 @@ YAML file:
|
|
|
23
23
|
- id: Account ID
|
|
24
24
|
- asset_account: Beancount asset account
|
|
25
25
|
- filing_account (opt): For hooks
|
|
26
|
+
- preferred_balance_type (opt): Preferred type for balance assertions, availability depends on the bank (e.g. "expected", "closingBooked", "interimBooked", "interimAvailable", "available", "booked")
|
|
27
|
+
- transaction_types (opt): List of types to fetch ("booked" and/or "pending")
|
|
26
28
|
|
|
27
29
|
Usage
|
|
28
30
|
-----
|
|
@@ -44,17 +46,26 @@ Example
|
|
|
44
46
|
accounts:
|
|
45
47
|
- id: <REDACTED_UUID>
|
|
46
48
|
asset_account: "Assets:Banks:Revolut:Checking"
|
|
49
|
+
preferred_balance_type: "expected"
|
|
50
|
+
transaction_types: ["booked", "pending"]
|
|
47
51
|
|
|
48
52
|
.. code-block:: python
|
|
49
53
|
|
|
50
54
|
import beangulp
|
|
51
55
|
from beancount_gocardless import GoCardLessImporter
|
|
52
|
-
from smart_importer import
|
|
56
|
+
from smart_importer import PredictPostings, PredictPayees
|
|
53
57
|
|
|
54
|
-
importers = [
|
|
58
|
+
importers = [
|
|
59
|
+
GoCardLessImporter()
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
hooks = [
|
|
63
|
+
PredictPostings().hook,
|
|
64
|
+
PredictPayees().hook,
|
|
65
|
+
]
|
|
55
66
|
|
|
56
67
|
if __name__ == "__main__":
|
|
57
|
-
ingest = beangulp.Ingest(importers)
|
|
68
|
+
ingest = beangulp.Ingest(importers, hooks=hooks)
|
|
58
69
|
ingest()
|
|
59
70
|
|
|
60
71
|
.. code-block:: bash
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[tasks]
|
|
2
|
+
test = "uv sync --extra test && uv run pytest tests/ -v"
|
|
3
|
+
lint = "uv sync --extra lint && uv run ruff check src/ tests/"
|
|
4
|
+
fmt = "uv sync --extra lint && uv run ruff check src/ tests/ --fix"
|
|
5
|
+
fmt-check = "uv sync --extra lint && uv run ruff check src/ tests/"
|
|
6
|
+
build = "uv sync && uv build"
|
|
7
|
+
publish = "uv sync && uv publish --token $PYPI_TOKEN"
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "beancount-gocardless"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.14"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = []
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
requires-python = ">=3.12,<4"
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Programming Language :: Python :: 3",
|
|
10
|
+
"Programming Language :: Python :: 3.12"
|
|
11
|
+
]
|
|
8
12
|
dependencies = [
|
|
9
13
|
"requests",
|
|
10
14
|
"requests-cache",
|
|
@@ -12,17 +16,15 @@ dependencies = [
|
|
|
12
16
|
"beangulp",
|
|
13
17
|
"pyyaml",
|
|
14
18
|
"rich",
|
|
15
|
-
"textual>=3.2.0",
|
|
16
|
-
"textual-dev>=1.7.0",
|
|
17
19
|
"pydantic>=2.0.0",
|
|
18
20
|
"pre-commit>=4.5.1",
|
|
21
|
+
"questionary>=2.0.0",
|
|
19
22
|
]
|
|
20
|
-
license = "
|
|
23
|
+
license = "MIT"
|
|
21
24
|
license-files = ["LICENSE"]
|
|
22
25
|
|
|
23
26
|
[project.scripts]
|
|
24
27
|
beancount-gocardless = "beancount_gocardless.cli:main"
|
|
25
|
-
beancount-gocardless-tui = "beancount_gocardless.tui:main"
|
|
26
28
|
|
|
27
29
|
[project.optional-dependencies]
|
|
28
30
|
dev = [
|
|
@@ -38,6 +40,9 @@ test = [
|
|
|
38
40
|
"pytest-asyncio",
|
|
39
41
|
]
|
|
40
42
|
|
|
43
|
+
[tool.uv]
|
|
44
|
+
package = true
|
|
45
|
+
|
|
41
46
|
[build-system]
|
|
42
47
|
requires = ["hatchling"]
|
|
43
48
|
build-backend = "hatchling.build"
|