Skip to main content

A comprehensive library for Indian Identity and Financial data validation.

Project description

indpy 🇮🇳

Python Version License Status PyPI

PyPI Downloads

indpy is a comprehensive Python library for validating and generating Indian government documents and financial identifiers. It uses official checksum algorithms (GSTIN Mod-36, Aadhaar Verhoeff) where applicable and provides regex-based structural validation for all document types.

🚀 Features

✅ Validation (14 Document Types)

  • PAN: Permanent Account Number (5 letters + 4 digits + 1 letter)
  • TAN: Tax Deduction and Collection Account Number (4 letters + 5 digits + 1 letter)
  • Driving License (DL): State + RTO + Year + serial number (15 characters)
  • GSTIN: GST Identification Number (with Mod-36 checksum verification)
  • Aadhaar: 12-digit unique identity (with Verhoeff checksum algorithm)
  • Voter ID (EPIC): Electoral ID (3 letters + 7 digits)
  • Passport: Passport number (1 letter + 7 digits)
  • Mobile: Indian 10-digit format (starts with 6–9)
  • IFSC: Bank branch code (4 letters + 0 + 6 alphanumeric)
  • Vehicle (RC): Registration certificate (state code + regional code + registration)
  • UPI: Unified Payments Interface handle
  • CIN: Corporate Identification Number (21-character corporate format)
  • Pincode: Indian postal code (6 digits, no leading zero)
  • Credit Card: 13–19 digit card numbers (with Luhn Mod-10 checksum)

🎲 Data Generation (11 Mock Data Generators)

  • Generate valid PAN numbers with realistic format
  • Generate valid TAN numbers
  • Generate valid Driving License numbers
  • Generate valid mobile numbers (6–9 prefix)
  • Generate valid Aadhaar numbers with mathematically correct Verhoeff checksum
  • Generate Voter ID numbers
  • Generate Passport numbers
  • Generate Vehicle registration numbers
  • Generate CIN numbers
  • Generate Pincode numbers
  • Generate valid Visa-format credit card numbers (Luhn checksum)

📦 Installation

Install from PyPI:

pip install indpy_core

Note: The package name on PyPI is indpy_core, but you import it in Python as indpy.

Install for local development:

# Clone the repository
git clone https://github.com/harshgupta2125/Indpy.git
cd Indpy
pip install -e .

💻 Usage

1️⃣ Python — Validation

from indpy import (
    is_pan, is_gstin, is_vehicle, is_aadhaar, is_voterid, 
   is_passport, is_mobile, is_ifsc, is_upi, is_cin, is_pincode,
   is_credit_card, is_tan, is_dl
)

# Validate PAN (Permanent Account Number)
print(is_pan("ABCDE1234F"))  # True

# Validate TAN
print(is_tan("DELM12345L"))  # True

# Validate Driving License
print(is_dl("MH1220140001234"))  # True

# Validate GSTIN (includes official Mod-36 checksum)
print(is_gstin("29ABCDE1234F1Z5"))  # True/False based on checksum

# Validate Aadhaar (12-digit with Verhoeff checksum algorithm)
print(is_aadhaar("379980670385"))  # True/False based on Verhoeff

# Validate Voter ID (EPIC format)
print(is_voterid("ABC1234567"))  # True

# Validate Passport
print(is_passport("A1234567"))  # True

# Validate Mobile number (Indian format, 6-9 prefix)
print(is_mobile("9876543210"))  # True

# Validate IFSC code (Bank branch)
print(is_ifsc("SBIN0004321"))  # True

# Optional: enforce known bank codes
known_banks = {"SBIN", "HDFC", "ICIC"}
print(is_ifsc("SBIN0004321", valid_bank_codes=known_banks))  # True

# Validate Vehicle registration number
print(is_vehicle("DL01CA1234"))  # True

# Validate UPI handle
print(is_upi("user@paytm"))  # True

# Validate CIN (Corporate Identification Number)
print(is_cin("L99999MH2014PLC241895"))  # True

# Validate Pincode (6 digits, no leading zero)
print(is_pincode("560034"))  # True

# Validate Credit/Debit Card (Luhn Mod-10)
print(is_credit_card("4111 1111 1111 1111"))  # True

2️⃣ Python — Generating Mock Data

from indpy import Generate

# Generate random PAN
print(Generate.pan())      # e.g. "BPLPZ5821K"

# Generate random TAN
print(Generate.tan())      # e.g. "DELM12345L"

# Generate random Driving License
print(Generate.dl())       # e.g. "MH1220140001234"

# Generate random mobile number
print(Generate.mobile())   # e.g. "9876123450"

# Generate random Aadhaar (with mathematically valid Verhoeff checksum)
print(Generate.aadhaar())  # e.g. "379980670385"

# Generate random Voter ID
print(Generate.voterid())  # e.g. "ABC1234567"

# Generate random Passport
print(Generate.passport()) # e.g. "A1234567"

# Generate random Vehicle registration
print(Generate.vehicle())  # e.g. "DL04CA9921"

# Generate random CIN
print(Generate.cin())      # e.g. "L12345AB2024PLC123456"

# Generate random Pincode
print(Generate.pincode())  # e.g. "560034"

# Generate random Credit Card (Visa-like, Luhn-valid)
print(Generate.credit_card())  # e.g. "4532123456781234"

3️⃣ Command Line Interface

Check version:

indpy --version
# Output: 0.1.7

Validate a document:

# Validate PAN
indpy check pan ABCDE1234F
# Output: ✅ PAN Validation Result: True

# Validate TAN
indpy check tan DELM12345L
# Output: ✅ TAN Validation Result: True

# Validate Driving License
indpy check dl MH1220140001234
# Output: ✅ DL Validation Result: True

# Validate Aadhaar
indpy check aadhaar 379980670385
# Output: ✅ AADHAAR Validation Result: True

# Validate Voter ID
indpy check voterid ABC1234567
# Output: ✅ VOTERID Validation Result: True

# Validate Passport
indpy check passport A1234567
# Output: ✅ PASSPORT Validation Result: True

# Validate CIN
indpy check cin L99999MH2014PLC241895
# Output: ✅ CIN Validation Result: True

# Validate Pincode
indpy check pincode 560034
# Output: ✅ PINCODE Validation Result: True

# Validate Credit Card
indpy check credit_card 4111111111111111
# Output: ✅ CREDIT_CARD Validation Result: True

Generate mock data:

# Generate PAN
indpy gen pan
# Output: ABCDE1234F

# Generate TAN
indpy gen tan
# Output: ABCD12345E

# Generate Driving License
indpy gen dl
# Output: MH1220140001234

# Generate Aadhaar
indpy gen aadhaar
# Output: 379980670385

# Generate Vehicle
indpy gen vehicle
# Output: DL04CA9921

# Generate Voter ID
indpy gen voterid
# Output: ABC1234567

# Generate Passport
indpy gen passport
# Output: A1234567

# Generate CIN
indpy gen cin
# Output: L12345AB2024PLC123456

# Generate Pincode
indpy gen pincode
# Output: 560034

# Generate Credit Card
indpy gen credit_card
# Output: 4XXXXXXXXXXXXXXX

🛠️ Supported Documents

Document Regex Pattern Checksum Notes
PAN ^[A-Z]{5}[0-9]{4}[A-Z]$ Structure only 10-character format
TAN ^[A-Z]{4}[0-9]{5}[A-Z]$ Structure only TDS/TCS account number
Driving License ^[A-Z]{2}[0-9]{2}[0-9]{4}[0-9]{7}$ N/A Sarathi-style 15-character format
GSTIN ^[0-9]{2}[A-Z]{5}[0-9A-Z]{9}[0-9]$ Mod-36 15-character GST ID
Aadhaar ^[2-9]\d{11}$ Verhoeff 12-digit unique ID
Voter ID ^[A-Z]{3}[0-9]{7}$ N/A EPIC format
Passport ^[A-Z][0-9]{7}$ N/A 8-character format
Mobile ^[6-9]\d{9}$ N/A 10-digit Indian number
IFSC ^[A-Z]{4}0[A-Z0-9]{6}$ N/A Bank branch code
Vehicle ^[A-Z]{2}\d{1,2}[A-Z]{1,2}\d{1,4}$ N/A State code + registration
UPI ^[a-zA-Z0-9.\-_]+@[a-zA-Z]+$ N/A Payment handle
CIN ^[A-Z][0-9]{5}[A-Z]{2}[0-9]{4}[A-Z]{3}[0-9]{6}$ N/A Corporate ID (21-char)
Pincode ^[1-9]\d{5}$ N/A 6-digit postal code
Credit Card ^\d{13,19}$ Luhn (Mod-10) Global card checksum standard
� Testing

Run the comprehensive test suite:

# Run all tests
python3 -m pytest tests/

# Run specific test file
python3 -m pytest tests/test_lib.py -v

# Run with coverage
python3 -m pytest tests/ --cov=indpy

Test files include:

  • test_lib.py: Comprehensive tests for all 14 validators and 11 generators
  • Coverage includes structural validation, checksum algorithms, and edge cases

🤝 Contributing

Contributions are welcome! Typical workflow:

  1. Fork the repository
  2. Create a feature branch:
    git checkout -b feature/NewValidator
    
  3. Add your validator to indpy/validators.py
  4. Add corresponding generator to indpy/generators.py
  5. Update indpy/init.py to export new functions
  6. Add tests to tests/test_lib.py
  7. Commit with clear message:
    git commit -m "Add new validator for [document type]"
    
  8. Push and open a pull request

Code Style:

  • Follow PEP 8 standards
  • Add comprehensive docstrings with regex patterns
  • Include usage examples in docstrings
  • Test coverage for all new validators

📚 API Reference

All validators return a boolean (True/False). All generators return a string.

Validators

is_pan(pan: str) -> bool
is_tan(tan: str) -> bool
is_dl(dl: str) -> bool
is_gstin(gstin: str) -> bool
is_aadhaar(aadhaar: str) -> bool
is_voterid(voterid: str) -> bool
is_passport(passport: str) -> bool
is_mobile(mobile: str) -> bool
is_ifsc(ifsc: str) -> bool
is_vehicle(vehicle: str) -> bool
is_upi(upi: str) -> bool
is_cin(cin: str) -> bool
is_pincode(pincode: str) -> bool
is_credit_card(card_number: str) -> bool

Generators

Generate.pan() -> str
Generate.tan() -> str
Generate.dl() -> str
Generate.gstin() -> str  # Note: Does not generate checksum
Generate.aadhaar() -> str  # With valid Verhoeff checksum
Generate.voterid() -> str
Generate.passport() -> str
Generate.mobile() -> str
Generate.vehicle() -> str
Generate.cin() -> str
Generate.pincode() -> str
Generate.credit_card() -> str

📄 License

Distributed under the MIT License. See LICENSE for details.

📊 Project Status

Version: 0.1.7

🆕 What's New in 0.1.7

  • Added TAN validator: is_tan(...)
  • Added Driving License validator: is_dl(...)
  • Added generators: Generate.tan() and Generate.dl()
  • Added CLI support:
    • indpy check tan <number>
    • indpy check dl <number>
    • indpy gen tan
    • indpy gen dl
  • Updated tests and documentation for both features

🆕 What's New in 0.1.6

  • Added credit/debit card validation via Luhn (Mod-10): is_credit_card(...)
  • Added valid Visa-style test card generation: Generate.credit_card()
  • Added CLI support:
    • indpy check credit_card <number>
    • indpy gen credit_card
  • Updated tests and documentation for new validator and generator

Features:

  • ✅ 14 document validators (all functional)
  • ✅ 11 mock data generators (production-ready)
  • ✅ Official checksum algorithms (Verhoeff, Mod-36, Luhn)
  • ✅ Comprehensive documentation with regex patterns
  • ✅ CLI support for validation and generation
  • ✅ PEP 8 compliant codebase
  • ✅ Full test coverage

Roadmap:

  • Add Enrollment ID (UID) validator
  • Add GST Certificate validator
  • Add international passport format support
git add README.md
git commit -m "Update README formatting"
git push origin main

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

indpy_core-0.1.7.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

indpy_core-0.1.7-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file indpy_core-0.1.7.tar.gz.

File metadata

  • Download URL: indpy_core-0.1.7.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for indpy_core-0.1.7.tar.gz
Algorithm Hash digest
SHA256 be36eee93cfb202c02daefbe4eda58990ea5e84f7e9c2678a35ccca203f7dd4d
MD5 18da1769c21075685ca73f1d0d367e2c
BLAKE2b-256 5b7a911d3bb383a588a0b6cd950b137090de6693184cee2c8b2ee07f8e545574

See more details on using hashes here.

File details

Details for the file indpy_core-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: indpy_core-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for indpy_core-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1aeddbbf477ad43f0306faa5d2c7760258d9867d021439c3c35d0076a51569b8
MD5 9e8538b9172182ce241c5fac7c926e9a
BLAKE2b-256 0f3bf6df5586b9c6f717d1f0e9ae3ea9b56652675fc221e7d2d1afc0380cbcd5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page