vin-check-digit 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vin_check_digit-1.0.0/LICENSE +21 -0
- vin_check_digit-1.0.0/PKG-INFO +90 -0
- vin_check_digit-1.0.0/README.md +75 -0
- vin_check_digit-1.0.0/pyproject.toml +21 -0
- vin_check_digit-1.0.0/setup.cfg +4 -0
- vin_check_digit-1.0.0/vin.py +40 -0
- vin_check_digit-1.0.0/vin_check_digit.egg-info/PKG-INFO +90 -0
- vin_check_digit-1.0.0/vin_check_digit.egg-info/SOURCES.txt +8 -0
- vin_check_digit-1.0.0/vin_check_digit.egg-info/dependency_links.txt +1 -0
- vin_check_digit-1.0.0/vin_check_digit.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oil & Miles
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vin-check-digit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Validate a 17-character VIN and its check digit (49 CFR 565, North America). No dependencies.
|
|
5
|
+
Author: Oil & Miles
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://oilandmiles.com
|
|
8
|
+
Keywords: vin,nhtsa,check-digit,vehicle,validation
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# vin-check-digit
|
|
17
|
+
|
|
18
|
+
Check whether a 17-character VIN is valid before you look it up anywhere. One small file each for Python and JavaScript, no dependencies.
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
## What it checks
|
|
23
|
+
|
|
24
|
+
- Exactly 17 characters (spaces around it are ignored, lowercase is accepted).
|
|
25
|
+
- Only allowed characters: digits and letters, never I, O or Q (they look too much like 1 and 0).
|
|
26
|
+
- The check digit in position 9 matches the other 16 characters.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm i vin-check-digit
|
|
32
|
+
pip install vin-check-digit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Python
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from vin import validate, check_digit
|
|
39
|
+
|
|
40
|
+
validate("1HGCM82633A004352") # (True, 'valid')
|
|
41
|
+
validate("1HGCM82643A004352") # (False, 'check digit is 4, expected 3')
|
|
42
|
+
check_digit("1M8GDM9AXKP042788") # 'X'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
From the command line:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python3 vin.py 1HGCM82633A004352
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## JavaScript (Node or the browser)
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const { validate, checkDigit } = require("vin-check-digit"); // or require("./vin") from a copy of vin.js
|
|
55
|
+
|
|
56
|
+
validate("1HGCM82633A004352"); // { ok: true, reason: 'valid' }
|
|
57
|
+
validate("1HGCM8263"); // { ok: false, reason: 'a VIN has 17 characters' }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## How the check digit works
|
|
61
|
+
|
|
62
|
+
1. 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.
|
|
63
|
+
2. 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.
|
|
64
|
+
3. The products are added up and divided by 11. The remainder is the check digit, and a remainder of 10 is written as X.
|
|
65
|
+
|
|
66
|
+
The rule comes from the US federal VIN standard, 49 CFR Part 565.
|
|
67
|
+
|
|
68
|
+
## Limits
|
|
69
|
+
|
|
70
|
+
- 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.
|
|
71
|
+
- 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.
|
|
72
|
+
|
|
73
|
+
## Run the tests
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python3 -m unittest test_vin
|
|
77
|
+
node test_vin.js
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Decode a VIN
|
|
81
|
+
|
|
82
|
+
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](https://oilandmiles.com/decoders/vin-decoder).
|
|
83
|
+
|
|
84
|
+
## About
|
|
85
|
+
|
|
86
|
+
Made by [Oil & Miles](https://oilandmiles.com), a site about car repair costs, recalls and owner guides for US drivers.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# vin-check-digit
|
|
2
|
+
|
|
3
|
+
Check whether a 17-character VIN is valid before you look it up anywhere. One small file each for Python and JavaScript, no dependencies.
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## What it checks
|
|
8
|
+
|
|
9
|
+
- Exactly 17 characters (spaces around it are ignored, lowercase is accepted).
|
|
10
|
+
- Only allowed characters: digits and letters, never I, O or Q (they look too much like 1 and 0).
|
|
11
|
+
- The check digit in position 9 matches the other 16 characters.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm i vin-check-digit
|
|
17
|
+
pip install vin-check-digit
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Python
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from vin import validate, check_digit
|
|
24
|
+
|
|
25
|
+
validate("1HGCM82633A004352") # (True, 'valid')
|
|
26
|
+
validate("1HGCM82643A004352") # (False, 'check digit is 4, expected 3')
|
|
27
|
+
check_digit("1M8GDM9AXKP042788") # 'X'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
From the command line:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python3 vin.py 1HGCM82633A004352
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## JavaScript (Node or the browser)
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const { validate, checkDigit } = require("vin-check-digit"); // or require("./vin") from a copy of vin.js
|
|
40
|
+
|
|
41
|
+
validate("1HGCM82633A004352"); // { ok: true, reason: 'valid' }
|
|
42
|
+
validate("1HGCM8263"); // { ok: false, reason: 'a VIN has 17 characters' }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## How the check digit works
|
|
46
|
+
|
|
47
|
+
1. 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.
|
|
48
|
+
2. 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.
|
|
49
|
+
3. The products are added up and divided by 11. The remainder is the check digit, and a remainder of 10 is written as X.
|
|
50
|
+
|
|
51
|
+
The rule comes from the US federal VIN standard, 49 CFR Part 565.
|
|
52
|
+
|
|
53
|
+
## Limits
|
|
54
|
+
|
|
55
|
+
- 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.
|
|
56
|
+
- 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.
|
|
57
|
+
|
|
58
|
+
## Run the tests
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python3 -m unittest test_vin
|
|
62
|
+
node test_vin.js
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Decode a VIN
|
|
66
|
+
|
|
67
|
+
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](https://oilandmiles.com/decoders/vin-decoder).
|
|
68
|
+
|
|
69
|
+
## About
|
|
70
|
+
|
|
71
|
+
Made by [Oil & Miles](https://oilandmiles.com), a site about car repair costs, recalls and owner guides for US drivers.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vin-check-digit"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Validate a 17-character VIN and its check digit (49 CFR 565, North America). No dependencies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Oil & Miles" }]
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
keywords = ["vin", "nhtsa", "check-digit", "vehicle", "validation"]
|
|
15
|
+
classifiers = ["Programming Language :: Python :: 3", "Operating System :: OS Independent"]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://oilandmiles.com"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools]
|
|
21
|
+
py-modules = ["vin"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Validate a 17-character VIN and its check digit (49 CFR 565, North America)."""
|
|
2
|
+
|
|
3
|
+
VALUES = {
|
|
4
|
+
**{str(d): d for d in range(10)},
|
|
5
|
+
"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H": 8,
|
|
6
|
+
"J": 1, "K": 2, "L": 3, "M": 4, "N": 5, "P": 7, "R": 9,
|
|
7
|
+
"S": 2, "T": 3, "U": 4, "V": 5, "W": 6, "X": 7, "Y": 8, "Z": 9,
|
|
8
|
+
}
|
|
9
|
+
WEIGHTS = (8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def check_digit(vin):
|
|
13
|
+
"""Return the check digit ("0"-"9" or "X") a VIN should carry in position 9."""
|
|
14
|
+
vin = vin.strip().upper()
|
|
15
|
+
if len(vin) != 17:
|
|
16
|
+
raise ValueError("a VIN has 17 characters")
|
|
17
|
+
bad = [c for c in vin if c not in VALUES]
|
|
18
|
+
if bad:
|
|
19
|
+
raise ValueError("characters not allowed in a VIN: " + ", ".join(sorted(set(bad))))
|
|
20
|
+
rest = sum(VALUES[c] * w for c, w in zip(vin, WEIGHTS)) % 11
|
|
21
|
+
return "X" if rest == 10 else str(rest)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def validate(vin):
|
|
25
|
+
"""Return (ok, reason). ok is True when the length, characters and check digit are right."""
|
|
26
|
+
vin = vin.strip().upper()
|
|
27
|
+
try:
|
|
28
|
+
expected = check_digit(vin)
|
|
29
|
+
except ValueError as e:
|
|
30
|
+
return False, str(e)
|
|
31
|
+
if vin[8] != expected:
|
|
32
|
+
return False, "check digit is %s, expected %s" % (vin[8], expected)
|
|
33
|
+
return True, "valid"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
import sys
|
|
38
|
+
for arg in sys.argv[1:]:
|
|
39
|
+
ok, reason = validate(arg)
|
|
40
|
+
print("%s %s" % (arg.upper(), reason))
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vin-check-digit
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Validate a 17-character VIN and its check digit (49 CFR 565, North America). No dependencies.
|
|
5
|
+
Author: Oil & Miles
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://oilandmiles.com
|
|
8
|
+
Keywords: vin,nhtsa,check-digit,vehicle,validation
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# vin-check-digit
|
|
17
|
+
|
|
18
|
+
Check whether a 17-character VIN is valid before you look it up anywhere. One small file each for Python and JavaScript, no dependencies.
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
## What it checks
|
|
23
|
+
|
|
24
|
+
- Exactly 17 characters (spaces around it are ignored, lowercase is accepted).
|
|
25
|
+
- Only allowed characters: digits and letters, never I, O or Q (they look too much like 1 and 0).
|
|
26
|
+
- The check digit in position 9 matches the other 16 characters.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm i vin-check-digit
|
|
32
|
+
pip install vin-check-digit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Python
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from vin import validate, check_digit
|
|
39
|
+
|
|
40
|
+
validate("1HGCM82633A004352") # (True, 'valid')
|
|
41
|
+
validate("1HGCM82643A004352") # (False, 'check digit is 4, expected 3')
|
|
42
|
+
check_digit("1M8GDM9AXKP042788") # 'X'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
From the command line:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python3 vin.py 1HGCM82633A004352
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## JavaScript (Node or the browser)
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const { validate, checkDigit } = require("vin-check-digit"); // or require("./vin") from a copy of vin.js
|
|
55
|
+
|
|
56
|
+
validate("1HGCM82633A004352"); // { ok: true, reason: 'valid' }
|
|
57
|
+
validate("1HGCM8263"); // { ok: false, reason: 'a VIN has 17 characters' }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## How the check digit works
|
|
61
|
+
|
|
62
|
+
1. 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.
|
|
63
|
+
2. 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.
|
|
64
|
+
3. The products are added up and divided by 11. The remainder is the check digit, and a remainder of 10 is written as X.
|
|
65
|
+
|
|
66
|
+
The rule comes from the US federal VIN standard, 49 CFR Part 565.
|
|
67
|
+
|
|
68
|
+
## Limits
|
|
69
|
+
|
|
70
|
+
- 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.
|
|
71
|
+
- 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.
|
|
72
|
+
|
|
73
|
+
## Run the tests
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python3 -m unittest test_vin
|
|
77
|
+
node test_vin.js
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Decode a VIN
|
|
81
|
+
|
|
82
|
+
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](https://oilandmiles.com/decoders/vin-decoder).
|
|
83
|
+
|
|
84
|
+
## About
|
|
85
|
+
|
|
86
|
+
Made by [Oil & Miles](https://oilandmiles.com), a site about car repair costs, recalls and owner guides for US drivers.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vin
|