tariff-core 2026.10.1__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.
- tariff_core-2026.10.1/.github/copilot-instructions.md +119 -0
- tariff_core-2026.10.1/.github/workflows/ci.yml +39 -0
- tariff_core-2026.10.1/.github/workflows/lint.yml +55 -0
- tariff_core-2026.10.1/.github/workflows/python-publish.yml +70 -0
- tariff_core-2026.10.1/.github/workflows/release.yml +29 -0
- tariff_core-2026.10.1/.gitignore +14 -0
- tariff_core-2026.10.1/CHANGELOG.md +7 -0
- tariff_core-2026.10.1/LICENSE +21 -0
- tariff_core-2026.10.1/PKG-INFO +76 -0
- tariff_core-2026.10.1/README.md +43 -0
- tariff_core-2026.10.1/docs/schema.md +323 -0
- tariff_core-2026.10.1/pyproject.toml +73 -0
- tariff_core-2026.10.1/requirements.txt +1 -0
- tariff_core-2026.10.1/scripts/gen_schema.py +267 -0
- tariff_core-2026.10.1/src/tariff_core/__init__.py +133 -0
- tariff_core-2026.10.1/src/tariff_core/adapters/__init__.py +1 -0
- tariff_core-2026.10.1/src/tariff_core/adapters/cdr.py +446 -0
- tariff_core-2026.10.1/src/tariff_core/contract.py +60 -0
- tariff_core-2026.10.1/src/tariff_core/data/origin_ergon.json +1 -0
- tariff_core-2026.10.1/src/tariff_core/engine/__init__.py +26 -0
- tariff_core-2026.10.1/src/tariff_core/engine/bill.py +712 -0
- tariff_core-2026.10.1/src/tariff_core/engine/blocks.py +81 -0
- tariff_core-2026.10.1/src/tariff_core/engine/demand.py +55 -0
- tariff_core-2026.10.1/src/tariff_core/engine/rates.py +275 -0
- tariff_core-2026.10.1/src/tariff_core/errors.py +10 -0
- tariff_core-2026.10.1/src/tariff_core/jsonschema/.gitkeep +0 -0
- tariff_core-2026.10.1/src/tariff_core/jsonschema/plan.v1.json +3434 -0
- tariff_core-2026.10.1/src/tariff_core/models.py +325 -0
- tariff_core-2026.10.1/src/tariff_core/parse.py +811 -0
- tariff_core-2026.10.1/src/tariff_core/py.typed +0 -0
- tariff_core-2026.10.1/src/tariff_core/schedule.py +94 -0
- tariff_core-2026.10.1/src/tariff_core/serialise.py +277 -0
- tariff_core-2026.10.1/src/tariff_core/units.py +74 -0
- tariff_core-2026.10.1/src/tariff_core/validate.py +142 -0
- tariff_core-2026.10.1/tests/fixtures/plans/cdr/ORI1161031MRE3@EME.json +1 -0
- tariff_core-2026.10.1/tests/fixtures/plans/cdr/ORI1202131MRE2@EME.json +1 -0
- tariff_core-2026.10.1/tests/fixtures/plans/cdr/ORI931606MBG4@EME.json +1 -0
- tariff_core-2026.10.1/tests/fixtures/plans/cdr/ORI988028MBE7@EME.json +1 -0
- tariff_core-2026.10.1/tests/fixtures/plans/gas.json +16 -0
- tariff_core-2026.10.1/tests/fixtures/plans/origin_ergon.yaml +34 -0
- tariff_core-2026.10.1/tests/fixtures/plans/water.json +14 -0
- tariff_core-2026.10.1/tests/golden/.gitkeep +0 -0
- tariff_core-2026.10.1/tests/test_bill.py +403 -0
- tariff_core-2026.10.1/tests/test_cdr.py +135 -0
- tariff_core-2026.10.1/tests/test_jsonschema.py +113 -0
- tariff_core-2026.10.1/tests/test_parse.py +558 -0
- tariff_core-2026.10.1/tests/test_public_api.py +62 -0
- tariff_core-2026.10.1/tests/test_rates.py +268 -0
- tariff_core-2026.10.1/tests/test_scaffold.py +29 -0
- tariff_core-2026.10.1/tests/test_serialise.py +145 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Copilot instructions: tariff-core
|
|
2
|
+
|
|
3
|
+
## What this repo is
|
|
4
|
+
|
|
5
|
+
`tariff-core` is a pure Python library that models electricity, gas and water tariff plans, validates them and calculates bills and rates from interval usage data. It is the single source of truth for the plan schema (`docs/schema.md`).
|
|
6
|
+
|
|
7
|
+
It is consumed by:
|
|
8
|
+
|
|
9
|
+
- `tariff-catalogue`: harvests and publishes plans; uses this library to normalise and validate them
|
|
10
|
+
- `ha-energy-tariff`: the Home Assistant custom integration; uses this library to evaluate plans locally
|
|
11
|
+
- potentially other tools (evcc, EMHASS, Predbat), so the API must not assume Home Assistant
|
|
12
|
+
|
|
13
|
+
Read `docs/schema.md` before changing any model, validator or engine code.
|
|
14
|
+
|
|
15
|
+
## Hard constraints
|
|
16
|
+
|
|
17
|
+
- **No I/O.** No network calls, no file system access outside explicit `load_*`/`dump_*` helpers that take a path or a string. No logging configuration. The library must be importable and fully usable offline.
|
|
18
|
+
- **No Home Assistant imports**, ever. Home Assistant-specific concepts (entities, `hass`, config entries) do not exist here.
|
|
19
|
+
- **Synchronous, side-effect-free functions.** Home Assistant will call this from an executor or wrap it; do not add `async`.
|
|
20
|
+
- **Money is `decimal.Decimal`.** Never use `float` for rates, costs or credits. Parse JSON numbers and strings into `Decimal` at the boundary; reject floats in monetary fields.
|
|
21
|
+
- **Time uses `zoneinfo` and timezone-aware `datetime` only.** Naive datetimes are a `ValueError`.
|
|
22
|
+
- **Minimal dependencies.** Home Assistant pins many packages, so conflicts are costly. Allowed runtime dependencies: `python-holidays` (optional extra `[holidays]`). Do not add `pydantic`, `pandas`, `numpy`, `attrs` or `arrow`. Use `dataclasses` (`frozen=True`, `slots=True`) and the standard library.
|
|
23
|
+
- **Python version:** match the oldest Python supported by current Home Assistant releases (3.13 at time of writing). Check `pyproject.toml` `requires-python`.
|
|
24
|
+
|
|
25
|
+
## Package layout
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
src/tariff_core/
|
|
29
|
+
__init__.py # public API re-exports only
|
|
30
|
+
models.py # frozen dataclasses mirroring docs/schema.md
|
|
31
|
+
parse.py # dict/JSON/YAML -> models; strict, with useful error paths
|
|
32
|
+
serialise.py # models -> canonical JSON; content hashing
|
|
33
|
+
validate.py # structural + semantic validation (coverage, refs, codes)
|
|
34
|
+
schedule.py # window matching, half-open intervals, midnight wrap, seasons, holidays
|
|
35
|
+
units.py # dimensions, exact Decimal conversion constants, contract conversions
|
|
36
|
+
engine/
|
|
37
|
+
rates.py # rate_at(), forecast()
|
|
38
|
+
bill.py # bill() -> Bill with line items
|
|
39
|
+
demand.py # demand charge methods
|
|
40
|
+
blocks.py # stepped/block pricing and pro-rating
|
|
41
|
+
contract.py # Contract, ContractSegment, segment lookup, overrides (JSON pointer)
|
|
42
|
+
adapters/ # source-format -> PlanVersion converters (pure functions)
|
|
43
|
+
cdr.py # Australian CDR Energy plan detail (x-v 3), electricity and gas -> PlanVersion
|
|
44
|
+
jsonschema/
|
|
45
|
+
plan.v1.json # generated, do not hand-edit (see scripts/gen_schema.py)
|
|
46
|
+
tests/
|
|
47
|
+
docs/schema.md
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Adapters live here (not in `tariff-catalogue`) because they are pure transformations and both the pipeline and tests need them. Fetching data is **not** an adapter's job.
|
|
51
|
+
|
|
52
|
+
## Public API (keep stable; changes need a changelog entry)
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
parse_plan(data: Mapping | str) -> PlanVersion
|
|
56
|
+
validate_plan(plan: PlanVersion) -> list[ValidationIssue] # empty = valid
|
|
57
|
+
validate_contract(contract: Contract) -> list[ValidationIssue]
|
|
58
|
+
convert(quantity: Decimal, from_unit: str, to_unit: str) -> Decimal # same dimension only
|
|
59
|
+
content_hash(plan: PlanVersion) -> str
|
|
60
|
+
dump_plan(plan: PlanVersion) -> str # canonical JSON
|
|
61
|
+
|
|
62
|
+
rate_at(plan, when: datetime, *, register="general", direction="import",
|
|
63
|
+
resolved: Mapping[str, Decimal] | None = None) -> RateInfo
|
|
64
|
+
forecast(plan, start: datetime, end: datetime, *, register="general",
|
|
65
|
+
direction="import") -> list[RateSlot]
|
|
66
|
+
|
|
67
|
+
bill(plan, intervals: Iterable[Interval], *, period: BillingPeriod,
|
|
68
|
+
resolved_rates: RateResolver | None = None) -> Bill
|
|
69
|
+
|
|
70
|
+
Contract.active_segment(when: datetime) -> ContractSegment
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- `RateInfo` carries: `rate`, `period`, `period_label`, `next_change`, `next_rate`, `next_period`.
|
|
74
|
+
- `Interval` carries: `end` (interval-ending timestamp), `duration`, `register`, `unit`, `import_qty`, `export_qty`, optional `demand_kw`/`demand_kva`. Quantities are in the meter's unit; `bill()` converts to each component's `quantity_unit` using `units.py` and the contract's `conversions`. Intervals may be long (daily, monthly, quarterly reads for gas and water).
|
|
75
|
+
- `Bill` carries line items (`component`, `quantity`, `unit`, `rate`, `amount`, `type: cost | credit`), subtotals, tax, total and a list of warnings (e.g. dynamic rate missing for 3 intervals).
|
|
76
|
+
- Dynamic rates (`rate: {entity: …}`) are resolved by the caller through `RateResolver`. The library never reads entities.
|
|
77
|
+
|
|
78
|
+
## Behaviour rules (from the schema; tests must enforce them)
|
|
79
|
+
|
|
80
|
+
- Windows are half-open `[start, end)`. Midnight-wrapping windows are normal.
|
|
81
|
+
- Interval data is interval-ending. Window lookup uses the interval **start** (`end - duration`).
|
|
82
|
+
- CDR inclusive end times (`HH:59`) are converted to the next minute in `adapters/cdr.py`.
|
|
83
|
+
- Export credits are negative rates internally; `Bill` line items always show positive amounts with `type`.
|
|
84
|
+
- Units convert within a dimension only (energy, volume, power). Gas volume → energy uses the contract's dated `conversions` (heating value × correction factor); never a built-in constant. `gal` is the US gallon.
|
|
85
|
+
- Derived quantities (e.g. sewerage = 0.85 × water) are computed from their source register before billing; cycles are a validation error.
|
|
86
|
+
- Long intervals that span a season or rate change are split pro-rata by elapsed time, with a warning on the `Bill`.
|
|
87
|
+
- Every `(register, direction, season)` with usage components must cover 168 h/week after precedence (scheduled beats anytime, seasonal beats all-year); schedules are lists of windows; seasons are MM-DD half-open ranges covering the year.
|
|
88
|
+
- Demand: average power over each interval (`kWh / hours`), not instantaneous, unless `method: max_instant`.
|
|
89
|
+
- Block pricing: thresholds pro-rated by billing-period length when `prorate: true`.
|
|
90
|
+
- Conditional discounts are excluded from `bill()` unless `include_conditional=True`.
|
|
91
|
+
- Incentives never affect `bill()`.
|
|
92
|
+
|
|
93
|
+
## Testing
|
|
94
|
+
|
|
95
|
+
- `pytest`, `pytest-cov`; target ≥ 95% line coverage on `engine/` and `schedule.py`.
|
|
96
|
+
- Use `hypothesis` for schedule coverage and window matching (random windows, midnight wraps, DST transitions in `Australia/Sydney` and `Europe/Amsterdam`).
|
|
97
|
+
- Golden tests in `tests/golden/`: real plans (e.g. the Origin Ergon plan `ORI1161031MRE3@EME`, Energex `6900`, one Origin Queensland gas plan, and one hand-built water plan with derived sewerage) with hand-calculated bills from fixed interval CSVs. A golden test must document where its expected numbers came from.
|
|
98
|
+
- Every bug fix starts with a failing test.
|
|
99
|
+
- Never use floats in test expectations for money; compare `Decimal`s.
|
|
100
|
+
|
|
101
|
+
## Tooling
|
|
102
|
+
|
|
103
|
+
- `ruff` (lint + format), `mypy --strict` on `src/`.
|
|
104
|
+
- `pyproject.toml` with `hatchling`; version from git tags.
|
|
105
|
+
- CI: lint, type-check, tests on all supported Python versions, regenerate JSON Schema and fail if it differs from the committed file.
|
|
106
|
+
|
|
107
|
+
## Style
|
|
108
|
+
|
|
109
|
+
- Small pure functions, explicit types, no global state, no singletons.
|
|
110
|
+
- Error messages include the JSON path of the problem (e.g. `components[3].schedule`).
|
|
111
|
+
- Docstrings explain *why* and units; do not restate the signature.
|
|
112
|
+
- Prefer clear names from the schema vocabulary (`commodity`, `register`, `direction`, `period`, `quantity_unit`) over synonyms. Never name anything `kwh` unless it is specifically kWh.
|
|
113
|
+
|
|
114
|
+
## Do not
|
|
115
|
+
|
|
116
|
+
- Add fetching, caching or scheduling code.
|
|
117
|
+
- Introduce float arithmetic for money "for performance".
|
|
118
|
+
- Add Home Assistant, evcc or vendor-specific concepts to models.
|
|
119
|
+
- Change `docs/schema.md` semantics without bumping the schema version and adding a migration.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
checks:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.13", "3.14"]
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v5
|
|
19
|
+
with:
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
persist-credentials: false
|
|
22
|
+
- uses: actions/setup-python@v6
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python-version }}
|
|
25
|
+
cache: pip
|
|
26
|
+
- name: Install development tools and package
|
|
27
|
+
run: python -m pip install ".[dev]"
|
|
28
|
+
- name: Lint
|
|
29
|
+
run: python -m ruff check .
|
|
30
|
+
- name: Check formatting
|
|
31
|
+
run: python -m ruff format --check .
|
|
32
|
+
- name: Type-check
|
|
33
|
+
run: python -m mypy --strict src/
|
|
34
|
+
- name: Check generated JSON Schema
|
|
35
|
+
run: python scripts/gen_schema.py --check
|
|
36
|
+
- name: Test
|
|
37
|
+
run: python -m pytest --cov=tariff_core --cov-report=term-missing
|
|
38
|
+
- name: Build wheel and source distribution
|
|
39
|
+
run: python -m hatchling build
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- "main"
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- "main"
|
|
10
|
+
|
|
11
|
+
permissions: {}
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
ruff:
|
|
15
|
+
name: "Ruff"
|
|
16
|
+
runs-on: "ubuntu-latest"
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout the repository
|
|
19
|
+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.14.8"
|
|
25
|
+
cache: "pip"
|
|
26
|
+
|
|
27
|
+
- name: Install requirements
|
|
28
|
+
run: python3 -m pip install -r requirements.txt
|
|
29
|
+
|
|
30
|
+
- name: Lint
|
|
31
|
+
run: python3 -m ruff check .
|
|
32
|
+
|
|
33
|
+
- name: Check formatting
|
|
34
|
+
run: python3 -m ruff format . --check
|
|
35
|
+
|
|
36
|
+
test:
|
|
37
|
+
name: "Tests"
|
|
38
|
+
runs-on: "ubuntu-latest"
|
|
39
|
+
steps:
|
|
40
|
+
- name: Checkout the repository
|
|
41
|
+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
42
|
+
with:
|
|
43
|
+
fetch-depth: 0
|
|
44
|
+
|
|
45
|
+
- name: Set up Python
|
|
46
|
+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
47
|
+
with:
|
|
48
|
+
python-version: "3.14.8"
|
|
49
|
+
cache: "pip"
|
|
50
|
+
|
|
51
|
+
- name: Install test dependencies
|
|
52
|
+
run: python3 -m pip install -r requirements.txt
|
|
53
|
+
|
|
54
|
+
- name: Test
|
|
55
|
+
run: python3 -m pytest
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# This workflow will upload a Python Package to PyPI when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
release-build:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.x"
|
|
28
|
+
|
|
29
|
+
- name: Build release distributions
|
|
30
|
+
run: |
|
|
31
|
+
# NOTE: put your own distribution build steps here.
|
|
32
|
+
python -m pip install build
|
|
33
|
+
python -m build
|
|
34
|
+
|
|
35
|
+
- name: Upload distributions
|
|
36
|
+
uses: actions/upload-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: release-dists
|
|
39
|
+
path: dist/
|
|
40
|
+
|
|
41
|
+
pypi-publish:
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
needs:
|
|
44
|
+
- release-build
|
|
45
|
+
permissions:
|
|
46
|
+
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
47
|
+
id-token: write
|
|
48
|
+
|
|
49
|
+
# Dedicated environments with protections for publishing are strongly recommended.
|
|
50
|
+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
|
|
51
|
+
environment:
|
|
52
|
+
name: pypi
|
|
53
|
+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
|
|
54
|
+
# url: https://pypi.org/p/YOURPROJECT
|
|
55
|
+
#
|
|
56
|
+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
|
|
57
|
+
# ALTERNATIVE: exactly, uncomment the following line instead:
|
|
58
|
+
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- name: Retrieve release distributions
|
|
62
|
+
uses: actions/download-artifact@v4
|
|
63
|
+
with:
|
|
64
|
+
name: release-dists
|
|
65
|
+
path: dist/
|
|
66
|
+
|
|
67
|
+
- name: Publish release distributions to PyPI
|
|
68
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
69
|
+
with:
|
|
70
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
id-token: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v5
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
persist-credentials: false
|
|
21
|
+
- uses: actions/setup-python@v6
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.13"
|
|
24
|
+
- name: Install build backend
|
|
25
|
+
run: python -m pip install "hatchling>=1.32.4" "hatch-vcs>=0.5.0"
|
|
26
|
+
- name: Build distributions
|
|
27
|
+
run: python -m hatchling build
|
|
28
|
+
- name: Publish to PyPI
|
|
29
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chris Abberley
|
|
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,76 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tariff-core
|
|
3
|
+
Version: 2026.10.1
|
|
4
|
+
Summary: Pure Python electricity, gas and water tariff modelling and evaluation.
|
|
5
|
+
Project-URL: Documentation, https://github.com/cabberley/tariff-core/blob/main/docs/schema.md
|
|
6
|
+
Project-URL: Issues, https://github.com/cabberley/tariff-core/issues
|
|
7
|
+
Project-URL: Source, https://github.com/cabberley/tariff-core
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Requires-Python: >=3.13
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: hatch-vcs>=0.5.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: hatchling>=1.32.4; extra == 'dev'
|
|
20
|
+
Requires-Dist: holidays>=0.106; extra == 'dev'
|
|
21
|
+
Requires-Dist: hypothesis>=6.168.5; extra == 'dev'
|
|
22
|
+
Requires-Dist: jsonschema>=4.26.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: mypy>=2.4.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=9.1.1; extra == 'dev'
|
|
26
|
+
Requires-Dist: pyyaml>=6.0.2; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.16.10; extra == 'dev'
|
|
28
|
+
Provides-Extra: holidays
|
|
29
|
+
Requires-Dist: holidays>=0.106; extra == 'holidays'
|
|
30
|
+
Provides-Extra: yaml
|
|
31
|
+
Requires-Dist: pyyaml>=6.0.2; extra == 'yaml'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# tariff-core
|
|
35
|
+
|
|
36
|
+
`tariff-core` is a pure Python library for modelling electricity, gas and water tariffs. It parses and validates tariff plans, calculates rates and bills, and works offline without Home Assistant or other application-specific dependencies.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
python -m pip install tariff-core
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
YAML support is optional: install `tariff-core[yaml]` to parse YAML documents.
|
|
45
|
+
|
|
46
|
+
## Example
|
|
47
|
+
|
|
48
|
+
This example loads the Origin Ergon fixture, prints its current tariff rate, then bills one day of hourly usage:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from datetime import datetime, time, timedelta
|
|
52
|
+
from decimal import Decimal
|
|
53
|
+
from importlib.resources import files
|
|
54
|
+
from zoneinfo import ZoneInfo
|
|
55
|
+
|
|
56
|
+
from tariff_core import BillingPeriod, Interval, bill, parse_plan, rate_at
|
|
57
|
+
|
|
58
|
+
plan = parse_plan(files("tariff_core").joinpath("data", "origin_ergon.json").read_text())
|
|
59
|
+
zone = ZoneInfo("Australia/Brisbane")
|
|
60
|
+
now = datetime.now(zone)
|
|
61
|
+
start = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
62
|
+
rate = rate_at(plan, now)
|
|
63
|
+
print(f"Current rate: {rate.rate} per kWh ({rate.period_label})")
|
|
64
|
+
intervals = [
|
|
65
|
+
Interval(start + timedelta(hours=hour), timedelta(hours=1), "general", "kWh", Decimal("1"))
|
|
66
|
+
for hour in range(1, 25)
|
|
67
|
+
]
|
|
68
|
+
result = bill(
|
|
69
|
+
plan,
|
|
70
|
+
intervals,
|
|
71
|
+
period=BillingPeriod(start, start + timedelta(days=1)),
|
|
72
|
+
)
|
|
73
|
+
print(f"One-day total: {result.total_rounded}")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
See the [tariff plan schema](docs/schema.md) for the data model and validation rules.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# tariff-core
|
|
2
|
+
|
|
3
|
+
`tariff-core` is a pure Python library for modelling electricity, gas and water tariffs. It parses and validates tariff plans, calculates rates and bills, and works offline without Home Assistant or other application-specific dependencies.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python -m pip install tariff-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
YAML support is optional: install `tariff-core[yaml]` to parse YAML documents.
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
|
+
|
|
15
|
+
This example loads the Origin Ergon fixture, prints its current tariff rate, then bills one day of hourly usage:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from datetime import datetime, time, timedelta
|
|
19
|
+
from decimal import Decimal
|
|
20
|
+
from importlib.resources import files
|
|
21
|
+
from zoneinfo import ZoneInfo
|
|
22
|
+
|
|
23
|
+
from tariff_core import BillingPeriod, Interval, bill, parse_plan, rate_at
|
|
24
|
+
|
|
25
|
+
plan = parse_plan(files("tariff_core").joinpath("data", "origin_ergon.json").read_text())
|
|
26
|
+
zone = ZoneInfo("Australia/Brisbane")
|
|
27
|
+
now = datetime.now(zone)
|
|
28
|
+
start = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
29
|
+
rate = rate_at(plan, now)
|
|
30
|
+
print(f"Current rate: {rate.rate} per kWh ({rate.period_label})")
|
|
31
|
+
intervals = [
|
|
32
|
+
Interval(start + timedelta(hours=hour), timedelta(hours=1), "general", "kWh", Decimal("1"))
|
|
33
|
+
for hour in range(1, 25)
|
|
34
|
+
]
|
|
35
|
+
result = bill(
|
|
36
|
+
plan,
|
|
37
|
+
intervals,
|
|
38
|
+
period=BillingPeriod(start, start + timedelta(days=1)),
|
|
39
|
+
)
|
|
40
|
+
print(f"One-day total: {result.total_rounded}")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
See the [tariff plan schema](docs/schema.md) for the data model and validation rules.
|