Salary Deduction Calculator in Python
Calculate net salary, income tax, and provident fund deductions from gross salary using Python.
Published:
Tags: salary calculator Python, Python payroll calculator, Python income tax calculation
Salary Deduction Calculator in Python Building a salary calculator in Python teaches you both Python programming fundamentals and India's payroll structure. This guide implements a complete take-home calculator covering income tax (old and new regime), PF, and professional tax — with working code you can run immediately. Official tax rates are published by the Income Tax Department of India and the CBDT (Central Board of Direct Taxes). --- What is the salary structure overview? Before writing code, understand the components: | Component | Typical Split | |---|---| | Basic Salary | 40–50% of CTC | | HRA (House Rent Allowance) | 40–50% of Basic | | Special Allowance | Remainder | | Employer PF Contribution | 12% of Basic | | Employer ESIC | 3.25% of Gross (if applicable) | | Gratuity |…
Frequently Asked Questions
How do I calculate income tax on salary in Python?
Define tax slabs as a list of (upper_limit, rate) tuples and process them sequentially. For each slab, calculate tax on the income that falls within that slab. Sum up the tax across all slabs. Apply standard deduction and other deductions before the tax calculation. The new FY2025-26 regime has a ₹75,000 standard deduction and slabs at 5%, 10%, 15%, 20%, and 30%.
How do I implement a salary calculator in Python?
Build four functions: (1) slab_tax(income, regime) for income tax, (2) pf_deduction(basic) for PF, (3) professional_tax(state) for PT, and (4) net_salary(ctc, components) that calls all three and returns a breakdown dict. Accept CTC and component percentages as inputs. Return a structured dictionary with gross, each deduction, net salary, and effective tax rate.
What tax slabs should I use in Python salary calculations?
For India FY2025-26 new regime: 0% up to ₹3L, 5% on ₹3L–₹7L, 10% on ₹7L–₹10L, 15% on ₹10L–₹12L, 20% on ₹12L–₹15L, 30% above ₹15L. Standard deduction: ₹75,000. Section 87A rebate: full tax rebate if net taxable income ≤ ₹7L (new regime). Old regime has deductions (80C up to ₹1.5L, HRA, LTA etc.) which reduce taxable income before applying different slabs.
How do I handle allowances and deductions in Python?
Model each component as a percentage or fixed amount. HRA exemption in the old regime is the minimum of: actual HRA received, 50% of basic (metro) or 40% of basic (non-metro), or actual rent minus 10% of basic. LTA is exempt for two trips per 4-year block. Standard deduction of ₹75,000 (new) or ₹50,000 (old) applies to all salaried employees automatically.
What Python library is used for payroll?
No standard Python payroll library exists for Indian payroll — the tax rules change annually and regional variations (professional tax by state, NPS rules) require custom logic. Most payroll applications build their own tax engine. For financial calculations, numpy-financial handles loan and investment math, but Indian income tax slab calculations are best implemented with plain Python dictionaries and loops.
All articles · theproductguy.in