pk-cnic
Validate, normalise and read Pakistani CNIC numbers (12345-1234567-1). Pure Python, no dependencies, typed.
- Accepts the number with or without hyphens and stores one canonical form.
- Converts Urdu (Extended Arabic-Indic) and Arabic-Indic digits, as produced by OCR or Urdu keyboards.
- Reads the region from the first digit and the gender from the last (odd male, even female).
A CNIC has no check digit. Format validation catches badly formed input; it can't tell you the number is real or belongs to the person. Verify identity against NADRA's records.
Install
pip install pk-cnic
Usage
from pk_cnic import is_valid, normalize, parse
parse("35202-1234567-1")
# Cnic(number='35202-1234567-1', locality_code='35202', region='Punjab', gender='male')
normalize("3520212345671") # '35202-1234567-1'
normalize("۳۵۲۰۲-۱۲۳۴۵۶۷-۸") # '35202-1234567-8'
is_valid("35202-12345671") # False: hyphens must be all or none
parse and normalize raise ValueError for anything that isn't a 13-digit CNIC number.
Command line
pk-cnic 35202-1234567-1 42101-7654321-2
Numbers can also be piped on stdin. Exit code is 0 when all are valid and 1 otherwise.
What the digits mean
| Part | Digits | Meaning |
|---|---|---|
| Locality code | 1–5 | First digit is the region; the rest narrow it down |
| Serial | 6–12 | Sequence number |
| Last digit | 13 | Odd: male. Even: female |
Region by first digit, as commonly documented: 1 Khyber Pakhtunkhwa, 2 FATA (now part of Khyber Pakhtunkhwa), 3 Punjab, 4 Sindh, 5 Balochistan, 6 Islamabad, 7 Gilgit-Baltistan. Use the region and gender digits for consistency checks, not as the source of truth.
Background
Why there's no check digit, what to do about it, and where CNIC checks fit in onboarding: Validating a Pakistani CNIC number. For the wider verification flow: How KYC identity verification works.
License
MIT
Metadata
Release files for pk-cnic 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 |
|---|---|---|---|---|
| pk_cnic-0.1.0.tar.gz | 4.8 kB | With provenance | Details for pk_cnic-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pk_cnic-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pk_cnic-0.1.0-py3-none-any.whl |
Total release size: 9.8 kB
Release files / pk_cnic-0.1.0.tar.gz
| Download URL | pk_cnic-0.1.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b26e759c541b35840645511353c6e2123f49d79f801c0e71ca600b9c4329aa08
|
|
BLAKE2b-256 checksum How to use checksums |
59327b8f87163e9dd2933556e99af60596d5d931110c83643df6cd55f1e77b09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / pk_cnic-0.1.0-py3-none-any.whl
| Download URL | pk_cnic-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd25b93e73e10e805a178dd1d6894fec99ef1040cb5baa0f7736b4193c33f3da
|
|
BLAKE2b-256 checksum How to use checksums |
0ccf4b65a3cc90fddcb29159859d577a470d7bffe3616e8b50e7175581118798
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for pk-cnic 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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pk_cnic-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA 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.