Detectors
PESEL
Detect and validate Polish national identification numbers with Mod 10 checksum and date/gender extraction.
Purpose
Use the pesel detector for Polish national identification numbers (PESEL — Powszechny Elektroniczny System Ewidencji Ludności).
This detector validates the encoded date and checksum, and exposes metadata for gender and birth date extraction.
Detector Name
peselSupported Formats
- 11 digits:
YYMMDDNNNNK - PESEL encodes date of birth in positions 1-6 and a checksum in position 11
For women, the encoded month uses +20 for birth month.
Century encoding in the month field:
01-12→ 1900s21-32→ 2000s41-52→ 2100s81-92→ 1800s
Validation Logic
The detector performs validation in this order:
- Require exactly 11 digits.
- Parse the encoded date (with century encoding from month field).
- Run the Mod 10 weighted checksum.
Checksum Algorithm
- Multiply each digit by weights
[1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1]. - Sum the products.
- Take
sum % 10. - If the result is
0, the PESEL is valid.
Python Examples
Explicit Engine (Recommended)
from fastpii import FastPII
from fastpii.countries.pl import PolishPack
priority = {"pesel": 100, "email": 70, "name": 50, "phone": 20}
engine = FastPII(priority=priority)
engine.register(PolishPack())
result = engine.detect("PESEL: 44051401458", detector_names=["pesel"])Convenience API
from fastpii import PrivacyGuard
guard = PrivacyGuard(regions=["pl"])
result = guard.validate("44051401458", "pesel")
print(result.is_valid)
print(result.metadata)Convenience API — Detect in free text
from fastpii import PrivacyGuard
guard = PrivacyGuard(regions=["pl"])
result = guard.detect("PESEL: 44051401458", detector_names=["pesel"])
for finding in result.findings:
print(finding.type, finding.value, finding.metadata)Expected Metadata
When validation or detection succeeds, this detector can return:
sex:maleorfemalebirth_date: normalized date stringchecksum_valid:True
Example Output
{
"sex": "male",
"birth_date": "1944-05-14",
"checksum_valid": True,
}Limitations
- PESEL is specific to Polish citizens and residents.
- The detector requires context or explicit formatting to distinguish from other 11-digit numbers.
- Metadata depends on successful date parsing.