python-taxes 0.1.0__tar.gz → 0.2.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 (21) hide show
  1. python_taxes-0.2.0/LICENSE +21 -0
  2. python_taxes-0.2.0/PKG-INFO +155 -0
  3. python_taxes-0.2.0/README.md +109 -0
  4. python_taxes-0.2.0/pyproject.toml +99 -0
  5. python_taxes-0.2.0/src/python_taxes/__init__.py +7 -0
  6. python_taxes-0.2.0/src/python_taxes/federal/__init__.py +19 -0
  7. python_taxes-0.2.0/src/python_taxes/federal/income/__init__.py +4 -0
  8. python_taxes-0.2.0/src/python_taxes/federal/income/payroll/automated.py +174 -0
  9. python_taxes-0.2.0/src/python_taxes/federal/income/tables/percentage/__init__.py +15 -0
  10. python_taxes-0.2.0/src/python_taxes/federal/income/tables/percentage/automated/hoh.py +309 -0
  11. python_taxes-0.2.0/src/python_taxes/federal/income/tables/percentage/automated/married.py +309 -0
  12. python_taxes-0.2.0/src/python_taxes/federal/income/tables/percentage/automated/single.py +309 -0
  13. python_taxes-0.2.0/src/python_taxes/federal/medicare.py +89 -0
  14. python_taxes-0.2.0/src/python_taxes/federal/social_security.py +57 -0
  15. python_taxes-0.1.0/PKG-INFO +0 -13
  16. python_taxes-0.1.0/pyproject.toml +0 -23
  17. python_taxes-0.1.0/src/python_taxes/federal/calculators/__init__.py +0 -13
  18. python_taxes-0.1.0/src/python_taxes/federal/calculators/medicare.py +0 -88
  19. python_taxes-0.1.0/src/python_taxes/federal/calculators/social_security.py +0 -32
  20. {python_taxes-0.1.0/src/python_taxes → python_taxes-0.2.0/src/python_taxes/federal/income/payroll}/__init__.py +0 -0
  21. /python_taxes-0.1.0/README.md → /python_taxes-0.2.0/src/python_taxes/federal/income/tables/percentage/automated/__init__.py +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Stacy Noland
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,155 @@
1
+ Metadata-Version: 2.3
2
+ Name: python-taxes
3
+ Version: 0.2.0
4
+ Summary: A Python library for calculating US Social Security, Medicare, and Federal Income taxes.
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 Stacy Noland
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ Author: Stacy Noland
27
+ Author-email: 46572585+stacynoland@users.noreply.github.com
28
+ Requires-Python: >=3.12,<4.0
29
+ Classifier: Development Status :: 4 - Beta
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: Intended Audience :: Information Technology
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3 :: Only
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Classifier: Topic :: Software Development :: Libraries
40
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
41
+ Requires-Dist: pydantic (>=2.11.3,<3.0.0)
42
+ Project-URL: Homepage, https://github.com/stacynoland/python-taxes
43
+ Project-URL: Source, https://github.com/stacynoland/python-taxes
44
+ Description-Content-Type: text/markdown
45
+
46
+ ![Python Taxes Image](https://github.com/user-attachments/assets/6c62946b-e749-46bb-a84e-6321397f1753)
47
+ ![Python Versions](https://img.shields.io/badge/Python-3.12%20%7C%203.13-blue?logo=python&logoColor=yellow)
48
+ [![GitHub Release](https://img.shields.io/github/v/release/stacynoland/python-taxes?include_prereleases&label=Current%20Release)](https://github.com/stacynoland/python-taxes/releases)
49
+ [![Tests](https://github.com/stacynoland/python-taxes/actions/workflows/test.yml/badge.svg)](https://github.com/stacynoland/python-taxes/actions/workflows/test.yml)
50
+ ![Coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstacynoland%2Fpython-taxes%2Frefs%2Fheads%2Fmain%2Fcoverage.json&query=%24.totals.percent_covered_display&suffix=%25&label=Coverage&color=3fb831)
51
+ [![Poetry Package Manager](https://img.shields.io/endpoint?url=https%3A%2F%2Fpython-poetry.org%2Fbadge%2Fv0.json)](https://python-poetry.org/)
52
+ [![Black](https://img.shields.io/badge/Code%20Style-black-000000)](https://github.com/psf/black)
53
+
54
+ > Disclaimer: This library is not intended to be used for tax advice. Please consult a tax professional for any tax-related questions or concerns.
55
+
56
+ Python-Taxes is a library designed to make calculating US Federal taxes easy.
57
+
58
+ The library supports Social Security, Medicare, and Federal Income taxes for tax years 2023 to 2025. Please note, 2025 is only added for future tax season.
59
+
60
+ `CURRENT_TAX_YEAR` is set to 2024.
61
+
62
+ ## Installation
63
+
64
+ To install the library, you can use pip or another dependency manager like Poetry.
65
+
66
+ `pip install python-taxes`
67
+
68
+ or
69
+
70
+ `poetry add python-taxes`
71
+
72
+ ## Usage
73
+
74
+ ### Social Security Tax
75
+
76
+ To calculate Social Security tax, use the `social_security` module:
77
+
78
+ ```python
79
+ from python_taxes.federal import social_security
80
+
81
+ social_security.withholding(5000) # Returns the amount withheld for Social Security tax
82
+
83
+ social_security.withholding(
84
+ taxable_wages=3000,
85
+ taxable_wages_ytd=100000,
86
+ self_employed=False,
87
+ tax_year=2024,
88
+ rounded=True,
89
+ )
90
+ ```
91
+ ---
92
+ ### Medicare Tax
93
+
94
+ To calculate Medicare tax, use the `medicare` module. There are two functions available:
95
+
96
+ `medicare.required_withholding` - Returns the required amount to withhold for Medicare tax regardless of filing status.
97
+ `medicare.additional_withholding` - Returns the amount that should be withheld based on filing status, including Additional Medicare tax.
98
+
99
+ ```python
100
+ from python_taxes.federal import medicare
101
+
102
+ medicare.required_withholding(5000) # Returns the amount withheld for Medicare tax
103
+
104
+ medicare.required_withholding(
105
+ taxable_wages=5000,
106
+ taxable_wages_ytd=100000,
107
+ self_employed=True,
108
+ rounded=True,
109
+ )
110
+
111
+ medicare.additional_withholding(100000, "married") # Returns the amount withheld for Medicare Tax and Additional Medicare tax, if applicable, based on filing status.
112
+
113
+ medicare.additional_withholding(
114
+ taxable_wages_ytd=100000,
115
+ filing_status="married",
116
+ self_employed=False,
117
+ rounded=True,
118
+ )
119
+ ```
120
+ ---
121
+ ### Federal Income Tax
122
+
123
+ To calculate Federal Income tax, use the `income` package. Currently, the only payroll withholding supported is for automated systems. Specifically, the percentage tables in IRS Publication 15-T section 1 (Percentage Method Tables for Automated Payroll Systems).
124
+
125
+ ```python
126
+ from python_taxes.federal import income
127
+
128
+ income.employer_withholding(10000) # Returns the amount withheld for Federal Income tax
129
+
130
+ income.employer_withholding(
131
+ taxable_wages=10000,
132
+ pay_frequency="monthly",
133
+ filing_status="married",
134
+ multiple_jobs=False,
135
+ tax_credits=0,
136
+ other_income=0,
137
+ deductions=0,
138
+ extra_withholding=0,
139
+ tax_year=2024,
140
+ rounded=True,
141
+ )
142
+
143
+ income.employer_withholding_pre_2020(10000) # Returns the amount withheld for Federal Income tax - using this method is required if Form W-4 is from 2019 or earlier.
144
+
145
+ income.employer_withholding_pre_2020(
146
+ taxable_wages=10000,
147
+ pay_frequency="monthly",
148
+ marital_status="married",
149
+ allowances_claimed=0,
150
+ extra_withholding=0,
151
+ tax_year=2024,
152
+ rounded=False,
153
+ )
154
+ ```
155
+
@@ -0,0 +1,109 @@
1
+ ![Python Taxes Image](https://github.com/user-attachments/assets/6c62946b-e749-46bb-a84e-6321397f1753)
2
+ ![Python Versions](https://img.shields.io/badge/Python-3.12%20%7C%203.13-blue?logo=python&logoColor=yellow)
3
+ [![GitHub Release](https://img.shields.io/github/v/release/stacynoland/python-taxes?include_prereleases&label=Current%20Release)](https://github.com/stacynoland/python-taxes/releases)
4
+ [![Tests](https://github.com/stacynoland/python-taxes/actions/workflows/test.yml/badge.svg)](https://github.com/stacynoland/python-taxes/actions/workflows/test.yml)
5
+ ![Coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fstacynoland%2Fpython-taxes%2Frefs%2Fheads%2Fmain%2Fcoverage.json&query=%24.totals.percent_covered_display&suffix=%25&label=Coverage&color=3fb831)
6
+ [![Poetry Package Manager](https://img.shields.io/endpoint?url=https%3A%2F%2Fpython-poetry.org%2Fbadge%2Fv0.json)](https://python-poetry.org/)
7
+ [![Black](https://img.shields.io/badge/Code%20Style-black-000000)](https://github.com/psf/black)
8
+
9
+ > Disclaimer: This library is not intended to be used for tax advice. Please consult a tax professional for any tax-related questions or concerns.
10
+
11
+ Python-Taxes is a library designed to make calculating US Federal taxes easy.
12
+
13
+ The library supports Social Security, Medicare, and Federal Income taxes for tax years 2023 to 2025. Please note, 2025 is only added for future tax season.
14
+
15
+ `CURRENT_TAX_YEAR` is set to 2024.
16
+
17
+ ## Installation
18
+
19
+ To install the library, you can use pip or another dependency manager like Poetry.
20
+
21
+ `pip install python-taxes`
22
+
23
+ or
24
+
25
+ `poetry add python-taxes`
26
+
27
+ ## Usage
28
+
29
+ ### Social Security Tax
30
+
31
+ To calculate Social Security tax, use the `social_security` module:
32
+
33
+ ```python
34
+ from python_taxes.federal import social_security
35
+
36
+ social_security.withholding(5000) # Returns the amount withheld for Social Security tax
37
+
38
+ social_security.withholding(
39
+ taxable_wages=3000,
40
+ taxable_wages_ytd=100000,
41
+ self_employed=False,
42
+ tax_year=2024,
43
+ rounded=True,
44
+ )
45
+ ```
46
+ ---
47
+ ### Medicare Tax
48
+
49
+ To calculate Medicare tax, use the `medicare` module. There are two functions available:
50
+
51
+ `medicare.required_withholding` - Returns the required amount to withhold for Medicare tax regardless of filing status.
52
+ `medicare.additional_withholding` - Returns the amount that should be withheld based on filing status, including Additional Medicare tax.
53
+
54
+ ```python
55
+ from python_taxes.federal import medicare
56
+
57
+ medicare.required_withholding(5000) # Returns the amount withheld for Medicare tax
58
+
59
+ medicare.required_withholding(
60
+ taxable_wages=5000,
61
+ taxable_wages_ytd=100000,
62
+ self_employed=True,
63
+ rounded=True,
64
+ )
65
+
66
+ medicare.additional_withholding(100000, "married") # Returns the amount withheld for Medicare Tax and Additional Medicare tax, if applicable, based on filing status.
67
+
68
+ medicare.additional_withholding(
69
+ taxable_wages_ytd=100000,
70
+ filing_status="married",
71
+ self_employed=False,
72
+ rounded=True,
73
+ )
74
+ ```
75
+ ---
76
+ ### Federal Income Tax
77
+
78
+ To calculate Federal Income tax, use the `income` package. Currently, the only payroll withholding supported is for automated systems. Specifically, the percentage tables in IRS Publication 15-T section 1 (Percentage Method Tables for Automated Payroll Systems).
79
+
80
+ ```python
81
+ from python_taxes.federal import income
82
+
83
+ income.employer_withholding(10000) # Returns the amount withheld for Federal Income tax
84
+
85
+ income.employer_withholding(
86
+ taxable_wages=10000,
87
+ pay_frequency="monthly",
88
+ filing_status="married",
89
+ multiple_jobs=False,
90
+ tax_credits=0,
91
+ other_income=0,
92
+ deductions=0,
93
+ extra_withholding=0,
94
+ tax_year=2024,
95
+ rounded=True,
96
+ )
97
+
98
+ income.employer_withholding_pre_2020(10000) # Returns the amount withheld for Federal Income tax - using this method is required if Form W-4 is from 2019 or earlier.
99
+
100
+ income.employer_withholding_pre_2020(
101
+ taxable_wages=10000,
102
+ pay_frequency="monthly",
103
+ marital_status="married",
104
+ allowances_claimed=0,
105
+ extra_withholding=0,
106
+ tax_year=2024,
107
+ rounded=False,
108
+ )
109
+ ```
@@ -0,0 +1,99 @@
1
+ [project]
2
+ name = "python-taxes"
3
+ version = "0.2.0"
4
+ description = "A Python library for calculating US Social Security, Medicare, and Federal Income taxes."
5
+ authors = [
6
+ {name = "Stacy Noland", email = "46572585+stacynoland@users.noreply.github.com"}
7
+ ]
8
+ readme = "README.md"
9
+ license = { file = "LICENSE" }
10
+ requires-python = ">=3.12,<4.0"
11
+ dependencies = [
12
+ "pydantic (>=2.11.3,<3.0.0)"
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Intended Audience :: Information Technology",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Software Development :: Libraries",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/stacynoland/python-taxes"
31
+ Source = "https://github.com/stacynoland/python-taxes"
32
+
33
+ [tool.poetry]
34
+ packages = [{include = "python_taxes", from = "src"}]
35
+
36
+ [tool.poetry.group.dev.dependencies]
37
+ pytest = "^8.3.5"
38
+ pytest-cov = "^6.1.1"
39
+ flake8 = "^7.2.0"
40
+ mypy = "^1.15.0"
41
+ tox = "^4.25.0"
42
+ black = "^25.1.0"
43
+ isort = "^6.0.1"
44
+ pre-commit = "^4.2.0"
45
+
46
+ [tool.tox]
47
+ requires = ["tox>=4.25.0,<5.0.0"]
48
+ env_list = ["3.13", "3.12", "type", "lint", "format"]
49
+
50
+ [dependency-groups]
51
+ pytest = [
52
+ "pytest>=8.3.0,<9.0.0",
53
+ ]
54
+
55
+ [tool.tox.env_run_base]
56
+ description = "Run tests under {base_python}"
57
+ package = "wheel"
58
+ dependency_groups = ["pytest"]
59
+ deps = [
60
+ "pytest-cov>=6.1.0,<7.0.0",
61
+ ]
62
+ commands = [["pytest"]]
63
+
64
+ [tool.tox.env.type]
65
+ description = "Run type checking on code base"
66
+ package = "wheel"
67
+ dependency_groups = ["pytest"]
68
+ deps = [
69
+ "mypy>=1.15.0,<2.0.0",
70
+ ]
71
+ commands = [["mypy", "."]]
72
+
73
+ [tool.tox.env.lint]
74
+ description = "Run linters on code base"
75
+ package = "wheel"
76
+ deps = ["flake8>=7.2.0,<8.0.0"]
77
+ commands = [["flake8", "."]]
78
+
79
+ [tool.tox.env.format]
80
+ description = "Run formatters on code base"
81
+ package = "wheel"
82
+ deps = [
83
+ "black>=25.1.0,<26.0.0",
84
+ "isort>=6.0.0,<7.0.0",
85
+ ]
86
+ commands = [
87
+ ["black", "."],
88
+ ["isort", "."],
89
+ ]
90
+
91
+ [tool.isort]
92
+ profile = "black"
93
+ skip_gitignore = true
94
+ extend_skip = [".pytest_cache",]
95
+ skip_glob = ["*/__pycache__/*", "tests/__pycache__/*"]
96
+
97
+ [build-system]
98
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
99
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,7 @@
1
+ from decimal import Decimal
2
+
3
+ from pydantic import Field
4
+
5
+ CURRENT_TAX_YEAR = 2024
6
+
7
+ currency_field = Field(ge=Decimal("0.01"), decimal_places=2)
@@ -0,0 +1,19 @@
1
+ from decimal import ROUND_HALF_UP, Decimal, getcontext
2
+
3
+ getcontext().rounding = ROUND_HALF_UP
4
+
5
+ ROUNDED = Decimal("1.")
6
+
7
+ NOT_ROUNDED = Decimal("0.01")
8
+
9
+ rounding = {
10
+ True: ROUNDED,
11
+ False: NOT_ROUNDED,
12
+ }
13
+
14
+
15
+ # AfterValidator for tax_year
16
+ def is_valid_tax_year(value: int) -> int:
17
+ if value in [2023, 2024, 2025]:
18
+ return value
19
+ raise ValueError("Invalid tax year. Valid tax years are 2023, 2024, and 2025.")
@@ -0,0 +1,4 @@
1
+ from .payroll.automated import (
2
+ employer_withholding,
3
+ employer_withholding_pre_2020,
4
+ )
@@ -0,0 +1,174 @@
1
+ from decimal import Decimal
2
+ from typing import Annotated, Literal
3
+
4
+ from pydantic import StrictBool, validate_call
5
+
6
+ from python_taxes import CURRENT_TAX_YEAR, currency_field
7
+ from python_taxes.federal import rounding
8
+
9
+ from ..tables.percentage.automated import hoh, married, single
10
+
11
+ PAY_FREQUENCY = {
12
+ "semiannual": 2,
13
+ "quarterly": 4,
14
+ "monthly": 12,
15
+ "semimonthly": 24,
16
+ "biweekly": 26,
17
+ "weekly": 52,
18
+ "daily": 260,
19
+ }
20
+
21
+
22
+ @validate_call
23
+ def employer_withholding(
24
+ taxable_wages: Annotated[Decimal, currency_field],
25
+ pay_frequency: Literal[
26
+ "semiannual",
27
+ "quarterly",
28
+ "monthly",
29
+ "semimonthly",
30
+ "biweekly",
31
+ "weekly",
32
+ "daily",
33
+ ] = "biweekly",
34
+ filing_status: Literal["single", "married", "separate", "hoh"] = "single",
35
+ multiple_jobs: StrictBool = False,
36
+ tax_credits: Annotated[Decimal, currency_field] = Decimal("0.00"),
37
+ other_income: Annotated[Decimal, currency_field] = Decimal("0.00"),
38
+ deductions: Annotated[Decimal, currency_field] = Decimal("0.00"),
39
+ extra_withholding: Annotated[Decimal, currency_field] = Decimal("0.00"),
40
+ tax_year: int = CURRENT_TAX_YEAR,
41
+ rounded: StrictBool = False,
42
+ ) -> Decimal:
43
+ """Calculate income tax withholding.
44
+
45
+ Formula used if Form W-4 is 2020 or later.
46
+ If W-4 is 2019 or earlier, use employer_withholding_pre_2020 instead.
47
+
48
+ Parameters:
49
+ taxable_wages -- Wages earned this year
50
+ pay_frequency -- Number of pay periods per year (default 'biweekly')
51
+ filing_status -- Filing status (default 'single')
52
+ multiple_jobs -- Indicates if box in Step 2 on W-4 is checked (default False)
53
+ tax_credits -- Dependant claims and other credits from Step 3 (default 0)
54
+ other_income -- Income not from jobs - Step 4 (default 0)
55
+ deductions -- If claiming deductions other than standard - Step 4 (default 0)
56
+ extra_withholding -- Extra amount to withhold each pay period - Step 4 (default 0)
57
+ tax_year -- Year for which you are filing (default CURRENT_TAX_YEAR)
58
+ rounded -- Round to nearest whole dollar amount (default False)
59
+ """
60
+
61
+ # Steps 1a-1i
62
+ match filing_status:
63
+ case "single" | "separate" if multiple_jobs:
64
+ withholding_schedule = single.multiple_jobs
65
+ case "single" | "separate":
66
+ withholding_schedule = single.standard_schedule
67
+ deductions = deductions + Decimal("8600.00")
68
+ case "married" if multiple_jobs:
69
+ withholding_schedule = married.multiple_jobs
70
+ case "married":
71
+ withholding_schedule = married.standard_schedule
72
+ deductions = deductions + Decimal("12900.00")
73
+ case "hoh" if multiple_jobs:
74
+ withholding_schedule = hoh.multiple_jobs
75
+ case "hoh":
76
+ withholding_schedule = hoh.standard_schedule
77
+ deductions = deductions + Decimal("8600.00")
78
+
79
+ pay_freq = PAY_FREQUENCY[pay_frequency]
80
+
81
+ adjusted_wage = ((taxable_wages * pay_freq) + other_income) - deductions
82
+
83
+ # Step 2
84
+ for row in withholding_schedule[tax_year]:
85
+ if adjusted_wage >= row.min and adjusted_wage < row.max:
86
+ withholding_rate = row
87
+ break
88
+
89
+ tax_withholding = (adjusted_wage - withholding_rate.min) * Decimal(
90
+ withholding_rate.percent / 100
91
+ ) + withholding_rate.withhold_amount
92
+
93
+ withheld_this_period = tax_withholding / pay_freq
94
+
95
+ # Step 3
96
+ if tax_credits:
97
+ withheld_this_period = withheld_this_period - (tax_credits / pay_freq)
98
+
99
+ # Step 4
100
+ if extra_withholding:
101
+ withheld_this_period = withheld_this_period + extra_withholding
102
+
103
+ return (
104
+ Decimal(withheld_this_period).quantize(rounding[rounded])
105
+ if withheld_this_period > 0
106
+ else Decimal("0.00")
107
+ )
108
+
109
+
110
+ @validate_call
111
+ def employer_withholding_pre_2020(
112
+ taxable_wages: Annotated[Decimal, currency_field],
113
+ pay_frequency: Literal[
114
+ "semiannual",
115
+ "quarterly",
116
+ "monthly",
117
+ "semimonthly",
118
+ "biweekly",
119
+ "weekly",
120
+ "daily",
121
+ ] = "biweekly",
122
+ marital_status: Literal["single", "married", "separate"] = "single",
123
+ allowances_claimed: int = 0,
124
+ extra_withholding: Annotated[Decimal, currency_field] = Decimal("0.00"),
125
+ tax_year: int = CURRENT_TAX_YEAR,
126
+ rounded: StrictBool = False,
127
+ ) -> Decimal:
128
+ """Calculate income tax withholding - only if Form W-4 is 2019 or earlier.
129
+
130
+ Parameters:
131
+ taxable_wages -- Wages earned this year
132
+ pay_frequency -- Number of pay periods per year (default 'biweekly')
133
+ marital_status -- Marital status (default 'single')
134
+ allowances_claimed -- Number of allowances claimed - Step 5 (default 0)
135
+ extra_withholding -- Extra amount to withhold each pay period - Step 6 (default 0)
136
+ tax_year -- Year for which you are filing (default CURRENT_TAX_YEAR)
137
+ rounded -- Round to nearest whole dollar amount (default False)
138
+ """
139
+
140
+ # Steps 1a-1c and 1j-1l
141
+ match marital_status:
142
+ case "single" | "separate":
143
+ withholding_schedule = single.standard_schedule
144
+ case "married":
145
+ withholding_schedule = married.standard_schedule
146
+
147
+ pay_freq = PAY_FREQUENCY[pay_frequency]
148
+
149
+ allowances = allowances_claimed * Decimal("4300.00")
150
+
151
+ adjusted_wage = (taxable_wages * pay_freq) - allowances
152
+
153
+ # Step 2
154
+ for row in withholding_schedule[tax_year]:
155
+ if adjusted_wage >= row.min and adjusted_wage < row.max:
156
+ withholding_rate = row
157
+ break
158
+
159
+ tax_withholding = (adjusted_wage - withholding_rate.min) * Decimal(
160
+ withholding_rate.percent / 100
161
+ ) + withholding_rate.withhold_amount
162
+
163
+ withheld_this_period = tax_withholding / pay_freq
164
+
165
+ # Step 3 skipped if W4 is from 2019 or earlier
166
+ # Step 4
167
+ if extra_withholding:
168
+ withheld_this_period = withheld_this_period + extra_withholding
169
+
170
+ return (
171
+ Decimal(withheld_this_period).quantize(rounding[rounded])
172
+ if withheld_this_period > 0
173
+ else Decimal("0.00")
174
+ )
@@ -0,0 +1,15 @@
1
+ from decimal import Decimal
2
+ from typing import NamedTuple
3
+
4
+ from pydantic import Field, PositiveInt
5
+
6
+ MAX = Decimal("999999999999.99")
7
+
8
+
9
+ class RateRow(NamedTuple):
10
+ """Tax withholding rate schedule."""
11
+
12
+ min: Decimal = Field(ge=Decimal("0.00"), le=MAX, decimal_places=2)
13
+ max: Decimal = Field(ge=Decimal("0.00"), le=MAX, decimal_places=2)
14
+ withhold_amount: Decimal = Field(ge=Decimal("0.00"), le=MAX, decimal_places=2)
15
+ percent: PositiveInt = Field(le=100)