FastPII Docs
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

pesel

Supported 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 → 1900s
  • 21-32 → 2000s
  • 41-52 → 2100s
  • 81-92 → 1800s

Validation Logic

The detector performs validation in this order:

  1. Require exactly 11 digits.
  2. Parse the encoded date (with century encoding from month field).
  3. Run the Mod 10 weighted checksum.

Checksum Algorithm

  1. Multiply each digit by weights [1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1].
  2. Sum the products.
  3. Take sum % 10.
  4. If the result is 0, the PESEL is valid.

Python Examples

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: male or female
  • birth_date: normalized date string
  • checksum_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.

On this page