python-taxes 0.4.0__py3-none-any.whl → 0.6.0a3__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
@@ -1,7 +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)
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.00"), decimal_places=2)
@@ -0,0 +1,4 @@
1
+ if __name__ == "__main__":
2
+ from python_taxes.cli import app
3
+
4
+ app()
python_taxes/cli.py ADDED
@@ -0,0 +1,147 @@
1
+ import sys
2
+ from decimal import Decimal
3
+ from enum import Enum
4
+ from typing import Annotated
5
+
6
+ from pydantic import StrictBool, validate_call
7
+
8
+ from python_taxes import CURRENT_TAX_YEAR, currency_field
9
+ from python_taxes.federal.income import employer_withholding as income_withholding
10
+ from python_taxes.federal.medicare import required_withholding as med_withholding
11
+ from python_taxes.federal.social_security import withholding as ss_withholding
12
+
13
+ try:
14
+ import typer
15
+ except ImportError: # pragma: no cover
16
+ print("Error: typer not found. Command-line (cli) not available.")
17
+ sys.exit(1)
18
+
19
+ app = typer.Typer()
20
+
21
+
22
+ class PayFrequency(str, Enum):
23
+ semiannual = "semiannual"
24
+ quarterly = "quarterly"
25
+ monthly = "monthly"
26
+ semimonthly = "semimonthly"
27
+ biweekly = "biweekly"
28
+ weekly = "weekly"
29
+ daily = "daily"
30
+
31
+
32
+ class FilingStatus(str, Enum):
33
+ single = "single"
34
+ married = "married"
35
+ separate = "separate"
36
+ hoh = "hoh"
37
+
38
+
39
+ @validate_call
40
+ def currency(value: Annotated[Decimal, currency_field]) -> Decimal:
41
+ return value
42
+
43
+
44
+ @app.callback()
45
+ def callback():
46
+ """
47
+ Calculate federal income related taxes with python-taxes CLI app: pytax
48
+ """
49
+
50
+
51
+ @app.command()
52
+ def med(
53
+ wages: Annotated[
54
+ Decimal, typer.Argument(parser=currency, help="Taxable wages this period")
55
+ ],
56
+ ytd: Annotated[
57
+ Decimal,
58
+ typer.Option(
59
+ parser=currency,
60
+ help="Total taxable wages paid year-to-date",
61
+ ),
62
+ ] = Decimal("0.00"),
63
+ selfemp: Annotated[
64
+ StrictBool,
65
+ typer.Option(help="Whether to calculate as self-employed"),
66
+ ] = False,
67
+ round: Annotated[
68
+ StrictBool,
69
+ typer.Option(help="Whether to round the final value"),
70
+ ] = False,
71
+ ):
72
+ value = med_withholding(wages, ytd, selfemp, round)
73
+ print(value)
74
+
75
+
76
+ @app.command()
77
+ def ss(
78
+ wages: Annotated[
79
+ Decimal,
80
+ typer.Argument(parser=currency, help="Taxable wages this period"),
81
+ ],
82
+ ytd: Annotated[
83
+ Decimal,
84
+ typer.Option(parser=currency, help="Total taxable wages paid year-to-date"),
85
+ ] = Decimal("0.00"),
86
+ selfemp: Annotated[
87
+ StrictBool,
88
+ typer.Option(help="Whether to calculate as self-employed"),
89
+ ] = False,
90
+ year: Annotated[int, typer.Option(help="Enter the tax year")] = CURRENT_TAX_YEAR,
91
+ round: Annotated[
92
+ StrictBool,
93
+ typer.Option(help="Whether to round the final value"),
94
+ ] = False,
95
+ ):
96
+ value = ss_withholding(wages, ytd, selfemp, year, round)
97
+ print(value)
98
+
99
+
100
+ @app.command()
101
+ def income(
102
+ wages: Annotated[
103
+ Decimal,
104
+ typer.Argument(parser=currency, help="Taxable wages this period"),
105
+ ],
106
+ freq: Annotated[
107
+ PayFrequency, typer.Option(help="Pay frequency", case_sensitive=False)
108
+ ] = PayFrequency.biweekly,
109
+ status: Annotated[
110
+ FilingStatus, typer.Option(help="Filing status", case_sensitive=False)
111
+ ] = FilingStatus.single,
112
+ mjobs: Annotated[
113
+ StrictBool,
114
+ typer.Option(help="Multiple jobs: Select True if box in Step 2 on W-4 checked"),
115
+ ] = False,
116
+ credits: Annotated[
117
+ Decimal,
118
+ typer.Option(
119
+ parser=currency, help="Amount to claim for dependents and credits"
120
+ ),
121
+ ] = Decimal("0.00"),
122
+ other: Annotated[
123
+ Decimal,
124
+ typer.Option(parser=currency, help="Income not from jobs"),
125
+ ] = Decimal("0.00"),
126
+ deduct: Annotated[
127
+ Decimal,
128
+ typer.Option(parser=currency, help="Deductions other than standard"),
129
+ ] = Decimal("0.00"),
130
+ extra: Annotated[
131
+ Decimal,
132
+ typer.Option(parser=currency, help="Extra to withhold each period"),
133
+ ] = Decimal("0.00"),
134
+ year: Annotated[int, typer.Option(help="Enter the tax year")] = CURRENT_TAX_YEAR,
135
+ round: Annotated[
136
+ StrictBool,
137
+ typer.Option(help="Whether to round the final value"),
138
+ ] = False,
139
+ ):
140
+ value = income_withholding(
141
+ wages, freq, status, mjobs, credits, other, deduct, extra, year, round
142
+ )
143
+ print(value)
144
+
145
+
146
+ if __name__ == "__main__":
147
+ app() # pragma: no cover
@@ -1,19 +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.")
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.")
@@ -1,4 +1,4 @@
1
- from .payroll.automated import (
2
- employer_withholding,
3
- employer_withholding_pre_2020,
4
- )
1
+ from .payroll.automated import (
2
+ employer_withholding,
3
+ employer_withholding_pre_2020,
4
+ )
@@ -1,174 +1,184 @@
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
- )
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: Annotated[
26
+ str,
27
+ Literal[
28
+ "semiannual",
29
+ "quarterly",
30
+ "monthly",
31
+ "semimonthly",
32
+ "biweekly",
33
+ "weekly",
34
+ "daily",
35
+ ],
36
+ ] = "biweekly",
37
+ filing_status: Annotated[
38
+ str, Literal["single", "married", "separate", "hoh"]
39
+ ] = "single",
40
+ multiple_jobs: StrictBool = False,
41
+ tax_credits: Annotated[Decimal, currency_field] = Decimal("0.00"),
42
+ other_income: Annotated[Decimal, currency_field] = Decimal("0.00"),
43
+ deductions: Annotated[Decimal, currency_field] = Decimal("0.00"),
44
+ extra_withholding: Annotated[Decimal, currency_field] = Decimal("0.00"),
45
+ tax_year: int = CURRENT_TAX_YEAR,
46
+ rounded: StrictBool = False,
47
+ ) -> Decimal:
48
+ """Calculate income tax withholding.
49
+
50
+ Formula used if Form W-4 is 2020 or later.
51
+ If W-4 is 2019 or earlier, use employer_withholding_pre_2020 instead.
52
+
53
+ Parameters:
54
+ taxable_wages -- Wages earned this year
55
+ pay_frequency -- Number of pay periods per year (default 'biweekly')
56
+ filing_status -- Filing status (default 'single')
57
+ multiple_jobs -- Indicates if box in Step 2 on W-4 is checked (default False)
58
+ tax_credits -- Dependant claims and other credits from Step 3 (default 0)
59
+ other_income -- Income not from jobs - Step 4 (default 0)
60
+ deductions -- If claiming deductions other than standard - Step 4 (default 0)
61
+ extra_withholding -- Extra amount to withhold each pay period - Step 4 (default 0)
62
+ tax_year -- Year for which you are filing (default CURRENT_TAX_YEAR)
63
+ rounded -- Round to nearest whole dollar amount (default False)
64
+ """
65
+
66
+ # Steps 1a-1i
67
+ match filing_status:
68
+ case "single" | "separate" if multiple_jobs:
69
+ withholding_schedule = single.multiple_jobs
70
+ case "single" | "separate":
71
+ withholding_schedule = single.standard_schedule
72
+ deductions = deductions + Decimal("8600.00")
73
+ case "married" if multiple_jobs:
74
+ withholding_schedule = married.multiple_jobs
75
+ case "married":
76
+ withholding_schedule = married.standard_schedule
77
+ deductions = deductions + Decimal("12900.00")
78
+ case "hoh" if multiple_jobs:
79
+ withholding_schedule = hoh.multiple_jobs
80
+ case "hoh":
81
+ withholding_schedule = hoh.standard_schedule
82
+ deductions = deductions + Decimal("8600.00")
83
+
84
+ pay_freq = PAY_FREQUENCY[pay_frequency]
85
+
86
+ adjusted_wage = ((taxable_wages * pay_freq) + other_income) - deductions
87
+
88
+ # Step 2
89
+ if adjusted_wage < 0:
90
+ withholding_rate = withholding_schedule[tax_year][0]
91
+ for row in withholding_schedule[tax_year]:
92
+ if adjusted_wage >= row.min and adjusted_wage < row.max:
93
+ withholding_rate = row
94
+ break
95
+
96
+ tax_withholding = (adjusted_wage - withholding_rate.min) * Decimal(
97
+ withholding_rate.percent / 100
98
+ ) + withholding_rate.withhold_amount
99
+
100
+ withheld_this_period = tax_withholding / pay_freq
101
+
102
+ # Step 3
103
+ if tax_credits:
104
+ withheld_this_period = withheld_this_period - (tax_credits / pay_freq)
105
+
106
+ # Step 4
107
+ if extra_withholding:
108
+ withheld_this_period = withheld_this_period + extra_withholding
109
+
110
+ return (
111
+ Decimal(withheld_this_period).quantize(rounding[rounded])
112
+ if withheld_this_period > 0
113
+ else Decimal("0.00")
114
+ )
115
+
116
+
117
+ @validate_call
118
+ def employer_withholding_pre_2020(
119
+ taxable_wages: Annotated[Decimal, currency_field],
120
+ pay_frequency: Annotated[
121
+ str,
122
+ Literal[
123
+ "semiannual",
124
+ "quarterly",
125
+ "monthly",
126
+ "semimonthly",
127
+ "biweekly",
128
+ "weekly",
129
+ "daily",
130
+ ],
131
+ ] = "biweekly",
132
+ marital_status: Annotated[str, Literal["single", "married", "separate"]] = "single",
133
+ allowances_claimed: int = 0,
134
+ extra_withholding: Annotated[Decimal, currency_field] = Decimal("0.00"),
135
+ tax_year: int = CURRENT_TAX_YEAR,
136
+ rounded: StrictBool = False,
137
+ ) -> Decimal:
138
+ """Calculate income tax withholding - only if Form W-4 is 2019 or earlier.
139
+
140
+ Parameters:
141
+ taxable_wages -- Wages earned this year
142
+ pay_frequency -- Number of pay periods per year (default 'biweekly')
143
+ marital_status -- Marital status (default 'single')
144
+ allowances_claimed -- Number of allowances claimed - Step 5 (default 0)
145
+ extra_withholding -- Extra amount to withhold each pay period - Step 6 (default 0)
146
+ tax_year -- Year for which you are filing (default CURRENT_TAX_YEAR)
147
+ rounded -- Round to nearest whole dollar amount (default False)
148
+ """
149
+
150
+ # Steps 1a-1c and 1j-1l
151
+ match marital_status:
152
+ case "single" | "separate":
153
+ withholding_schedule = single.standard_schedule
154
+ case "married":
155
+ withholding_schedule = married.standard_schedule
156
+
157
+ pay_freq = PAY_FREQUENCY[pay_frequency]
158
+
159
+ allowances = allowances_claimed * Decimal("4300.00")
160
+
161
+ adjusted_wage = (taxable_wages * pay_freq) - allowances
162
+
163
+ # Step 2
164
+ for row in withholding_schedule[tax_year]:
165
+ if adjusted_wage >= row.min and adjusted_wage < row.max:
166
+ withholding_rate = row
167
+ break
168
+
169
+ tax_withholding = (adjusted_wage - withholding_rate.min) * Decimal(
170
+ withholding_rate.percent / 100
171
+ ) + withholding_rate.withhold_amount
172
+
173
+ withheld_this_period = tax_withholding / pay_freq
174
+
175
+ # Step 3 skipped if W4 is from 2019 or earlier
176
+ # Step 4
177
+ if extra_withholding:
178
+ withheld_this_period = withheld_this_period + extra_withholding
179
+
180
+ return (
181
+ Decimal(withheld_this_period).quantize(rounding[rounded])
182
+ if withheld_this_period > 0
183
+ else Decimal("0.00")
184
+ )
@@ -1,15 +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)
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)