Python – Data Processing and Automation

Here we create a quick and dirty solution for python VIN decoder implementation.

Python is a scripting language that evolved into data processing and automation tool powering a lot of websites. Below is an example code using VinLINK Cloud API reports. For the full code, please visit this github: https://github.com/Piotr3kK/vinlink-http-vin-decoder-python

Implementing a Python Decoder

First, we start with necessary imports then, we use python’s request, xml.etree packages and sys for command line arguments processing.

import sys
import requests
from requests.auth import HTTPDigestAuth
import xml.etree.ElementTree as ET

Then we declare VinLiNK™ service entry URL prefix and then process every VIN provided at the command line:

url = 'http://service.vinlink.com/report?type=BASIC_PLUS&vin='
for vin in sys.argv[1:]:
        results = requests.get(url+vin, auth=HTTPDigestAuth('login', 'password'))
        if results:
            tree = ET.fromstring(results.text)
            e = tree.findall('./REPORT/VINPOWER/VIN/DECODED/ITEM')
            for i in e:
                print('%s = %s' % (i.attrib['name'], i.attrib['value']))

This code is based on an XML api, and should make sense.

VinLink is also accessible using SOAP web-service protocol. Below is an analogous code example using Python SOAP and the Zeep Library.

Imports first:

import sys
from zeep import Client
from zeep.wsse.username import UsernameToken

This brings us to the following code:

client = Client('http://ws.vinlink.com/VLWS/services/Decoder?wsdl', wsse=UsernameToken('login', 'password'))
    for vin in sys.argv[1:]:
        results = client.service.decode(vin, 'BASIC_PLUS')
        if results:
            result = results[0]
            # print main attributes
            print("Model Year: %s" % result.modelYear)
            print("Make: %s" % result.make)
            print("Model: %s" % result.model)
            print("Trim Level: %s" % result.trimLevel)
            print("Engine Type: %s" % result.engineType)
            print("Body Type: %s" % result.bodyType)
            print("Drive Line Type: %s" % result.driveLineType)
            print("Transmission: %s" % result.transmission)
            # print all available attributes
            attributes = result.vinSpecification.Item
            for a in attributes:
                print("%s = %s" % (a.name, a.value))

This type of solution allows ESP Data Solutions to create a report that is web service structured from an object. Implementing vin decoder in python is easy!

For more details and the full code please visit:

https://github.com/Piotr3kK/vinlink-vin-decoder-python

More questions about implementing the Python VIN decoder, please send us an email: Sales@espdata.com.