iranian-national-code
A small, dependency-free Python library to validate and generate Iranian National Codes (کد ملی).
Python port of the original JavaScript project by majidh1: https://github.com/majidh1/iranianNationalCode
Install
Using uv (recommended):
uv add iranian-national-code
Using pip:
pip install iranian-national-code
Usage
from iranian_national_code import (
validate,
validate_bulk,
generate,
generate_round,
generate_bulk,
)
# Validate a single code
validate("0499370899") # -> True / False
# Validate many codes at once
validate_bulk(["0499370899", "1111111111"]) # -> [True, False]
# Generate a single random valid code
generate() # -> e.g. "8856815311"
# Generate a code with a "rounder" digit pattern
generate_round() # -> e.g. "6510101017"
# Generate many codes at once
generate_bulk(5) # -> list of 5 valid codes
generate_bulk(5, round_style=True) # -> list of 5 "round" codes
API
| Function | Description |
|---|---|
validate(code: str) -> bool |
Checks the syntax and checksum of a single national code. |
validate_bulk(codes: list[str]) -> list[bool] |
Validates a list of codes, returning a matching list of booleans. |
generate() -> str |
Generates a random, checksum-valid national code. |
generate_round() -> str |
Generates a random, checksum-valid code biased toward lower/repeated digits. |
generate_bulk(count: int, round_style: bool = False) -> list[str] |
Generates count random, checksum-valid codes. |
Development
This project uses uv for dependency management and packaging.
git clone https://github.com/twilispar/iranian-national-code.git
cd iranian-national-code
uv sync
uv build
License
MIT — see LICENSE. Original algorithm and project by majidh1.
Metadata
Release files for iranian-national-code 1.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 | |
|---|---|---|---|
| iranian_national_code-1.1.0.tar.gz | 142.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iranian_national_code-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 147.1 kB
Release files / iranian_national_code-1.1.0.tar.gz
| Download URL | iranian_national_code-1.1.0.tar.gz |
|---|---|
| Size | 142.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e2e8fb07be0f028cd5b69410830f0f59ce2e3c33ab126406ae8aedec5bc07cd
|
|
BLAKE2b-256 checksum How to use checksums |
715fb96c0d64a8683e1339a6ef3d789a2982707107c392e3006877d5d794bc77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / iranian_national_code-1.1.0-py3-none-any.whl
| Download URL | iranian_national_code-1.1.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23d16881d6b33153b22f6dd0d705b9048e065ac45b7c804137348090aee5be23
|
|
BLAKE2b-256 checksum How to use checksums |
651b45d025e116b82f0c8693a545efa34889004190ca88780d720d1be2e1d30f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|