vin-check-digit
Check whether a 17-character VIN is valid before you look it up anywhere. One small file each for Python and JavaScript, no dependencies.
A VIN is the 17-character code on every car sold in North America. Its 9th character is a check digit, calculated from the other 16. If one character is mistyped, the check digit almost always stops matching, so you can catch the mistake before you search a recall database or a parts catalog with the wrong number.
What it checks
- Exactly 17 characters (spaces around it are ignored, lowercase is accepted).
- Only allowed characters: digits and letters, never I, O or Q (they look too much like 1 and 0).
- The check digit in position 9 matches the other 16 characters.
Install
npm i vin-check-digit
pip install vin-check-digit
Python
from vin import validate, check_digit
validate("1HGCM82633A004352") # (True, 'valid')
validate("1HGCM82643A004352") # (False, 'check digit is 4, expected 3')
check_digit("1M8GDM9AXKP042788") # 'X'
From the command line:
python3 vin.py 1HGCM82633A004352
JavaScript (Node or the browser)
const { validate, checkDigit } = require("vin-check-digit"); // or require("./vin") from a copy of vin.js
validate("1HGCM82633A004352"); // { ok: true, reason: 'valid' }
validate("1HGCM8263"); // { ok: false, reason: 'a VIN has 17 characters' }
How the check digit works
- Each letter is turned into a number (A=1, B=2 ... H=8, J=1 ... R=9, S=2 ... Z=9). Digits keep their value.
- Each of the 17 values is multiplied by the weight of its position: 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2. Position 9 has weight 0, because it is the check digit itself.
- The products are added up and divided by 11. The remainder is the check digit, and a remainder of 10 is written as X.
The rule comes from the US federal VIN standard, 49 CFR Part 565.
Limits
- The check digit is required for cars and light trucks sold in the US and Canada. Vehicles built for other markets often do not use it, so a "wrong" check digit there does not mean the VIN is fake.
- A valid check digit only means the VIN is well formed. It does not tell you the car's history, and it does not prove the VIN belongs to the car in front of you.
Run the tests
python3 -m unittest test_vin
node test_vin.js
Decode a VIN
To see what a valid VIN says about the car (make, model, year, engine) and its open recalls, try the free VIN decoder at Oil & Miles.
About
Made by Oil & Miles, a site about car repair costs, recalls and owner guides for US drivers.
License
MIT
Metadata
Release files for vin-check-digit 1.0.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 |
|---|---|---|---|---|
| vin_check_digit-1.0.0.tar.gz | 3.9 kB | Without provenance | Details for vin_check_digit-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vin_check_digit-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for vin_check_digit-1.0.0-py3-none-any.whl |
Total release size: 8.1 kB
Release files / vin_check_digit-1.0.0.tar.gz
| Download URL | vin_check_digit-1.0.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
097be8e533ba8d14ad7ba78a53d210e662c6f19aeb75f61894999ebf4d16f97d
|
|
BLAKE2b-256 checksum How to use checksums |
e2b6504068ab2c2fb69a73b5551faa0ef94743e9bfb57e92a530939d5f3eb70d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / vin_check_digit-1.0.0-py3-none-any.whl
| Download URL | vin_check_digit-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d027adbe935fea3f2529656fc614bd5076ddeb04b07f5a9497101707b2647b7
|
|
BLAKE2b-256 checksum How to use checksums |
31fcf4c8da58bd30d16f306fa57a5bcd3e2976b0416988693960c8df50897769
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for vin-check-digit 1.0.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.