a-ledger 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.
- a_ledger-0.1.0/LICENSE +21 -0
- a_ledger-0.1.0/PKG-INFO +100 -0
- a_ledger-0.1.0/README.md +73 -0
- a_ledger-0.1.0/pyproject.toml +42 -0
- a_ledger-0.1.0/setup.cfg +4 -0
- a_ledger-0.1.0/src/a_ledger/__init__.py +35 -0
- a_ledger-0.1.0/src/a_ledger/errors.py +2 -0
- a_ledger-0.1.0/src/a_ledger/ledger.py +975 -0
- a_ledger-0.1.0/src/a_ledger/models.py +128 -0
- a_ledger-0.1.0/src/a_ledger/schema.py +206 -0
- a_ledger-0.1.0/src/a_ledger.egg-info/PKG-INFO +100 -0
- a_ledger-0.1.0/src/a_ledger.egg-info/SOURCES.txt +14 -0
- a_ledger-0.1.0/src/a_ledger.egg-info/dependency_links.txt +1 -0
- a_ledger-0.1.0/src/a_ledger.egg-info/requires.txt +5 -0
- a_ledger-0.1.0/src/a_ledger.egg-info/top_level.txt +1 -0
- a_ledger-0.1.0/tests/test_ledger.py +526 -0
a_ledger-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 realqiyan
|
|
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.
|
a_ledger-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: a-ledger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Application-neutral double-entry ledger SDK backed by SQLite
|
|
5
|
+
Author: realqiyan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/realqiyan/a-ledger
|
|
8
|
+
Project-URL: Repository, https://github.com/realqiyan/a-ledger
|
|
9
|
+
Project-URL: Issues, https://github.com/realqiyan/a-ledger/issues
|
|
10
|
+
Keywords: ledger,accounting,double-entry,sqlite,bookkeeping
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build>=1; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
25
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# a-ledger
|
|
29
|
+
|
|
30
|
+
`a-ledger` is an application-neutral, SQLite-backed double-entry ledger SDK.
|
|
31
|
+
It owns accounting primitives and persistence; calling applications own business
|
|
32
|
+
commands, broker integration, market calendars, projections, APIs, and pages.
|
|
33
|
+
|
|
34
|
+
## Accounting convention
|
|
35
|
+
|
|
36
|
+
- Money is stored as integer minor units; posted amounts never use `float`.
|
|
37
|
+
- A positive posting is a debit and a negative posting is a credit.
|
|
38
|
+
- Every posted transaction balances exactly to zero.
|
|
39
|
+
- Accounts use one of `ASSET`, `LIABILITY`, `EQUITY`, `INCOME`, or `EXPENSE`.
|
|
40
|
+
- Security quantities and cost lots are replayed from immutable lot events. There
|
|
41
|
+
are no persisted balance or position snapshots.
|
|
42
|
+
- Posted transactions, postings, lots, lot events, and audit events cannot be
|
|
43
|
+
updated or deleted. Corrections use linked reversal and replacement entries.
|
|
44
|
+
- Reservations are mutable authorization state, not accounting entries.
|
|
45
|
+
|
|
46
|
+
## Transaction ownership
|
|
47
|
+
|
|
48
|
+
The caller supplies a `sqlite3.Connection`, enables a short transaction, and
|
|
49
|
+
decides whether to commit or roll back. Write APIs reject calls without an active
|
|
50
|
+
caller-owned transaction. The SDK never calls `commit()` or `rollback()` and
|
|
51
|
+
never runs network or application callbacks.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import sqlite3
|
|
55
|
+
|
|
56
|
+
from a_ledger import AccountCategory, Ledger, PostingDraft, TransactionDraft
|
|
57
|
+
|
|
58
|
+
connection = sqlite3.connect("application.sqlite3")
|
|
59
|
+
ledger = Ledger(connection) # enables and verifies SQLite foreign keys
|
|
60
|
+
|
|
61
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
62
|
+
ledger.install_schema()
|
|
63
|
+
ledger.create_portfolio("portfolio-uuid", code="main", currency="CNY")
|
|
64
|
+
ledger.create_account(
|
|
65
|
+
"cash-account-uuid",
|
|
66
|
+
portfolio_id="portfolio-uuid",
|
|
67
|
+
code="ASSET:CASH",
|
|
68
|
+
category=AccountCategory.ASSET,
|
|
69
|
+
currency="CNY",
|
|
70
|
+
)
|
|
71
|
+
ledger.create_account(
|
|
72
|
+
"capital-account-uuid",
|
|
73
|
+
portfolio_id="portfolio-uuid",
|
|
74
|
+
code="EQUITY:CONTRIBUTED_CAPITAL",
|
|
75
|
+
category=AccountCategory.EQUITY,
|
|
76
|
+
currency="CNY",
|
|
77
|
+
)
|
|
78
|
+
ledger.post(
|
|
79
|
+
TransactionDraft(
|
|
80
|
+
portfolio_id="portfolio-uuid",
|
|
81
|
+
source_namespace="app.capital",
|
|
82
|
+
idempotency_key="capital-flow-uuid",
|
|
83
|
+
event_code="CAPITAL_FLOW",
|
|
84
|
+
business_date="2026-08-03",
|
|
85
|
+
currency="CNY",
|
|
86
|
+
postings=(
|
|
87
|
+
PostingDraft("cash-account-uuid", 100_00),
|
|
88
|
+
PostingDraft("capital-account-uuid", -100_00),
|
|
89
|
+
),
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
connection.commit()
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Non-goals
|
|
96
|
+
|
|
97
|
+
The package does not define trading strategies, orders, options, QMT behavior,
|
|
98
|
+
HTTP APIs, UI, market prices, settlement calendars, or bank/broker transfers.
|
|
99
|
+
Generic `event_code`, `source_type`, and JSON dimensions let each application
|
|
100
|
+
attach its own domain semantics without coupling those semantics to the SDK.
|
a_ledger-0.1.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# a-ledger
|
|
2
|
+
|
|
3
|
+
`a-ledger` is an application-neutral, SQLite-backed double-entry ledger SDK.
|
|
4
|
+
It owns accounting primitives and persistence; calling applications own business
|
|
5
|
+
commands, broker integration, market calendars, projections, APIs, and pages.
|
|
6
|
+
|
|
7
|
+
## Accounting convention
|
|
8
|
+
|
|
9
|
+
- Money is stored as integer minor units; posted amounts never use `float`.
|
|
10
|
+
- A positive posting is a debit and a negative posting is a credit.
|
|
11
|
+
- Every posted transaction balances exactly to zero.
|
|
12
|
+
- Accounts use one of `ASSET`, `LIABILITY`, `EQUITY`, `INCOME`, or `EXPENSE`.
|
|
13
|
+
- Security quantities and cost lots are replayed from immutable lot events. There
|
|
14
|
+
are no persisted balance or position snapshots.
|
|
15
|
+
- Posted transactions, postings, lots, lot events, and audit events cannot be
|
|
16
|
+
updated or deleted. Corrections use linked reversal and replacement entries.
|
|
17
|
+
- Reservations are mutable authorization state, not accounting entries.
|
|
18
|
+
|
|
19
|
+
## Transaction ownership
|
|
20
|
+
|
|
21
|
+
The caller supplies a `sqlite3.Connection`, enables a short transaction, and
|
|
22
|
+
decides whether to commit or roll back. Write APIs reject calls without an active
|
|
23
|
+
caller-owned transaction. The SDK never calls `commit()` or `rollback()` and
|
|
24
|
+
never runs network or application callbacks.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import sqlite3
|
|
28
|
+
|
|
29
|
+
from a_ledger import AccountCategory, Ledger, PostingDraft, TransactionDraft
|
|
30
|
+
|
|
31
|
+
connection = sqlite3.connect("application.sqlite3")
|
|
32
|
+
ledger = Ledger(connection) # enables and verifies SQLite foreign keys
|
|
33
|
+
|
|
34
|
+
connection.execute("BEGIN IMMEDIATE")
|
|
35
|
+
ledger.install_schema()
|
|
36
|
+
ledger.create_portfolio("portfolio-uuid", code="main", currency="CNY")
|
|
37
|
+
ledger.create_account(
|
|
38
|
+
"cash-account-uuid",
|
|
39
|
+
portfolio_id="portfolio-uuid",
|
|
40
|
+
code="ASSET:CASH",
|
|
41
|
+
category=AccountCategory.ASSET,
|
|
42
|
+
currency="CNY",
|
|
43
|
+
)
|
|
44
|
+
ledger.create_account(
|
|
45
|
+
"capital-account-uuid",
|
|
46
|
+
portfolio_id="portfolio-uuid",
|
|
47
|
+
code="EQUITY:CONTRIBUTED_CAPITAL",
|
|
48
|
+
category=AccountCategory.EQUITY,
|
|
49
|
+
currency="CNY",
|
|
50
|
+
)
|
|
51
|
+
ledger.post(
|
|
52
|
+
TransactionDraft(
|
|
53
|
+
portfolio_id="portfolio-uuid",
|
|
54
|
+
source_namespace="app.capital",
|
|
55
|
+
idempotency_key="capital-flow-uuid",
|
|
56
|
+
event_code="CAPITAL_FLOW",
|
|
57
|
+
business_date="2026-08-03",
|
|
58
|
+
currency="CNY",
|
|
59
|
+
postings=(
|
|
60
|
+
PostingDraft("cash-account-uuid", 100_00),
|
|
61
|
+
PostingDraft("capital-account-uuid", -100_00),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
connection.commit()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Non-goals
|
|
69
|
+
|
|
70
|
+
The package does not define trading strategies, orders, options, QMT behavior,
|
|
71
|
+
HTTP APIs, UI, market prices, settlement calendars, or bank/broker transfers.
|
|
72
|
+
Generic `event_code`, `source_type`, and JSON dimensions let each application
|
|
73
|
+
attach its own domain semantics without coupling those semantics to the SDK.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "a-ledger"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Application-neutral double-entry ledger SDK backed by SQLite"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "realqiyan" }]
|
|
13
|
+
keywords = ["ledger", "accounting", "double-entry", "sqlite", "bookkeeping"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Office/Business :: Financial :: Accounting",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/realqiyan/a-ledger"
|
|
27
|
+
Repository = "https://github.com/realqiyan/a-ledger"
|
|
28
|
+
Issues = "https://github.com/realqiyan/a-ledger/issues"
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = ["build>=1", "pytest>=8", "twine>=5"]
|
|
32
|
+
|
|
33
|
+
[tool.setuptools]
|
|
34
|
+
license-files = ["LICENSE"]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
addopts = "-q"
|
|
41
|
+
pythonpath = ["src"]
|
|
42
|
+
testpaths = ["tests"]
|
a_ledger-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from .errors import LedgerError
|
|
2
|
+
from .ledger import Ledger
|
|
3
|
+
from .models import (
|
|
4
|
+
AccountCategory,
|
|
5
|
+
LotAllocation,
|
|
6
|
+
LotOperation,
|
|
7
|
+
LotEventKind,
|
|
8
|
+
Money,
|
|
9
|
+
OpenLot,
|
|
10
|
+
PostResult,
|
|
11
|
+
PostingDraft,
|
|
12
|
+
Price,
|
|
13
|
+
Reservation,
|
|
14
|
+
ReservationKind,
|
|
15
|
+
ReservationStatus,
|
|
16
|
+
TransactionDraft,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"AccountCategory",
|
|
21
|
+
"Ledger",
|
|
22
|
+
"LedgerError",
|
|
23
|
+
"LotAllocation",
|
|
24
|
+
"LotOperation",
|
|
25
|
+
"LotEventKind",
|
|
26
|
+
"Money",
|
|
27
|
+
"OpenLot",
|
|
28
|
+
"PostResult",
|
|
29
|
+
"PostingDraft",
|
|
30
|
+
"Price",
|
|
31
|
+
"Reservation",
|
|
32
|
+
"ReservationKind",
|
|
33
|
+
"ReservationStatus",
|
|
34
|
+
"TransactionDraft",
|
|
35
|
+
]
|