loadledger 0.1.0__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.
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
loadledger/__init__.py ADDED
@@ -0,0 +1,77 @@
1
+ """LoadLedger — budget accumulation and ceilings over ADR-0030's cost model.
2
+
3
+ Layer 3 capability package. It adds two things to what BaseAiCore already has, and deliberately
4
+ nothing else: it **adds spend up across a multi-step run**, and it **says when a ceiling is
5
+ crossed**. There is no pricing here (prices arrive as ``ModelPricing`` records the caller
6
+ acquired), no currency conversion (ADR-0030 rule 3), and no policy — the ledger answers "would
7
+ this exceed?" and "what remains?", and halting, pausing or re-approving is the caller's decision.
8
+
9
+ This module is pure: no I/O, no SQL, no logging, no environment, and `baseaicore` is its only
10
+ dependency. Durability lives in ``loadledger.sql`` — ``mount_ledger_tables`` and ``SqlLedger``,
11
+ under the ``loadledger[sql]`` extra — which is deliberately **not** imported here, so installing
12
+ this package never drags in an ORM (ADR-0050 decision 4). Import it explicitly:
13
+ ``from loadledger.sql import SqlLedger``.
14
+
15
+ >>> from datetime import UTC, datetime
16
+ >>> from baseaicore import Money, TokenUsage
17
+ >>> from loadledger import BudgetCeiling, CeilingScope, Debit, InMemoryLedger
18
+ >>> clock = lambda: datetime(2026, 9, 2, 12, 0, tzinfo=UTC)
19
+ >>> ledger = InMemoryLedger(
20
+ ... [BudgetCeiling(scope=CeilingScope.PER_RUN, tokens=2_000_000)], clock=clock
21
+ ... )
22
+ >>> entry = ledger.debit(
23
+ ... Debit(
24
+ ... run_id="traj-1",
25
+ ... source_ref="turn-1",
26
+ ... usage=TokenUsage(input_tokens=1_200, output_tokens=340),
27
+ ... cost=None,
28
+ ... )
29
+ ... )
30
+ >>> entry.unpriced, entry.verdicts[0].tokens_spent, entry.verdicts[0].exceeded
31
+ (True, 1540, False)
32
+
33
+ Anything not listed in ``__all__`` is private and may change without a version bump, whatever its
34
+ module happens to be named. ``Money`` is not re-exported: it is BaseAiCore's, and a second name
35
+ for one type is how two components stop agreeing about it.
36
+ """
37
+
38
+ from __future__ import annotations
39
+
40
+ from loadledger.__about__ import __version__
41
+ from loadledger.core import BalanceBook, Ledger, utc_day_key, utc_day_start
42
+ from loadledger.errors import (
43
+ CurrencyMismatch,
44
+ InvalidCeiling,
45
+ LedgerError,
46
+ UnknownRun,
47
+ UnsupportedDialect,
48
+ )
49
+ from loadledger.memory import InMemoryLedger
50
+ from loadledger.types import (
51
+ BudgetCeiling,
52
+ CeilingScope,
53
+ CeilingVerdict,
54
+ Debit,
55
+ LedgerEntry,
56
+ PartialPricing,
57
+ )
58
+
59
+ __all__ = [
60
+ "BalanceBook",
61
+ "BudgetCeiling",
62
+ "CeilingScope",
63
+ "CeilingVerdict",
64
+ "CurrencyMismatch",
65
+ "Debit",
66
+ "InMemoryLedger",
67
+ "InvalidCeiling",
68
+ "Ledger",
69
+ "LedgerEntry",
70
+ "LedgerError",
71
+ "PartialPricing",
72
+ "UnknownRun",
73
+ "UnsupportedDialect",
74
+ "__version__",
75
+ "utc_day_key",
76
+ "utc_day_start",
77
+ ]