A Python library for parsing, validating, and generating Egyptian National IDs
Project description
Egyptian National ID
A lightweight and comprehensive Python library for validating, parsing, and generating Egyptian National ID numbers. Built with type hints and designed for reliability in production environments.
Table of Contents
Features
- Validation: Comprehensive ID validation including checksum verification, date validation, and governorate checks
- Parsing: Extract birth date, gender, age, governorate, and region information from ID numbers
- Generation: Create valid mock Egyptian National IDs for testing and development
- Type Safety: Full type hints for better IDE support and code reliability
- Arabic Support: Handles Arabic numerals in ID input
- Cross-Platform: Compatible with Python 3.8+
Installation
From PyPI (Recommended)
pip install egyid
From Source
git clone https://github.com/Petter0x1/egyid.git
cd egyid
pip install .
Requirements
- Python 3.8 or higher
- No external dependencies
Quick Start
from egyid import EgyptianNationalId
# Validate an ID
is_valid = EgyptianNationalId.is_valid_id("29010280165195")
print(is_valid) # True
# Parse an ID
eid = EgyptianNationalId("29010280165195")
if eid.is_valid():
print(f"Birth Date: {eid.birth_date}") # 1990-10-28
print(f"Gender: {eid.gender}") # male
print(f"Governorate: {eid.governorate}") # Cairo
print(f"Age: {eid.age}") # 35 (as of 2026)
print(f"Region: {eid.region_name}") # Cairo
# Generate a new ID
new_id = EgyptianNationalId.generate({
"year": 1995,
"gender": "female",
"governorate": "01" # Cairo
})
print(new_id) # e.g., "39501010100000" (with correct checksum)
# Get full information as dictionary
info = eid.to_dict()
print(info)
# {
# "nationalId": "29010280165195",
# "birthYear": 1990,
# "birthMonth": 10,
# "birthDay": 28,
# "age": 35,
# "gender": "male",
# "governorate": "Cairo",
# "region": "Cairo",
# "insideEgypt": true,
# "isAdult": true
# }
API Reference
Class: EgyptianNationalId
Methods
EgyptianNationalId(id_value: Union[str, int])- Create an instance from an ID string or integeris_valid() -> bool- Check if the ID is validto_dict() -> Optional[Dict[str, Any]]- Return ID information as a dictionary (None if invalid)
Properties
birth_date: Optional[date]- Birth dateage: Optional[int]- Current agegender: str- 'male' or 'female'governorate: Optional[str]- Governorate nameregion_name: str- Region name
Class Methods
is_valid_id(id_value: Union[str, int]) -> bool- Validate without creating instancegenerate(options: Optional[Dict[str, Any]] = None) -> str- Generate a new valid IDparse(id_value: Union[str, int]) -> EgyptianNationalId- Alias for constructorcheck_is_male(id_value: Union[str, int]) -> bool- Check if ID belongs to malecheck_is_female(id_value: Union[str, int]) -> bool- Check if ID belongs to femalecheck_is_adult(id_value: Union[str, int]) -> bool- Check if person is 18+
Generation Options
The generate() method accepts an optional dictionary with:
year: int- Birth year (default: random 1950-current)month: int- Birth month (default: random 1-12)day: int- Birth day (default: valid for month/year)gender: str- 'male' or 'female' (default: random)governorate: str- 2-digit governorate code (default: random)
Testing
Run the test suite:
python -m unittest discover tests
Tests cover validation, parsing, generation, and edge cases across all supported Python versions.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
git clone https://github.com/Petter0x1/egyid.git
cd egyid
python -m venv venv
venv\Scripts\activate # On Windows
pip install -e .
python -m unittest discover tests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
@Petter0x1
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 egyid-1.0.0.tar.gz.
File metadata
- Download URL: egyid-1.0.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f665ba278589106071aa7d94e738bc96ceeafa6a88a4f7790fca690f18d6f6b
|
|
| MD5 |
1f8425552b549ae36033ae089f190a2f
|
|
| BLAKE2b-256 |
2435ded405b838603be73fd608a77856da5d0db0a361f310ad7092d062457a53
|
File details
Details for the file egyid-1.0.0-py3-none-any.whl.
File metadata
- Download URL: egyid-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bee2e3cf6efcf3fd70a2881481f5e977dd95d12526adac81b6ca0bf1c79421ad
|
|
| MD5 |
6d92d1d87b61634612954a4679860582
|
|
| BLAKE2b-256 |
a805a578b43dce89adc78c8fb1be4c5dae0ff0a172a5b4883ccfbdc2811fa6fc
|