python-taxes 0.1.0__py3-none-any.whl → 0.4.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.
python_taxes/__init__.py CHANGED
@@ -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
+ )
File without changes
@@ -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)
@@ -0,0 +1,309 @@
1
+ from decimal import Decimal
2
+
3
+ from .. import MAX, RateRow
4
+
5
+ standard_schedule = {
6
+ 2023: [
7
+ RateRow(
8
+ min=Decimal("0.00"),
9
+ max=Decimal("12199.99"),
10
+ withhold_amount=Decimal("0.00"),
11
+ percent=0,
12
+ ),
13
+ RateRow(
14
+ min=Decimal("12200.00"),
15
+ max=Decimal("27899.99"),
16
+ withhold_amount=Decimal("0.00"),
17
+ percent=10,
18
+ ),
19
+ RateRow(
20
+ min=Decimal("27900.00"),
21
+ max=Decimal("72049.99"),
22
+ withhold_amount=Decimal("1570.00"),
23
+ percent=12,
24
+ ),
25
+ RateRow(
26
+ min=Decimal("72050.00"),
27
+ max=Decimal("107549.99"),
28
+ withhold_amount=Decimal("6868.00"),
29
+ percent=22,
30
+ ),
31
+ RateRow(
32
+ min=Decimal("107550.00"),
33
+ max=Decimal("194299.99"),
34
+ withhold_amount=Decimal("14678.00"),
35
+ percent=24,
36
+ ),
37
+ RateRow(
38
+ min=Decimal("194300.00"),
39
+ max=Decimal("243449.99"),
40
+ withhold_amount=Decimal("35498.00"),
41
+ percent=32,
42
+ ),
43
+ RateRow(
44
+ min=Decimal("243450.00"),
45
+ max=Decimal("590299.99"),
46
+ withhold_amount=Decimal("51226.00"),
47
+ percent=35,
48
+ ),
49
+ RateRow(
50
+ min=Decimal("590300.00"),
51
+ max=MAX,
52
+ withhold_amount=Decimal("172623.50"),
53
+ percent=37,
54
+ ),
55
+ ],
56
+ 2024: [
57
+ RateRow(
58
+ min=Decimal("0.00"),
59
+ max=Decimal("13299.99"),
60
+ withhold_amount=Decimal("0.00"),
61
+ percent=0,
62
+ ),
63
+ RateRow(
64
+ min=Decimal("13300.00"),
65
+ max=Decimal("29849.99"),
66
+ withhold_amount=Decimal("0.00"),
67
+ percent=10,
68
+ ),
69
+ RateRow(
70
+ min=Decimal("29850.00"),
71
+ max=Decimal("76399.99"),
72
+ withhold_amount=Decimal("1655.00"),
73
+ percent=12,
74
+ ),
75
+ RateRow(
76
+ min=Decimal("76400.00"),
77
+ max=Decimal("113799.99"),
78
+ withhold_amount=Decimal("7241.00"),
79
+ percent=22,
80
+ ),
81
+ RateRow(
82
+ min=Decimal("113800.00"),
83
+ max=Decimal("205249.99"),
84
+ withhold_amount=Decimal("15469.00"),
85
+ percent=24,
86
+ ),
87
+ RateRow(
88
+ min=Decimal("205250.00"),
89
+ max=Decimal("256999.99"),
90
+ withhold_amount=Decimal("37417.00"),
91
+ percent=32,
92
+ ),
93
+ RateRow(
94
+ min=Decimal("257000.00"),
95
+ max=Decimal("622649.99"),
96
+ withhold_amount=Decimal("53977.00"),
97
+ percent=35,
98
+ ),
99
+ RateRow(
100
+ min=Decimal("622650.00"),
101
+ max=MAX,
102
+ withhold_amount=Decimal("181954.50"),
103
+ percent=37,
104
+ ),
105
+ ],
106
+ 2025: [
107
+ RateRow(
108
+ min=Decimal("0.00"),
109
+ max=Decimal("13899.99"),
110
+ withhold_amount=Decimal("0.00"),
111
+ percent=0,
112
+ ),
113
+ RateRow(
114
+ min=Decimal("13900.00"),
115
+ max=Decimal("30899.99"),
116
+ withhold_amount=Decimal("0.00"),
117
+ percent=10,
118
+ ),
119
+ RateRow(
120
+ min=Decimal("30900.00"),
121
+ max=Decimal("78749.99"),
122
+ withhold_amount=Decimal("1700.00"),
123
+ percent=12,
124
+ ),
125
+ RateRow(
126
+ min=Decimal("78750.00"),
127
+ max=Decimal("117249.99"),
128
+ withhold_amount=Decimal("7442.00"),
129
+ percent=22,
130
+ ),
131
+ RateRow(
132
+ min=Decimal("117250.00"),
133
+ max=Decimal("211199.99"),
134
+ withhold_amount=Decimal("15912.00"),
135
+ percent=24,
136
+ ),
137
+ RateRow(
138
+ min=Decimal("211200.00"),
139
+ max=Decimal("264399.99"),
140
+ withhold_amount=Decimal("38460.00"),
141
+ percent=32,
142
+ ),
143
+ RateRow(
144
+ min=Decimal("264400.00"),
145
+ max=Decimal("640249.99"),
146
+ withhold_amount=Decimal("55484.00"),
147
+ percent=35,
148
+ ),
149
+ RateRow(
150
+ min=Decimal("640250.00"),
151
+ max=MAX,
152
+ withhold_amount=Decimal("187031.50"),
153
+ percent=37,
154
+ ),
155
+ ],
156
+ }
157
+
158
+ multiple_jobs = {
159
+ 2023: [
160
+ RateRow(
161
+ min=Decimal("0.00"),
162
+ max=Decimal("10399.99"),
163
+ withhold_amount=Decimal("0.00"),
164
+ percent=0,
165
+ ),
166
+ RateRow(
167
+ min=Decimal("10400.00"),
168
+ max=Decimal("18249.99"),
169
+ withhold_amount=Decimal("0.00"),
170
+ percent=10,
171
+ ),
172
+ RateRow(
173
+ min=Decimal("18250.00"),
174
+ max=Decimal("40324.99"),
175
+ withhold_amount=Decimal("785.00"),
176
+ percent=12,
177
+ ),
178
+ RateRow(
179
+ min=Decimal("40325.00"),
180
+ max=Decimal("58074.99"),
181
+ withhold_amount=Decimal("3434.00"),
182
+ percent=22,
183
+ ),
184
+ RateRow(
185
+ min=Decimal("58075.00"),
186
+ max=Decimal("101449.99"),
187
+ withhold_amount=Decimal("7339.00"),
188
+ percent=24,
189
+ ),
190
+ RateRow(
191
+ min=Decimal("101450.00"),
192
+ max=Decimal("126024.99"),
193
+ withhold_amount=Decimal("17749.00"),
194
+ percent=32,
195
+ ),
196
+ RateRow(
197
+ min=Decimal("126025.00"),
198
+ max=Decimal("299449.99"),
199
+ withhold_amount=Decimal("25613.00"),
200
+ percent=35,
201
+ ),
202
+ RateRow(
203
+ min=Decimal("299450.00"),
204
+ max=MAX,
205
+ withhold_amount=Decimal("86311.75"),
206
+ percent=37,
207
+ ),
208
+ ],
209
+ 2024: [
210
+ RateRow(
211
+ min=Decimal("0.00"),
212
+ max=Decimal("10949.99"),
213
+ withhold_amount=Decimal("0.00"),
214
+ percent=0,
215
+ ),
216
+ RateRow(
217
+ min=Decimal("10950.00"),
218
+ max=Decimal("19224.99"),
219
+ withhold_amount=Decimal("0.00"),
220
+ percent=10,
221
+ ),
222
+ RateRow(
223
+ min=Decimal("19225.00"),
224
+ max=Decimal("42499.99"),
225
+ withhold_amount=Decimal("827.50"),
226
+ percent=12,
227
+ ),
228
+ RateRow(
229
+ min=Decimal("42500.00"),
230
+ max=Decimal("61199.99"),
231
+ withhold_amount=Decimal("3620.50"),
232
+ percent=22,
233
+ ),
234
+ RateRow(
235
+ min=Decimal("61200.00"),
236
+ max=Decimal("106924.99"),
237
+ withhold_amount=Decimal("7734.50"),
238
+ percent=24,
239
+ ),
240
+ RateRow(
241
+ min=Decimal("106925.00"),
242
+ max=Decimal("132799.99"),
243
+ withhold_amount=Decimal("18708.50"),
244
+ percent=32,
245
+ ),
246
+ RateRow(
247
+ min=Decimal("132800.00"),
248
+ max=Decimal("315624.99"),
249
+ withhold_amount=Decimal("26988.50"),
250
+ percent=35,
251
+ ),
252
+ RateRow(
253
+ min=Decimal("315625.00"),
254
+ max=MAX,
255
+ withhold_amount=Decimal("90977.25"),
256
+ percent=37,
257
+ ),
258
+ ],
259
+ 2025: [
260
+ RateRow(
261
+ min=Decimal("0.00"),
262
+ max=Decimal("11249.99"),
263
+ withhold_amount=Decimal("0.00"),
264
+ percent=0,
265
+ ),
266
+ RateRow(
267
+ min=Decimal("11250.00"),
268
+ max=Decimal("19749.99"),
269
+ withhold_amount=Decimal("0.00"),
270
+ percent=10,
271
+ ),
272
+ RateRow(
273
+ min=Decimal("19750.00"),
274
+ max=Decimal("43674.99"),
275
+ withhold_amount=Decimal("850.00"),
276
+ percent=12,
277
+ ),
278
+ RateRow(
279
+ min=Decimal("43675.00"),
280
+ max=Decimal("62924.99"),
281
+ withhold_amount=Decimal("3721.00"),
282
+ percent=22,
283
+ ),
284
+ RateRow(
285
+ min=Decimal("62925.00"),
286
+ max=Decimal("109899.99"),
287
+ withhold_amount=Decimal("7956.00"),
288
+ percent=24,
289
+ ),
290
+ RateRow(
291
+ min=Decimal("109900.00"),
292
+ max=Decimal("136499.99"),
293
+ withhold_amount=Decimal("19230.00"),
294
+ percent=32,
295
+ ),
296
+ RateRow(
297
+ min=Decimal("136500.00"),
298
+ max=Decimal("324424.99"),
299
+ withhold_amount=Decimal("27742.00"),
300
+ percent=35,
301
+ ),
302
+ RateRow(
303
+ min=Decimal("324425.00"),
304
+ max=MAX,
305
+ withhold_amount=Decimal("93515.75"),
306
+ percent=37,
307
+ ),
308
+ ],
309
+ }