python-taxes 0.1.0__tar.gz → 0.4.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.
- python_taxes-0.4.0/LICENSE +21 -0
- python_taxes-0.4.0/PKG-INFO +159 -0
- python_taxes-0.4.0/README.md +110 -0
- python_taxes-0.4.0/pyproject.toml +102 -0
- python_taxes-0.4.0/src/python_taxes/__init__.py +7 -0
- python_taxes-0.4.0/src/python_taxes/federal/__init__.py +19 -0
- python_taxes-0.4.0/src/python_taxes/federal/income/__init__.py +4 -0
- python_taxes-0.4.0/src/python_taxes/federal/income/payroll/automated.py +174 -0
- python_taxes-0.4.0/src/python_taxes/federal/income/tables/percentage/__init__.py +15 -0
- python_taxes-0.4.0/src/python_taxes/federal/income/tables/percentage/automated/hoh.py +309 -0
- python_taxes-0.4.0/src/python_taxes/federal/income/tables/percentage/automated/married.py +309 -0
- python_taxes-0.4.0/src/python_taxes/federal/income/tables/percentage/automated/single.py +309 -0
- python_taxes-0.4.0/src/python_taxes/federal/medicare.py +89 -0
- python_taxes-0.4.0/src/python_taxes/federal/social_security.py +57 -0
- python_taxes-0.1.0/PKG-INFO +0 -13
- python_taxes-0.1.0/pyproject.toml +0 -23
- python_taxes-0.1.0/src/python_taxes/federal/calculators/__init__.py +0 -13
- python_taxes-0.1.0/src/python_taxes/federal/calculators/medicare.py +0 -88
- python_taxes-0.1.0/src/python_taxes/federal/calculators/social_security.py +0 -32
- {python_taxes-0.1.0/src/python_taxes → python_taxes-0.4.0/src/python_taxes/federal/income/payroll}/__init__.py +0 -0
- /python_taxes-0.1.0/README.md → /python_taxes-0.4.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,159 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: python-taxes
|
3
|
+
Version: 0.4.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.10,<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.10
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
41
|
+
Classifier: Typing :: Typed
|
42
|
+
Classifier: Topic :: Software Development :: Libraries
|
43
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
44
|
+
Requires-Dist: pydantic (>=2.11.3,<3.0.0)
|
45
|
+
Project-URL: Homepage, https://github.com/stacynoland/python-taxes
|
46
|
+
Project-URL: Source, https://github.com/stacynoland/python-taxes
|
47
|
+
Description-Content-Type: text/markdown
|
48
|
+
|
49
|
+

|
50
|
+

|
51
|
+
[](https://github.com/stacynoland/python-taxes/releases)
|
52
|
+

|
53
|
+
[](https://github.com/stacynoland/python-taxes/actions/workflows/test.yml)
|
54
|
+

|
55
|
+
[](https://python-poetry.org/)
|
56
|
+
[](https://github.com/psf/black)
|
57
|
+
|
58
|
+
> Disclaimer: This library is not intended to be used for tax advice. Please consult a tax professional for any tax-related questions or concerns.
|
59
|
+
|
60
|
+
Python-Taxes is a library designed to make calculating US Federal taxes easy.
|
61
|
+
|
62
|
+
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.
|
63
|
+
|
64
|
+
`CURRENT_TAX_YEAR` is set to 2024.
|
65
|
+
|
66
|
+
## Installation
|
67
|
+
|
68
|
+
To install the library, you can use pip or another dependency manager like Poetry.
|
69
|
+
|
70
|
+
`pip install python-taxes`
|
71
|
+
|
72
|
+
or
|
73
|
+
|
74
|
+
`poetry add python-taxes`
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
### Social Security Tax
|
79
|
+
|
80
|
+
To calculate Social Security tax, use the `social_security` module:
|
81
|
+
|
82
|
+
```python
|
83
|
+
from python_taxes.federal import social_security
|
84
|
+
|
85
|
+
social_security.withholding(5000) # Returns the amount withheld for Social Security tax
|
86
|
+
|
87
|
+
social_security.withholding(
|
88
|
+
taxable_wages=3000,
|
89
|
+
taxable_wages_ytd=100000,
|
90
|
+
self_employed=False,
|
91
|
+
tax_year=2024,
|
92
|
+
rounded=True,
|
93
|
+
)
|
94
|
+
```
|
95
|
+
---
|
96
|
+
### Medicare Tax
|
97
|
+
|
98
|
+
To calculate Medicare tax, use the `medicare` module. There are two functions available:
|
99
|
+
|
100
|
+
`medicare.required_withholding` - Returns the required amount to withhold for Medicare tax regardless of filing status.
|
101
|
+
`medicare.additional_withholding` - Returns the amount that should be withheld based on filing status, including Additional Medicare tax.
|
102
|
+
|
103
|
+
```python
|
104
|
+
from python_taxes.federal import medicare
|
105
|
+
|
106
|
+
medicare.required_withholding(5000) # Returns the amount withheld for Medicare tax
|
107
|
+
|
108
|
+
medicare.required_withholding(
|
109
|
+
taxable_wages=5000,
|
110
|
+
taxable_wages_ytd=100000,
|
111
|
+
self_employed=True,
|
112
|
+
rounded=True,
|
113
|
+
)
|
114
|
+
|
115
|
+
medicare.additional_withholding(100000, "married") # Returns the amount withheld for Medicare Tax and Additional Medicare tax, if applicable, based on filing status.
|
116
|
+
|
117
|
+
medicare.additional_withholding(
|
118
|
+
taxable_wages_ytd=100000,
|
119
|
+
filing_status="married",
|
120
|
+
self_employed=False,
|
121
|
+
rounded=True,
|
122
|
+
)
|
123
|
+
```
|
124
|
+
---
|
125
|
+
### Federal Income Tax
|
126
|
+
|
127
|
+
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).
|
128
|
+
|
129
|
+
```python
|
130
|
+
from python_taxes.federal import income
|
131
|
+
|
132
|
+
income.employer_withholding(10000) # Returns the amount withheld for Federal Income tax
|
133
|
+
|
134
|
+
income.employer_withholding(
|
135
|
+
taxable_wages=10000,
|
136
|
+
pay_frequency="monthly",
|
137
|
+
filing_status="married",
|
138
|
+
multiple_jobs=False,
|
139
|
+
tax_credits=0,
|
140
|
+
other_income=0,
|
141
|
+
deductions=0,
|
142
|
+
extra_withholding=0,
|
143
|
+
tax_year=2024,
|
144
|
+
rounded=True,
|
145
|
+
)
|
146
|
+
|
147
|
+
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.
|
148
|
+
|
149
|
+
income.employer_withholding_pre_2020(
|
150
|
+
taxable_wages=10000,
|
151
|
+
pay_frequency="monthly",
|
152
|
+
marital_status="married",
|
153
|
+
allowances_claimed=0,
|
154
|
+
extra_withholding=0,
|
155
|
+
tax_year=2024,
|
156
|
+
rounded=False,
|
157
|
+
)
|
158
|
+
```
|
159
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+

|
2
|
+

|
3
|
+
[](https://github.com/stacynoland/python-taxes/releases)
|
4
|
+

|
5
|
+
[](https://github.com/stacynoland/python-taxes/actions/workflows/test.yml)
|
6
|
+

|
7
|
+
[](https://python-poetry.org/)
|
8
|
+
[](https://github.com/psf/black)
|
9
|
+
|
10
|
+
> Disclaimer: This library is not intended to be used for tax advice. Please consult a tax professional for any tax-related questions or concerns.
|
11
|
+
|
12
|
+
Python-Taxes is a library designed to make calculating US Federal taxes easy.
|
13
|
+
|
14
|
+
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.
|
15
|
+
|
16
|
+
`CURRENT_TAX_YEAR` is set to 2024.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
To install the library, you can use pip or another dependency manager like Poetry.
|
21
|
+
|
22
|
+
`pip install python-taxes`
|
23
|
+
|
24
|
+
or
|
25
|
+
|
26
|
+
`poetry add python-taxes`
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Social Security Tax
|
31
|
+
|
32
|
+
To calculate Social Security tax, use the `social_security` module:
|
33
|
+
|
34
|
+
```python
|
35
|
+
from python_taxes.federal import social_security
|
36
|
+
|
37
|
+
social_security.withholding(5000) # Returns the amount withheld for Social Security tax
|
38
|
+
|
39
|
+
social_security.withholding(
|
40
|
+
taxable_wages=3000,
|
41
|
+
taxable_wages_ytd=100000,
|
42
|
+
self_employed=False,
|
43
|
+
tax_year=2024,
|
44
|
+
rounded=True,
|
45
|
+
)
|
46
|
+
```
|
47
|
+
---
|
48
|
+
### Medicare Tax
|
49
|
+
|
50
|
+
To calculate Medicare tax, use the `medicare` module. There are two functions available:
|
51
|
+
|
52
|
+
`medicare.required_withholding` - Returns the required amount to withhold for Medicare tax regardless of filing status.
|
53
|
+
`medicare.additional_withholding` - Returns the amount that should be withheld based on filing status, including Additional Medicare tax.
|
54
|
+
|
55
|
+
```python
|
56
|
+
from python_taxes.federal import medicare
|
57
|
+
|
58
|
+
medicare.required_withholding(5000) # Returns the amount withheld for Medicare tax
|
59
|
+
|
60
|
+
medicare.required_withholding(
|
61
|
+
taxable_wages=5000,
|
62
|
+
taxable_wages_ytd=100000,
|
63
|
+
self_employed=True,
|
64
|
+
rounded=True,
|
65
|
+
)
|
66
|
+
|
67
|
+
medicare.additional_withholding(100000, "married") # Returns the amount withheld for Medicare Tax and Additional Medicare tax, if applicable, based on filing status.
|
68
|
+
|
69
|
+
medicare.additional_withholding(
|
70
|
+
taxable_wages_ytd=100000,
|
71
|
+
filing_status="married",
|
72
|
+
self_employed=False,
|
73
|
+
rounded=True,
|
74
|
+
)
|
75
|
+
```
|
76
|
+
---
|
77
|
+
### Federal Income Tax
|
78
|
+
|
79
|
+
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).
|
80
|
+
|
81
|
+
```python
|
82
|
+
from python_taxes.federal import income
|
83
|
+
|
84
|
+
income.employer_withholding(10000) # Returns the amount withheld for Federal Income tax
|
85
|
+
|
86
|
+
income.employer_withholding(
|
87
|
+
taxable_wages=10000,
|
88
|
+
pay_frequency="monthly",
|
89
|
+
filing_status="married",
|
90
|
+
multiple_jobs=False,
|
91
|
+
tax_credits=0,
|
92
|
+
other_income=0,
|
93
|
+
deductions=0,
|
94
|
+
extra_withholding=0,
|
95
|
+
tax_year=2024,
|
96
|
+
rounded=True,
|
97
|
+
)
|
98
|
+
|
99
|
+
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.
|
100
|
+
|
101
|
+
income.employer_withholding_pre_2020(
|
102
|
+
taxable_wages=10000,
|
103
|
+
pay_frequency="monthly",
|
104
|
+
marital_status="married",
|
105
|
+
allowances_claimed=0,
|
106
|
+
extra_withholding=0,
|
107
|
+
tax_year=2024,
|
108
|
+
rounded=False,
|
109
|
+
)
|
110
|
+
```
|
@@ -0,0 +1,102 @@
|
|
1
|
+
[project]
|
2
|
+
name = "python-taxes"
|
3
|
+
version = "0.4.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.10,<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.10",
|
24
|
+
"Programming Language :: Python :: 3.11",
|
25
|
+
"Programming Language :: Python :: 3.12",
|
26
|
+
"Programming Language :: Python :: 3.13",
|
27
|
+
"Typing :: Typed",
|
28
|
+
"Topic :: Software Development :: Libraries",
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
30
|
+
]
|
31
|
+
|
32
|
+
[project.urls]
|
33
|
+
Homepage = "https://github.com/stacynoland/python-taxes"
|
34
|
+
Source = "https://github.com/stacynoland/python-taxes"
|
35
|
+
|
36
|
+
[tool.poetry]
|
37
|
+
packages = [{include = "python_taxes", from = "src"}]
|
38
|
+
|
39
|
+
[tool.poetry.group.dev.dependencies]
|
40
|
+
pytest = "^8.3.5"
|
41
|
+
pytest-cov = "^6.1.1"
|
42
|
+
flake8 = "^7.2.0"
|
43
|
+
mypy = "^1.15.0"
|
44
|
+
tox = "^4.25.0"
|
45
|
+
black = "^25.1.0"
|
46
|
+
isort = "^6.0.1"
|
47
|
+
pre-commit = "^4.2.0"
|
48
|
+
|
49
|
+
[tool.tox]
|
50
|
+
requires = ["tox>=4.25.0,<5.0.0"]
|
51
|
+
env_list = ["py3", "type", "lint", "format"]
|
52
|
+
|
53
|
+
[dependency-groups]
|
54
|
+
pytest = [
|
55
|
+
"pytest>=8.3.0,<9.0.0",
|
56
|
+
]
|
57
|
+
|
58
|
+
[tool.tox.env_run_base]
|
59
|
+
description = "Run tests under {base_python}"
|
60
|
+
package = "wheel"
|
61
|
+
dependency_groups = ["pytest"]
|
62
|
+
deps = [
|
63
|
+
"pytest-cov>=6.1.0,<7.0.0",
|
64
|
+
]
|
65
|
+
commands = [["pytest"]]
|
66
|
+
|
67
|
+
[tool.tox.env.type]
|
68
|
+
description = "Run type checking on code base"
|
69
|
+
package = "wheel"
|
70
|
+
dependency_groups = ["pytest"]
|
71
|
+
deps = [
|
72
|
+
"mypy>=1.15.0,<2.0.0",
|
73
|
+
]
|
74
|
+
commands = [["mypy", "."]]
|
75
|
+
|
76
|
+
[tool.tox.env.lint]
|
77
|
+
description = "Run linters on code base"
|
78
|
+
package = "wheel"
|
79
|
+
deps = ["flake8>=7.2.0,<8.0.0"]
|
80
|
+
commands = [["flake8", "."]]
|
81
|
+
|
82
|
+
[tool.tox.env.format]
|
83
|
+
description = "Run formatters on code base"
|
84
|
+
package = "wheel"
|
85
|
+
deps = [
|
86
|
+
"black>=25.1.0,<26.0.0",
|
87
|
+
"isort>=6.0.0,<7.0.0",
|
88
|
+
]
|
89
|
+
commands = [
|
90
|
+
["black", "."],
|
91
|
+
["isort", "."],
|
92
|
+
]
|
93
|
+
|
94
|
+
[tool.isort]
|
95
|
+
profile = "black"
|
96
|
+
skip_gitignore = true
|
97
|
+
extend_skip = [".pytest_cache",]
|
98
|
+
skip_glob = ["*/__pycache__/*", "tests/__pycache__/*"]
|
99
|
+
|
100
|
+
[build-system]
|
101
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
102
|
+
build-backend = "poetry.core.masonry.api"
|
@@ -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,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)
|