finstore 0.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 (86) hide show
  1. finstore-0.1.0/.claude/settings.local.json +8 -0
  2. finstore-0.1.0/.gitignore +12 -0
  3. finstore-0.1.0/CHANGELOG.md +12 -0
  4. finstore-0.1.0/CLAUDE.md +50 -0
  5. finstore-0.1.0/LICENSE +170 -0
  6. finstore-0.1.0/PKG-INFO +95 -0
  7. finstore-0.1.0/README.md +53 -0
  8. finstore-0.1.0/docs/api-reference.md +264 -0
  9. finstore-0.1.0/docs/architecture.md +159 -0
  10. finstore-0.1.0/docs/contributing.md +163 -0
  11. finstore-0.1.0/docs/decisions/01-async-backends-sync-storage.md +20 -0
  12. finstore-0.1.0/docs/decisions/02-backend-protocol-coarse-surface.md +22 -0
  13. finstore-0.1.0/docs/decisions/03-credentials-as-empty-marker.md +24 -0
  14. finstore-0.1.0/docs/decisions/04-tenant-in-every-storage-call.md +19 -0
  15. finstore-0.1.0/docs/decisions/05-filesystem-storage-in-core.md +19 -0
  16. finstore-0.1.0/docs/decisions/06-no-file-locking.md +23 -0
  17. finstore-0.1.0/docs/decisions/07-no-credential-lookup-in-core.md +21 -0
  18. finstore-0.1.0/docs/decisions/08-normalization-seam.md +29 -0
  19. finstore-0.1.0/docs/decisions/09-on-disk-format-is-private.md +22 -0
  20. finstore-0.1.0/docs/decisions/10-apache-2-license.md +16 -0
  21. finstore-0.1.0/docs/decisions/11-cancellation-propagate-partial-writes-kept.md +24 -0
  22. finstore-0.1.0/docs/decisions/12-cloud-variant-not-in-this-repo.md +25 -0
  23. finstore-0.1.0/docs/decisions/README.md +19 -0
  24. finstore-0.1.0/pyproject.toml +90 -0
  25. finstore-0.1.0/src/finstore/__init__.py +36 -0
  26. finstore-0.1.0/src/finstore/backends/__init__.py +0 -0
  27. finstore-0.1.0/src/finstore/backends/simplefin/__init__.py +15 -0
  28. finstore-0.1.0/src/finstore/backends/simplefin/backend.py +177 -0
  29. finstore-0.1.0/src/finstore/backends/simplefin/client.py +124 -0
  30. finstore-0.1.0/src/finstore/backends/simplefin/models.py +144 -0
  31. finstore-0.1.0/src/finstore/exceptions.py +33 -0
  32. finstore-0.1.0/src/finstore/fetch.py +42 -0
  33. finstore-0.1.0/src/finstore/model/__init__.py +91 -0
  34. finstore-0.1.0/src/finstore/protocols.py +78 -0
  35. finstore-0.1.0/src/finstore/py.typed +0 -0
  36. finstore-0.1.0/src/finstore/storage/__init__.py +36 -0
  37. finstore-0.1.0/src/finstore/storage/_schema.py +3 -0
  38. finstore-0.1.0/src/finstore/storage/exceptions.py +39 -0
  39. finstore-0.1.0/src/finstore/storage/filesystem.py +405 -0
  40. finstore-0.1.0/src/finstore/storage/paths.py +43 -0
  41. finstore-0.1.0/src/finstore/storage/types.py +48 -0
  42. finstore-0.1.0/src/finstore/storage/validate.py +272 -0
  43. finstore-0.1.0/src/finstore_local/__init__.py +6 -0
  44. finstore-0.1.0/src/finstore_local/cli/__init__.py +29 -0
  45. finstore-0.1.0/src/finstore_local/cli/_app.py +60 -0
  46. finstore-0.1.0/src/finstore_local/cli/accounts.py +54 -0
  47. finstore-0.1.0/src/finstore_local/cli/cache_reset.py +57 -0
  48. finstore-0.1.0/src/finstore_local/cli/fetch.py +96 -0
  49. finstore-0.1.0/src/finstore_local/cli/serve.py +51 -0
  50. finstore-0.1.0/src/finstore_local/cli/validate.py +29 -0
  51. finstore-0.1.0/src/finstore_local/config/__init__.py +113 -0
  52. finstore-0.1.0/src/finstore_local/logging/__init__.py +71 -0
  53. finstore-0.1.0/src/finstore_local/web/__init__.py +68 -0
  54. finstore-0.1.0/src/finstore_local/web/jobs.py +102 -0
  55. finstore-0.1.0/src/finstore_local/web/router.py +207 -0
  56. finstore-0.1.0/src/finstore_local/web/static/app.js +53 -0
  57. finstore-0.1.0/src/finstore_local/web/static/style.css +199 -0
  58. finstore-0.1.0/src/finstore_local/web/templates/account_detail.html +50 -0
  59. finstore-0.1.0/src/finstore_local/web/templates/accounts.html +41 -0
  60. finstore-0.1.0/src/finstore_local/web/templates/base.html +28 -0
  61. finstore-0.1.0/src/finstore_local/web/templates/cache_reset.html +34 -0
  62. finstore-0.1.0/src/finstore_local/web/templates/dashboard.html +35 -0
  63. finstore-0.1.0/src/finstore_local/web/templates/fetch.html +32 -0
  64. finstore-0.1.0/src/finstore_local/web/templates/login.html +29 -0
  65. finstore-0.1.0/src/finstore_local/web/templates/validate.html +37 -0
  66. finstore-0.1.0/tests/__init__.py +0 -0
  67. finstore-0.1.0/tests/arch/__init__.py +0 -0
  68. finstore-0.1.0/tests/arch/test_imports.py +164 -0
  69. finstore-0.1.0/tests/conftest.py +9 -0
  70. finstore-0.1.0/tests/unit/__init__.py +0 -0
  71. finstore-0.1.0/tests/unit/api/__init__.py +0 -0
  72. finstore-0.1.0/tests/unit/api/test_protocols.py +339 -0
  73. finstore-0.1.0/tests/unit/finstore_local/__init__.py +0 -0
  74. finstore-0.1.0/tests/unit/finstore_local/test_config.py +40 -0
  75. finstore-0.1.0/tests/unit/finstore_local/web/__init__.py +0 -0
  76. finstore-0.1.0/tests/unit/finstore_local/web/test_jobs.py +26 -0
  77. finstore-0.1.0/tests/unit/simplefin/__init__.py +0 -0
  78. finstore-0.1.0/tests/unit/simplefin/test_backend.py +321 -0
  79. finstore-0.1.0/tests/unit/simplefin/test_client.py +262 -0
  80. finstore-0.1.0/tests/unit/simplefin/test_models.py +194 -0
  81. finstore-0.1.0/tests/unit/store/__init__.py +0 -0
  82. finstore-0.1.0/tests/unit/store/test_paths.py +7 -0
  83. finstore-0.1.0/tests/unit/store/test_reader.py +297 -0
  84. finstore-0.1.0/tests/unit/store/test_sanitize_account_name.py +34 -0
  85. finstore-0.1.0/tests/unit/store/test_validate.py +210 -0
  86. finstore-0.1.0/tests/unit/store/test_writer.py +269 -0
@@ -0,0 +1,8 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(python -m pytest tests/ -x -q)",
5
+ "Bash(uv build *)"
6
+ ]
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ .env
8
+ cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .pytest_cache/
12
+ uv.lock
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+ - Initial extraction from `gnc-sfin-gateway`.
7
+ - `finstore` core library: `Tenant`, `fetch()`, `Backend`/`Storage`/`Credentials` protocols,
8
+ `Account`/`Transaction`/`Connection`/`AccountSummary`/`Window` data model,
9
+ `FilesystemStorage` reference implementation, exception hierarchy rooted at `FinstoreError`.
10
+ - `finstore[simplefin]` extra: `SimpleFINBackend`, `SimpleFINCredentials`, `FetchReport`.
11
+ - `finstore[local]` extra: `finstore_local` self-hosted CLI (`fetch`, `serve`, `accounts`,
12
+ `validate`, `cache reset`) and FastAPI dashboard.
@@ -0,0 +1,50 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Working agreements
6
+
7
+ - **Do not commit without an explicit request from the user.**
8
+ - Commit messages must not include a `Co-Authored-By` tag.
9
+
10
+ ## Commands
11
+
12
+ ```bash
13
+ # Install (requires Python 3.11+)
14
+ uv venv && source .venv/bin/activate && uv pip install -e ".[dev]"
15
+
16
+ # Tests
17
+ pytest tests/unit/ # unit tests only
18
+ pytest tests/arch/ # import boundary invariants
19
+ pytest tests/ # everything
20
+ pytest tests/unit/store/test_writer.py # single file
21
+
22
+ # Lint / type-check
23
+ ruff check src/ tests/
24
+ mypy src/finstore src/finstore_local
25
+ ```
26
+
27
+ ## Architecture
28
+
29
+ Two packages share one `src/` tree:
30
+
31
+ - **`finstore`** — the public library. Backend-agnostic; no app-layer imports allowed.
32
+ - **`finstore_local`** — the self-hosted CLI + dashboard. Imports `finstore`; not importable as API.
33
+
34
+ Data flow: `SimpleFINBackend` fetches from the SimpleFIN HTTP API → normalizes `Sf*` types into neutral `finstore.model` types → calls `FilesystemStorage.merge_chunk()` to persist atomically per account.
35
+
36
+ ### Import boundaries (enforced by `tests/arch/`)
37
+
38
+ 1. `finstore.*` must not import `finstore_local.*`
39
+ 2. `finstore.model.*` and `finstore.storage.*` must not import `finstore.backends.*`
40
+ 3. `Sf*` types are confined to `finstore.backends.simplefin.*` — they never cross the normalization seam in `backend.py`
41
+
42
+ ### Key design points
43
+
44
+ **Normalization seam** — `SimpleFINBackend` in `backends/simplefin/backend.py` is the only place `Sf*` → model conversion happens. `models.py` holds raw SimpleFIN shapes; `client.py` is pure HTTP and returns `SfResponse`; `backend.py` converts and persists.
45
+
46
+ **Protocols** — `Backend`, `Storage`, and `Credentials` in `finstore/protocols.py` define the contract. `SimpleFINBackend` and `FilesystemStorage` satisfy them structurally. `Credentials` is an empty marker; each backend defines its own frozen dataclass.
47
+
48
+ **Tenant scoping** — every `Storage` method accepts `tenant_id: str`. `FilesystemStorage` is single-tenant and ignores it (all data lands under the same root), but the parameter must be threaded through — never hardcode `"local"` outside `finstore_local`.
49
+
50
+ **`finstore_local` settings** — use `load_settings(env_file)` from `finstore_local.config` in all CLI commands. It returns the cached singleton when `env_file` is `None` and constructs a fresh instance for an alternate env file. Do not call `get_settings()` directly in CLI commands.
finstore-0.1.0/LICENSE ADDED
@@ -0,0 +1,170 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and its Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contributions
78
+ with the Work to which such Contributions were submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any patent
81
+ claim embodied within the Work constitutes direct or indirect patent
82
+ infringement, then any patent licenses granted to You under this
83
+ License for that Work shall terminate as of the date such litigation
84
+ is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the
121
+ Derivative Works, as conditions for such additional rights; and
122
+
123
+ You may add additional license statement in the NOTICE text
124
+ alongside the LICENSE text in the Work.
125
+
126
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
127
+ any Contribution intentionally submitted for inclusion in the Work
128
+ by You to the Licensor shall be under the terms and conditions of
129
+ this License, without any additional terms or conditions.
130
+ Notwithstanding the above, nothing herein shall supersede or modify
131
+ the terms of any separate license agreement you may have executed
132
+ with Licensor regarding such Contributions.
133
+
134
+ 6. Trademarks. This License does not grant permission to use the trade
135
+ names, trademarks, service marks, or product names of the Licensor,
136
+ except as required for reasonable and customary use in describing the
137
+ origin of the Work and reproducing the content of the NOTICE file.
138
+
139
+ 7. Disclaimer of Warranty. Unless required by applicable law or
140
+ agreed to in writing, Licensor provides the Work (and each
141
+ Contributor provides its Contributions) on an "AS IS" BASIS,
142
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
143
+ implied, including, without limitation, any conditions of TITLE,
144
+ NONINFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
145
+ PURPOSE. You are solely responsible for determining the
146
+ appropriateness of using or reproducing the Work and assume any
147
+ risks associated with Your exercise of permissions under this License.
148
+
149
+ 8. Limitation of Liability. In no event and under no legal theory,
150
+ whether in tort (including negligence), contract, or otherwise,
151
+ unless required by applicable law (such as deliberate and grossly
152
+ negligent acts) or agreed to in writing, shall any Contributor be
153
+ liable to You for damages, including any direct, indirect, special,
154
+ incidental, or exemplary damages of any character arising as a
155
+ result of this License or out of the use or inability to use the
156
+ Work (including but not limited to damages for loss of goodwill,
157
+ work stoppage, computer failure or malfunction, or all other
158
+ commercial damages or losses), even if such Contributor has been
159
+ advised of the possibility of such damages.
160
+
161
+ 9. Accepting Warranty or Additional Liability. While redistributing
162
+ the Work or Derivative Works thereof, You may choose to offer,
163
+ and charge a fee for, acceptance of support, warranty, indemnity,
164
+ or other liability obligations and/or rights consistent with this
165
+ License. However, in accepting such obligations, You may offer only
166
+ conditions consistent with this License and not in the form of
167
+ additional liability conditions, imposing obligations not consistent
168
+ with this License, or conditions on behalf of any Contributor.
169
+
170
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: finstore
3
+ Version: 0.1.0
4
+ Summary: Backend-agnostic local repository of a user's financial data
5
+ Project-URL: Homepage, https://github.com/stevel408/finstore
6
+ Project-URL: Repository, https://github.com/stevel408/finstore
7
+ Project-URL: Bug Tracker, https://github.com/stevel408/finstore/issues
8
+ Author-email: Steven Li <steve.98@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: banking,finance,financial-data,gnucash,ofx,personal-finance,simplefin
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: platformdirs>=4
14
+ Requires-Dist: pydantic>=2
15
+ Provides-Extra: dev
16
+ Requires-Dist: fastapi>=0.110; extra == 'dev'
17
+ Requires-Dist: httpx>=0.27; extra == 'dev'
18
+ Requires-Dist: import-linter>=2.1; extra == 'dev'
19
+ Requires-Dist: itsdangerous>=2.1; extra == 'dev'
20
+ Requires-Dist: jinja2>=3.1; extra == 'dev'
21
+ Requires-Dist: mypy>=1.10; extra == 'dev'
22
+ Requires-Dist: pydantic-settings>=2.2; extra == 'dev'
23
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
24
+ Requires-Dist: pytest-httpx>=0.30; extra == 'dev'
25
+ Requires-Dist: pytest>=8; extra == 'dev'
26
+ Requires-Dist: python-multipart>=0.0.9; extra == 'dev'
27
+ Requires-Dist: ruff>=0.4; extra == 'dev'
28
+ Requires-Dist: typer>=0.12; extra == 'dev'
29
+ Requires-Dist: uvicorn[standard]>=0.27; extra == 'dev'
30
+ Provides-Extra: local
31
+ Requires-Dist: fastapi>=0.110; extra == 'local'
32
+ Requires-Dist: httpx>=0.27; extra == 'local'
33
+ Requires-Dist: itsdangerous>=2.1; extra == 'local'
34
+ Requires-Dist: jinja2>=3.1; extra == 'local'
35
+ Requires-Dist: pydantic-settings>=2.2; extra == 'local'
36
+ Requires-Dist: python-multipart>=0.0.9; extra == 'local'
37
+ Requires-Dist: typer>=0.12; extra == 'local'
38
+ Requires-Dist: uvicorn[standard]>=0.27; extra == 'local'
39
+ Provides-Extra: simplefin
40
+ Requires-Dist: httpx>=0.27; extra == 'simplefin'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # finstore
44
+
45
+ Backend-agnostic local repository of a user's financial data.
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ # Library only (for custom integrations / the gnc-sfin-gateway OFX server)
51
+ pip install finstore
52
+
53
+ # Library + SimpleFIN backend
54
+ pip install finstore[simplefin]
55
+
56
+ # Self-hosted CLI + dashboard (end users)
57
+ pipx install 'finstore[local]'
58
+ ```
59
+
60
+ ## Quick start
61
+
62
+ ```python
63
+ import asyncio
64
+ import time
65
+ from pathlib import Path
66
+
67
+ import httpx
68
+
69
+ from finstore import Tenant, fetch
70
+ from finstore.backends.simplefin import SimpleFINBackend, SimpleFINCredentials
71
+ from finstore.storage.filesystem import FilesystemStorage
72
+
73
+ tenant = Tenant(id="local")
74
+ storage = FilesystemStorage(root=Path("~/.local/share/finstore").expanduser())
75
+ creds = SimpleFINCredentials(access_url="https://user:pass@bridge.simplefin.org/simplefin")
76
+
77
+ dtstart = int(time.time()) - 90 * 86400 # last 90 days
78
+
79
+ async def main() -> None:
80
+ async with httpx.AsyncClient() as http_client:
81
+ backend = SimpleFINBackend(credentials=creds, httpx_client=http_client)
82
+ await fetch(tenant, backend, storage, window=(dtstart, None))
83
+
84
+ accounts = storage.list_accounts(tenant.id)
85
+
86
+ asyncio.run(main())
87
+ ```
88
+
89
+ ## Development
90
+
91
+ See [docs/contributing.md](docs/contributing.md) for setup, running tests, linting, and CLI usage.
92
+
93
+ ## License
94
+
95
+ Apache-2.0
@@ -0,0 +1,53 @@
1
+ # finstore
2
+
3
+ Backend-agnostic local repository of a user's financial data.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ # Library only (for custom integrations / the gnc-sfin-gateway OFX server)
9
+ pip install finstore
10
+
11
+ # Library + SimpleFIN backend
12
+ pip install finstore[simplefin]
13
+
14
+ # Self-hosted CLI + dashboard (end users)
15
+ pipx install 'finstore[local]'
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```python
21
+ import asyncio
22
+ import time
23
+ from pathlib import Path
24
+
25
+ import httpx
26
+
27
+ from finstore import Tenant, fetch
28
+ from finstore.backends.simplefin import SimpleFINBackend, SimpleFINCredentials
29
+ from finstore.storage.filesystem import FilesystemStorage
30
+
31
+ tenant = Tenant(id="local")
32
+ storage = FilesystemStorage(root=Path("~/.local/share/finstore").expanduser())
33
+ creds = SimpleFINCredentials(access_url="https://user:pass@bridge.simplefin.org/simplefin")
34
+
35
+ dtstart = int(time.time()) - 90 * 86400 # last 90 days
36
+
37
+ async def main() -> None:
38
+ async with httpx.AsyncClient() as http_client:
39
+ backend = SimpleFINBackend(credentials=creds, httpx_client=http_client)
40
+ await fetch(tenant, backend, storage, window=(dtstart, None))
41
+
42
+ accounts = storage.list_accounts(tenant.id)
43
+
44
+ asyncio.run(main())
45
+ ```
46
+
47
+ ## Development
48
+
49
+ See [docs/contributing.md](docs/contributing.md) for setup, running tests, linting, and CLI usage.
50
+
51
+ ## License
52
+
53
+ Apache-2.0
@@ -0,0 +1,264 @@
1
+ # finstore — Public API Reference (0.1)
2
+
3
+ Changes to anything listed here require a minor (new symbol) or major
4
+ (changed/removed symbol) version bump and a CHANGELOG entry. Everything else
5
+ is free to change between patch releases.
6
+
7
+ ---
8
+
9
+ ## Top-level (`finstore`)
10
+
11
+ ```python
12
+ from finstore import fetch, Tenant, Window, FinstoreError
13
+ from finstore import BackendError, StorageError, CredentialError, ValidationError
14
+ ```
15
+
16
+ ### `Tenant`
17
+
18
+ ```python
19
+ @dataclass(frozen=True)
20
+ class Tenant:
21
+ id: str
22
+ ```
23
+
24
+ Pure identity token. The local app uses `Tenant(id="local")`. A future
25
+ multi-tenant deployment would derive the id from auth. Every storage call is
26
+ scoped to a tenant.
27
+
28
+ ### `Window`
29
+
30
+ ```python
31
+ Window = tuple[int, int | None]
32
+ ```
33
+
34
+ `(dtstart_epoch, dtend_epoch_or_none)`. Epoch seconds UTC. `None` on the upper
35
+ bound means "no upper limit." Bounds are inclusive at both the backend and the
36
+ storage reader.
37
+
38
+ ### `fetch()`
39
+
40
+ ```python
41
+ async def fetch(
42
+ tenant: Tenant,
43
+ backend: Backend,
44
+ storage: Storage,
45
+ *,
46
+ window: Window,
47
+ ) -> Any
48
+ ```
49
+
50
+ Fetch one window of financial data via `backend` and persist it into `storage`
51
+ under `tenant`. Returns the backend's report object (today: `FetchReport` from
52
+ `SimpleFINBackend`).
53
+
54
+ **Cancellation:** `asyncio.CancelledError` propagates to the caller. Any
55
+ `storage.merge_chunk()` calls that completed before cancellation are kept on
56
+ disk; the in-flight chunk is dropped. No rollback is attempted.
57
+
58
+ ### Exception hierarchy
59
+
60
+ ```
61
+ FinstoreError
62
+ ├── BackendError # backend fetch failed (network, auth, upstream error)
63
+ ├── StorageError # storage read/write failed
64
+ │ ├── CacheMissError (finstore.storage)
65
+ │ ├── CacheEmptyError (finstore.storage)
66
+ │ ├── CacheCorruptError (finstore.storage)
67
+ │ └── CacheSchemaMismatchError (finstore.storage)
68
+ ├── CredentialError # credentials missing, malformed, or rejected
69
+ └── ValidationError # data crossing a public boundary failed validation
70
+ ```
71
+
72
+ ---
73
+
74
+ ## Data model (`finstore.model`)
75
+
76
+ ```python
77
+ from finstore.model import Account, Transaction, Connection, AccountSummary, StorageChunk, Window
78
+ ```
79
+
80
+ All model types are **frozen dataclasses**. Fields listed here are guaranteed
81
+ at 0.1; backends may not populate optional fields (marked below).
82
+
83
+ ### `Account`
84
+
85
+ | Field | Type | Notes |
86
+ |---|---|---|
87
+ | `id` | `str` | Backend-assigned identifier (e.g. raw SimpleFIN id) |
88
+ | `name` | `str` | Display name |
89
+ | `currency` | `str` | ISO 4217 code (e.g. `"USD"`) |
90
+ | `balance` | `Decimal` | Ledger balance |
91
+ | `available_balance` | `Decimal \| None` | May be absent |
92
+ | `balance_date` | `int` | Epoch seconds UTC |
93
+ | `conn_id` | `str` | Links to a `Connection` |
94
+ | `transactions` | `tuple[Transaction, ...]` | |
95
+
96
+ ### `Transaction`
97
+
98
+ | Field | Type | Notes |
99
+ |---|---|---|
100
+ | `id` | `str` | Backend-assigned identifier |
101
+ | `posted` | `int` | Epoch seconds UTC |
102
+ | `amount` | `Decimal` | Signed; `"0.00"` is valid (fee reversals) |
103
+ | `description` | `str` | |
104
+ | `payee` | `str` | |
105
+ | `memo` | `str` | |
106
+ | `transacted_at` | `int \| None` | When the transaction was initiated; may be absent |
107
+
108
+ ### `Connection`
109
+
110
+ | Field | Type | Notes |
111
+ |---|---|---|
112
+ | `conn_id` | `str` | Stable identifier (e.g. institution domain) |
113
+ | `org_name` | `str` | Human-readable institution name |
114
+ | `org_id` | `str` | Backend-assigned institution id |
115
+ | `org_domain` | `str` | Default `""` |
116
+ | `sfin_url` | `str` | Default `""` |
117
+ | `org_url` | `str` | Default `""` |
118
+
119
+ ### `AccountSummary`
120
+
121
+ Lightweight stub returned by `Storage.list_accounts`. Does not include
122
+ transactions.
123
+
124
+ | Field | Type | Notes |
125
+ |---|---|---|
126
+ | `acctid` | `str` | Display id (e.g. sanitized account name) |
127
+ | `name` | `str` | |
128
+ | `currency` | `str` | |
129
+ | `connection` | `Connection` | |
130
+ | `last_fetch_at` | `int \| None` | `None` if never fetched |
131
+ | `txn_count` | `int` | Total stored transactions |
132
+
133
+ ### `StorageChunk`
134
+
135
+ Unit of normalized data produced by a backend and consumed by `Storage.merge_chunk`.
136
+
137
+ | Field | Type |
138
+ |---|---|
139
+ | `accounts` | `tuple[Account, ...]` |
140
+ | `connections` | `tuple[Connection, ...]` |
141
+
142
+ ---
143
+
144
+ ## Protocols (`finstore.protocols`)
145
+
146
+ ```python
147
+ from finstore.protocols import Backend, Storage, Credentials
148
+ ```
149
+
150
+ All three are `@runtime_checkable`. See `docs/architecture.md` for the
151
+ full method signatures and rationale.
152
+
153
+ ---
154
+
155
+ ## Storage (`finstore.storage`)
156
+
157
+ ```python
158
+ from finstore.storage.filesystem import FilesystemStorage
159
+ from finstore.storage import (
160
+ CacheMissError, CacheEmptyError, CacheCorruptError, CacheSchemaMismatchError,
161
+ CacheMeta, CachedAccount, AccountMeta, MergeStats,
162
+ )
163
+ ```
164
+
165
+ ### `FilesystemStorage(root: Path)`
166
+
167
+ Reference `Storage` implementation. Single-writer invariant: only one process
168
+ should call `merge_chunk` at a time. Reads are safe to concurrent callers.
169
+
170
+ Constructor argument `root` is the storage directory (e.g.
171
+ `~/.local/share/finstore`). The directory and `accounts/` subdirectory must
172
+ exist before the first write; `finstore_local.config` creates them.
173
+
174
+ ### Return types
175
+
176
+ **`MergeStats`** — returned by `merge_chunk`.
177
+
178
+ | Field | Type |
179
+ |---|---|
180
+ | `accounts_seen` | `int` |
181
+ | `txns_new` | `int` |
182
+ | `txns_duplicate` | `int` |
183
+
184
+ **`CacheMeta`** — returned by `read_meta`.
185
+
186
+ | Field | Type |
187
+ |---|---|
188
+ | `schema_version` | `int` |
189
+ | `last_fetch_at` | `int` |
190
+ | `connections` | `tuple[Connection, ...]` |
191
+ | `accounts` | `dict[str, AccountMeta]` |
192
+
193
+ **`CachedAccount`** — returned by `read_account` and `read_account_window`.
194
+
195
+ | Field | Type |
196
+ |---|---|
197
+ | `account` | `Account` |
198
+ | `display_id` | `str` |
199
+
200
+ **`AccountMeta`**
201
+
202
+ | Field | Type |
203
+ |---|---|
204
+ | `last_fetch_at` | `int` |
205
+ | `txn_count` | `int` |
206
+ | `earliest_posted` | `int \| None` |
207
+ | `latest_posted` | `int \| None` |
208
+ | `conn_id` | `str` |
209
+
210
+ ---
211
+
212
+ ## SimpleFIN backend (`finstore.backends.simplefin`)
213
+
214
+ Requires the `[simplefin]` extra (`pip install finstore[simplefin]`).
215
+
216
+ ```python
217
+ from finstore.backends.simplefin import SimpleFINBackend, SimpleFINCredentials, FetchReport
218
+ ```
219
+
220
+ ### `SimpleFINCredentials`
221
+
222
+ ```python
223
+ @dataclass(frozen=True)
224
+ class SimpleFINCredentials:
225
+ access_url: str
226
+ ```
227
+
228
+ Structurally satisfies the `Credentials` marker.
229
+
230
+ ### `SimpleFINBackend`
231
+
232
+ ```python
233
+ SimpleFINBackend(
234
+ credentials: SimpleFINCredentials,
235
+ httpx_client: httpx.AsyncClient | None = None,
236
+ )
237
+ ```
238
+
239
+ Satisfies the `Backend` protocol. `httpx_client` is optional; if omitted the
240
+ backend creates and closes its own client per `fetch_and_persist` call.
241
+
242
+ ### `FetchReport`
243
+
244
+ Returned by `fetch()` when the backend is `SimpleFINBackend`.
245
+
246
+ | Field | Type |
247
+ |---|---|
248
+ | `chunks` | `int` |
249
+ | `accounts_seen` | `int` |
250
+ | `txns_new` | `int` |
251
+ | `txns_duplicate` | `int` |
252
+ | `errors` | `list[str]` |
253
+
254
+ ---
255
+
256
+ ## What is NOT public API
257
+
258
+ - `finstore.backends.simplefin.models` — the `Sf*` types are backend-internal.
259
+ Do not import them; the arch tests will catch violations.
260
+ - `finstore_local.*` — the self-hosted app modules. The CLI command shape
261
+ (`finstore fetch`, `finstore serve`, etc.) and dashboard URL paths are
262
+ public surface; the Python modules behind them are not.
263
+ - `finstore.storage._schema` — internal schema constants.
264
+ - Anything prefixed `_`.