CarsXE Developer

Python Quickstart Guide

Get started with CarsXE's Python SDK to integrate comprehensive vehicle data into your Python applications.


The CarsXE Python SDK provides a simple and powerful way to integrate vehicle data into your Python applications. This guide will help you get started quickly.

For more information, see the package on PyPI.

Installation

Install the CarsXE Python package using pip:

pip install carsxe

Setup

First, import the CarsXE client and initialize it with your API key:

app.py

from carsxe_api import CarsXE 
# Initialize the client 
carsxe = CarsXE('YOUR_API_KEY_HERE') 

Basic Usage

VIN Specifications

app.py

vin = 'WBAFR7C57CC811956'
try:
    vehicle = carsxe.specs({"vin": vin})
    print(vehicle["input"]["vin"])
except Exception as error:
    print(f"Error: {error}")

International VIN Decoder

app.py

try:
    intvin = carsxe.int_vin_decoder({"vin": "WF0MXXGBWM8R43240"})
    print(intvin)
except Exception as error:
    print(f"Error: {error}")

Market Value

app.py

try:
    marketvalue = carsxe.market_value({"vin": "WBAFR7C57CC811956"})
    print(marketvalue)
except Exception as error:
    print(f"Error: {error}")

Vehicle History

app.py

try:
    history = carsxe.history({"vin": "WBAFR7C57CC811956"})
    print(history)
except Exception as error:
    print(f"Error: {error}")

License Plate Decoder

app.py

try:
    decoded_plate = carsxe.plate_decoder({"plate": "7XER187", "state": "CA", "country": "US"})
    print(decoded_plate)
except Exception as error:
    print(f"Error: {error}")

Vehicle Images

app.py

try:
    images = carsxe.images({"make": "BMW", "model": "X5", "year": "2019"})
    print(images)
except Exception as error:
    print(f"Error: {error}")

Vehicle Recalls

app.py

try:
    recalls = carsxe.recalls({"vin": "1C4JJXR64PW696340"})
    print(recalls)
except Exception as error:
    print(f"Error: {error}")

Plate Image Recognition

app.py

try:
    plateimg = carsxe.plate_image_recognition({"upload_url": "https://api.carsxe.com/img/apis/plate_recognition.JPG"})
    print(plateimg)
except Exception as error:
    print(f"Error: {error}")

VIN OCR from Image

app.py

try:
    vinocr = carsxe.vin_ocr({"upload_url": "https://api.carsxe.com/img/apis/plate_recognition.JPG"})
    print(vinocr)
except Exception as error:
    print(f"Error: {error}")

app.py

try:
    yymm = carsxe.year_make_model({"year": "2012", "make": "BMW", "model": "5 Series"})
    print(yymm)
except Exception as error:
    print(f"Error: {error}")

OBD Code Decoder

app.py

try:
    obdcode = carsxe.obd_codes_decoder({"code": "P0115"})
    print(obdcode)
except Exception as error:
    print(f"Error: {error}")

Error Handling

The SDK provides comprehensive error handling:

error_handling.py

from carsxe_api import CarsXE
carsxe = CarsXE('YOUR_API_KEY')
try:
    result = carsxe.specs({"vin": "INVALID_VIN"})
except Exception as error:
    if hasattr(error, 'status_code'):
        if error.status_code == 400:
            print("Invalid VIN format")
        elif error.status_code == 401:
            print("Invalid API key")
        elif error.status_code == 429:
            print("Rate limit exceeded")
        else:
            print(f"Unexpected error: {error}")
    else:
        print(f"Error: {error}")

Environment Variables

Store your API key securely using environment variables:

.env

CARSXE_API_KEY=your_api_key_here 

app.py

import os from dotenv 
import load_dotenv from carsxe_api 
import CarsXE 
load_dotenv() 
carsxe = CarsXE(os.environ.get('CARSXE_API_KEY')) 

Available Endpoints

MethodDescription
carsxe.specs({"vin": vin})Decode VIN & get full vehicle specifications
carsxe.int_vin_decoder({"vin": vin})Decode VIN with worldwide support
carsxe.plate_decoder({"plate": plate, "state": state, "country": country})Decode license plate info
carsxe.market_value({"vin": vin})Estimate vehicle market value based on VIN
carsxe.history({"vin": vin})Retrieve vehicle history
carsxe.images({"make": make, "model": model, "year": year})Fetch images by make, model, year, trim
carsxe.recalls({"vin": vin})Get safety recall data for a VIN
carsxe.plate_image_recognition({"upload_url": url})Read & decode plates from images
carsxe.vin_ocr({"upload_url": url})Extract VINs from images using OCR
carsxe.year_make_model({"year": year, "make": make, "model": model})Query vehicle by year, make, model and trim
carsxe.obd_codes_decoder({"code": code})Decode OBD error/diagnostic codes

Start building powerful automotive applications with CarsXE's Python SDK!