---
title: "Python"
description: "Official CarsXE SDK for Python."
canonical_url: "https://docs.carsxe.com/docs/sdks/python"
markdown_url: "https://docs.carsxe.com/docs/sdks/python.md"
last_updated: "1980-01-01"
x_farming_labs_generated_preamble: true
agent:
  task: "Install and use the carsxe Python SDK to call CarsXE API endpoints."
  outcome: "The Python client is installed and its documented example returns a successful CarsXE response."
  prerequisites:
    - "A valid CarsXE API key."
    - "The runtime and package tooling required by the Python installation steps."
  verification:
    - "Run the documented Python example and confirm it authenticates and returns vehicle data without an SDK or API error."
  failureModes:
    - symptom: "The Python client cannot install, authenticate, or complete the example request."
      resolution: "Verify the runtime version, package installation, API-key environment variable, and endpoint inputs before rerunning the example."
---

# Python
URL: /docs/sdks/python
LLM index: /llms.txt
Description: Official CarsXE SDK for Python.
Related: /docs/sdks, /docs/get-started

<!-- farming-labs:agent-contract:start -->
## Agent Contract

Task: Install and use the carsxe Python SDK to call CarsXE API endpoints.
Outcome: The Python client is installed and its documented example returns a successful CarsXE response.

### Prerequisites

- A valid CarsXE API key.
- The runtime and package tooling required by the Python installation steps.

### Verification

- Run the documented Python example and confirm it authenticates and returns vehicle data without an SDK or API error.

### Failure Modes

- The Python client cannot install, authenticate, or complete the example request. — Recovery: Verify the runtime version, package installation, API-key environment variable, and endpoint inputs before rerunning the example.
<!-- farming-labs:agent-contract:end -->

Task: Install and use the carsxe Python SDK to call CarsXE API endpoints.
Related: /docs/sdks/python, /docs/get-started#quickstart, /docs/get-started#authentication

The `carsxe` package is the official CarsXE client for Python. It installs the `carsxe_api` module.

## Installation

```bash
pip install carsxe
# uv add carsxe
# poetry add carsxe
```

## Quick start

Construct the client with your API key. Every method is a coroutine, so `await` it (or run it with `asyncio.run`).

```python
import asyncio
from carsxe_api import CarsXE

carsxe = CarsXE("YOUR_API_KEY")

async def main():
    vehicle = await carsxe.specs({"vin": "WBAFR7C57CC811956"})
    print(vehicle)

asyncio.run(main())
```

## Methods

Each method is `async` and takes a single `dict` of parameters, returning the parsed JSON response.

| Method | Params | Description |
|---|---|---|
| `specs(params)` | `{"vin", "deepdata"?, "disableIntVINDecoding"?}` | Decode a VIN into full vehicle specifications |
| `int_vin_decoder(params)` | `{"vin"}` | Decode a non-US international VIN |
| `market_value(params)` | `{"vin", "state"?, "mileage"?, "condition"?}` | Retail, trade-in, and auction value estimates |
| `history(params)` | `{"vin"}` | Title events, salvage, and insurance records |
| `recalls(params)` | `{"vin"}` | Open safety recalls by VIN |
| `lien_and_theft(params)` | `{"vin"}` | Lien records and theft/salvage status |
| `plate_decoder(params)` | `{"plate", "state"?, "country"?, "district"?}` | Resolve a license plate to vehicle data (`country` defaults to `US`) |
| `images(params)` | `{"make", "model", "year"?, "trim"?, "color"?, "angle"?, "photoType"?, "size"?, "transparent"?, "license"?}` | Vehicle photos by make, model, and year |
| `plate_image_recognition(params)` | `{"upload_url"}` | Extract plate info from an image URL |
| `vin_ocr(params)` | `{"upload_url"}` | Extract VIN text from an image via OCR |
| `year_make_model(params)` | `{"year", "make", "model"}` | Look up vehicles by year, make, and model |
| `obd_codes_decoder(params)` | `{"code"}` | Decode an OBD-II diagnostic trouble code |

## Endpoint examples

Runnable examples for each method. All of them assume the `carsxe` client from [Quick start](#quick-start) and are driven with `asyncio.run(...)`.

### International VIN Decoder

```python
intvin = asyncio.run(carsxe.int_vin_decoder({"vin": "WF0MXXGBWM8R43240"}))
print(intvin)
```

### Market Value

```python
marketvalue = asyncio.run(carsxe.market_value({"vin": "WBAFR7C57CC811956"}))
print(marketvalue)
```

### Vehicle History

```python
history = asyncio.run(carsxe.history({"vin": "WBAFR7C57CC811956"}))
print(history)
```

### License Plate Decoder

```python
decoded_plate = asyncio.run(
    carsxe.plate_decoder({"plate": "7XER187", "state": "CA", "country": "US"})
)
print(decoded_plate)
```

### Vehicle Images

```python
images = asyncio.run(carsxe.images({"make": "BMW", "model": "X5", "year": "2019"}))
print(images)
```

### Vehicle Recalls

```python
recalls = asyncio.run(carsxe.recalls({"vin": "1C4JJXR64PW696340"}))
print(recalls)
```

### Plate Image Recognition

```python
plateimg = asyncio.run(
    carsxe.plate_image_recognition(
        {
            "upload_url": "https://imagedelivery.net/moyiiSImjJPI_EZVxNMBBw/f49aed53-d736-4370-f3f4-97418841c800/public"
        }
    )
)
print(plateimg)
```

### VIN OCR from Image

```python
vinocr = asyncio.run(
    carsxe.vin_ocr(
        {
            "upload_url": "https://imagedelivery.net/moyiiSImjJPI_EZVxNMBBw/f49aed53-d736-4370-f3f4-97418841c800/public"
        }
    )
)
print(vinocr)
```

### Year-Make-Model Search

```python
yymm = asyncio.run(
    carsxe.year_make_model({"year": "2012", "make": "BMW", "model": "5 Series"})
)
print(yymm)
```

### OBD Code Decoder

```python
obdcode = asyncio.run(carsxe.obd_codes_decoder({"code": "P0115"}))
print(obdcode)
```

### Lien and Theft

```python
lien_and_theft = asyncio.run(carsxe.lien_and_theft({"vin": "2C3CDXFG1FH762860"}))
print(lien_and_theft)
```

## Error handling

Methods return the parsed JSON response. Wrap calls in `try/except` to catch network and request errors:

```python
import asyncio
from carsxe_api import CarsXE

carsxe = CarsXE("YOUR_API_KEY")

async def main():
    try:
        vehicle = await carsxe.specs({"vin": "WBAFR7C57CC811956"})
        print(vehicle)
    except Exception as error:
        print(f"CarsXE error: {error}")

asyncio.run(main())
```

## Best practices

**Store your key in an environment variable.** Never hardcode it or commit it to source control.

```python
import os
from carsxe_api import CarsXE

carsxe = CarsXE(os.environ["CARSXE_API_KEY"])
```

```bash
# .env
CARSXE_API_KEY=your_key_here
```

**Every method is asynchronous.** Call them from within an `async` function and drive them with `asyncio.run(...)`, or `await` them directly inside an existing event loop (FastAPI, async workers, notebooks).

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
