Skip to main content

tax-engine: an open-source income tax calculation engine in Python

CI PyPI License: Apache-2.0 Python 3.12+

tax-engine is a personal income tax calculation library where every number is a line on a real tax form, and every result explains itself in a readable trace.

Tax rules live as data taken as printed from the tax authority's own forms. Each form line is one small, tested step. You can follow any figure back to the form line it came from. It powers the live take-home calculator at aftertaxlens.com.

Supported today: Canada (federal), Ontario and Alberta, tax years 2025 and 2026 (2026 is provisional). More forms, lines, years and jurisdictions are added over time (see Coverage).

Example: a $70,000 salary (tax year 2025)

Given only a gross salary, the engine works out the contributions and tax from the CRA forms. Take-home is then salary minus CPP, EI and total tax, a subtraction done by the caller outside the engine:

Item Amount
Federal tax 7,585.64
Ontario tax (ON428, incl. health premium) 3,911.45
Total tax 11,497.09
CPP contributions (base 3,291.75 + enhanced 665.00) 3,956.75
EI premiums 1,077.48
Take-home 53,468.68

Every figure the engine computes comes with a trace saying how it was reached. Each trace line is about one figure (line.label), and its sentence names the figures it uses as the form prints them, so a caller shows the figure beside the sentence. This is the trace for the last Ontario line (ON428 line 90, "Ontario tax"):

line 90: Line 88 (CA$3311.45) plus line 89 (CA$600.00) gives CA$3911.45 (rounded to the nearest cent).

Why tax-engine

  • Explains itself. A trace for every line: inputs, operation, result, rounding. A renderer turns it into text in any language; English is built today.
  • Mirrors the forms. One form line is one capability, so engine steps read like the form itself.
  • Rules are data. Rates, thresholds and limits are datasets copied as printed, never recomputed in code.
  • Follows the published forms. The engine follows the CRA's published forms and formulas, including the T4127 payroll guide, line by line. It is an independent estimation tool and has not been reviewed or approved by the CRA.
  • Exact arithmetic. Decimal everywhere, rounding only where the form says to round.
  • Jurisdiction-agnostic core. Jurisdictions are plugins that add forms, datasets and capabilities; adding one does not change the core.

Quick start

Requires Python 3.12 or newer. Install from PyPI:

pip install tax-engine

To work on the engine itself, install from a checkout instead:

git clone https://github.com/The-Pied-Piper/tax-engine.git
cd tax-engine
pip install -e .

Run the example, which prints the English trace for every form (the argument is the gross salary):

python examples/quickstart.py 70000

examples/quickstart.py:

import sys
from decimal import Decimal

from tax_engine import build_tax_computation
from tax_engine.adapters.inbound.trace_english import EnglishNames, EnglishTraceRenderer
from tax_engine.domain.artifact import Artifact
from tax_engine.domain.jurisdiction_code import JurisdictionCode
from tax_engine.jurisdictions.ca.catalog.income import EMPLOYMENT_INCOME

engine = build_tax_computation()
sheets = engine.compute(
    JurisdictionCode("CA-ON"), 2025, Artifact(EMPLOYMENT_INCOME, Decimal(sys.argv[1]))
)
for form, form_sheets in sheets.items():
    for sheet in form_sheets:
        print(f"\n== {form} ==")
        renderer = EnglishTraceRenderer()
        names = EnglishNames(sheet)
        for line in sheet.trace:
            # The sentence names the figures it uses as the form prints them when it is given
            # the worksheet; the figure the line is about is named beside it.
            sentence = renderer.render(line, sheet)
            print(sentence if line.label is None else f"{names.of_label(line.label)}: {sentence}")

The example uses Ontario (CA-ON) and tax year 2025. Change CA-ON to CA-AB for Alberta, and 2025 to 2026 for the provisional 2026 year.

How it works

A jurisdiction's manifest lists the forms that make up a return. Each form is built line by line from small capabilities (sum, bracket tax, credit, cap, and so on) fed by parameter datasets for the tax year. The engine wires the forms together, runs them, and records a trace for every step.

Coverage

Jurisdiction Year Forms and lines built
Canada (federal) 2025, 2026 (provisional) T1 General tax lines, Schedule 8 (CPP), T2204 (EI), Schedule 6 (Canada workers benefit), taxable income
Ontario 2025, 2026 (provisional) ON428 (Ontario tax), ON428-A (LIFT credit)
Alberta 2025, 2026 (provisional) AB428 (Alberta tax), Worksheet AB428 (Alberta supplemental tax credit)

Roadmap: more forms and lines, and other provinces and territories. Forms are added one at a time, each built line by line from the CRA's own text.

Disclaimer and limits

tax-engine is not tax advice and is not an official CRA product. It comes with no warranty, as the Apache-2.0 license says.

It covers tax years 2025 and 2026 (2026 is provisional), Canada (federal), Ontario and Alberta only, and only the forms and lines listed under Coverage. A return with items the engine does not model will not come out right. The take-home example assumes a single filer with salary as the only income.

Check any result against the CRA's own forms or with a professional before relying on it.

Contributing

Issues and pull requests are welcome. Developer setup and checks are in CONTRIBUTING.md.

License

Licensed under the Apache License, Version 2.0.

Metadata

Release files for tax-engine 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tax-engine 0.2.0
File Size Uploaded Provenance Actions
tax_engine-0.2.0.tar.gz 412.5 kB Without provenance Details for tax_engine-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tax-engine 0.2.0
File Interpreter ABI Platform Actions
tax_engine-0.2.0-py3-none-any.whl Python 3 none any Details for tax_engine-0.2.0-py3-none-any.whl

Total release size: 1.2 MB

Release files / tax_engine-0.2.0.tar.gz

Download URL tax_engine-0.2.0.tar.gz
Size 412.5 kB
Tags Source
SHA-256 checksum
How to use checksums
72cffbe229e0cae4e869706d1fd124e16a998e7c3ccc44de5ac6b13ffe979d49
BLAKE2b-256 checksum
How to use checksums
f1ad0166d2094119ef48395d3e75e423c21df1ed085209790b549cd92473b901
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tax_engine-0.2.0-py3-none-any.whl

Download URL tax_engine-0.2.0-py3-none-any.whl
Size 761.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3077f0688bc1c83478bb62c8c8df7e03dd83e729195a5330cda593a93293eeea
BLAKE2b-256 checksum
How to use checksums
d122a4a283a4f886d1e79287c3dc2bc296fd58dde42604763a473fb8db12e96f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for tax-engine 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page