A Python package to validate and decode Indian PAN card numbers
Project description
PAN Card Validator
A Python package to validate and decode Indian PAN (Permanent Account Number) card numbers.
Features
- ✅ Validate PAN card numbers according to Indian Income Tax standards
- 🔍 Decode PAN structure and extract meaningful information
- 📝 Detailed breakdown of each character's meaning
- 🖥️ Command-line interface for quick validation
- 🐍 Simple Python API for integration
- 🚀 Zero dependencies
- 💯 Comprehensive validation with detailed error messages
Installation
pip install pancard
Quick Start
Command Line Usage
# Validate a PAN
pancard ABCDE1234F --validate
# Decode a PAN (default behavior)
pancard ABCDE1234F
# Get a summary
pancard ABCDE1234F --summary
# Output as JSON
pancard ABCDE1234F --json
Python API Usage
from pancard import validate_pan, decode_pan, PANValidator, PANDecoder
# Quick validation
is_valid = validate_pan("ABCDE1234F")
print(f"Valid: {is_valid}")
# Quick decode
info = decode_pan("ABCDE1234F")
print(info)
# Using validator class
validator = PANValidator()
is_valid = validator.validate("ABCDE1234F")
# Strict validation with exceptions
try:
validator.validate_strict("ABCDE1234F")
print("PAN is valid!")
except InvalidPANError as e:
print(f"Invalid PAN: {e}")
# Using decoder class
decoder = PANDecoder()
decoded_info = decoder.decode("ABCDE1234F")
print(decoded_info)
# Get human-readable summary
summary = decoder.get_summary("ABCDE1234F")
print(summary)
PAN Structure Explanation
A PAN is a 10-character alphanumeric identifier with the format: AAAAA9999A
Character Breakdown:
-
First 3 characters (AAA): Alphabetic series running from AAA to ZZZ
-
4th character: Type of PAN holder
- P = Individual (Person)
- C = Company
- H = Hindu Undivided Family (HUF)
- F = Firm/Partnership
- A = Association of Persons (AOP)
- T = Trust
- B = Body of Individuals (BOI)
- L = Local Authority
- J = Artificial Juridical Person
- G = Government
-
5th character: First letter of PAN holder's last name/surname
-
Next 4 characters (6-9): Sequential numbers from 0001 to 9999
-
Last character: Alphabetic check digit
Example
For PAN ABCPE1234K:
ABC- Alphabetic seriesP- Individual personE- Surname starts with 'E'1234- Unique sequential numberK- Check digit
API Reference
Functions
validate_pan(pan_number: str) -> bool
Validates a PAN card number.
decode_pan(pan_number: str) -> dict
Decodes a PAN card number and returns detailed information.
Classes
PANValidator
validate(pan_number: str) -> bool: Basic validationvalidate_strict(pan_number: str) -> bool: Strict validation with exceptions
PANDecoder
decode(pan_number: str) -> dict: Decode PAN structureget_summary(pan_number: str) -> str: Get human-readable summary
Exceptions
InvalidPANError
Raised when PAN validation fails in strict mode.
Decoded Information Format
{
'pan_number': 'ABCPE1234K',
'is_valid': True,
'structure': {
'pattern': 'AAAAA9999A',
'total_length': 10,
'alphabets_count': 6,
'digits_count': 4
},
'holder_type': {
'code': 'P',
'type': 'Individual (Person)',
'description': 'Individual taxpayer (most common type)'
},
'components': {
'first_three_letters': {...},
'fourth_letter': {...},
'fifth_letter': {...},
'next_four_digits': {...},
'last_letter': {...}
},
'detailed_breakdown': [...]
}
Development
Setting up development environment
# Clone the repository
git clone https://github.com/yourusername/pancard.git
cd pancard
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
flake8 pancard/
black pancard/ --check
mypy pancard/
Running Tests
pytest tests/ -v
pytest --cov=pancard tests/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This package is for educational and validation purposes only. Always verify PAN details with official Income Tax Department resources for critical applications.
Support
If you encounter any problems or have suggestions, please open an issue.
Acknowledgments
- Income Tax Department of India for PAN structure documentation
- Python community for inspiration and support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pancard-0.1.0.tar.gz.
File metadata
- Download URL: pancard-0.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27662c80f2a97808ca2a33de7e0ad2eb8115b568390088be61b9507352792ac1
|
|
| MD5 |
7343d178af90fd7bdfc38eaf941df207
|
|
| BLAKE2b-256 |
e7df19d66526e754d08787374006e76a52cf0cd87468f00a5f407dbfd878fbb5
|
File details
Details for the file pancard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pancard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fca088ca1c4717189810462939487bec2c339b68c72f855aa288ca51224f27e
|
|
| MD5 |
e0a2b55a98021e0cd4723f486433a231
|
|
| BLAKE2b-256 |
df8f362d98e81385f5dc863fbc01d4536224d65ccedab6bc92dc7e76ef672919
|