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
Metadata
Release files for pancard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pancard-0.1.0.tar.gz | 13.5 kB | Without provenance | Details for pancard-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pancard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pancard-0.1.0-py3-none-any.whl |
Total release size: 23.8 kB
Release files / pancard-0.1.0.tar.gz
| Download URL | pancard-0.1.0.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27662c80f2a97808ca2a33de7e0ad2eb8115b568390088be61b9507352792ac1
|
|
BLAKE2b-256 checksum How to use checksums |
e7df19d66526e754d08787374006e76a52cf0cd87468f00a5f407dbfd878fbb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Release files / pancard-0.1.0-py3-none-any.whl
| Download URL | pancard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7fca088ca1c4717189810462939487bec2c339b68c72f855aa288ca51224f27e
|
|
BLAKE2b-256 checksum How to use checksums |
df8f362d98e81385f5dc863fbc01d4536224d65ccedab6bc92dc7e76ef672919
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Security for pancard 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.