Skip to main content

Python SDK for DVSA MOT History API

Project description

DVSA MOT History Python SDK

GitHub Actions Workflow Status PyPI - Python Versions PyPI - Version

dvsa_mot_history is a Python SDK that provides a simple interface for interacting with the DVSA MOT History API, allowing retrieval of MOT history, test results, and bulk downloads for vehicles registered with DVSA, DVA Northern Ireland, or the Commercial Vehicle Service.

Features

  • Retrieve Vehicle MOT History by Registration: Fetch detailed MOT history using a vehicle's registration number.
  • Retrieve Vehicle MOT History by VIN: Fetch detailed MOT history using a vehicle's VIN.
  • Bulk Download of MOT History Data: Retrieve bulk MOT history data files for further processing.

Installation

Install the package using pip:

pip install dvsa_mot_history

Usage

Initialisation

To use the MOTHistory class, you'll need the client_id, client_secret, tenant_id, and api_key credentials provided by the DVSA API service.

from dvsa_mot_history import MOTHistory

mot_history = MOTHistory(
    client_id="your-client-id",
    client_secret="your-client-secret",
    tenant_id="your-tenant-id",
    api_key="your-api-key"
)

Fetch MOT History by Registration

To fetch MOT history for a vehicle using its registration number:

import asyncio
from dvsa_mot_history.errors import VehicleHistoryError

async def get_mot_history_by_registration():
    try:
        response = await mot_history.get_vehicle_history_by_registration("AB12CDE")
        print(f"Vehicle: {response.make} {response.model}")
        for test in response.motTests:
            print(f"Test Date: {test.completedDate}, Result: {test.testResult}")
    except VehicleHistoryError as e:
        print(f"Error: {e.message}")

asyncio.run(get_mot_history_by_registration())

Fetch MOT History by VIN

To fetch MOT history for a vehicle using its VIN:

async def get_mot_history_by_vin():
    try:
        response = await mot_history.get_vehicle_history_by_vin("12345678901234567")
        print(f"Vehicle: {response.make} {response.model}")
        for test in response.motTests:
            print(f"Test Date: {test.completedDate}, Result: {test.testResult}")
    except VehicleHistoryError as e:
        print(f"Error: {e.message}")

asyncio.run(get_mot_history_by_vin())

Bulk Download of MOT History Data

To download bulk MOT history data:

async def download_bulk_mot_history():
    try:
        response = await mot_history.get_bulk_download()
        for file in response.bulk:
            print(f"Bulk File: {file.filename}, URL: {file.downloadUrl}")
        for file in response.delta:
            print(f"Delta File: {file.filename}, URL: {file.downloadUrl}")
    except VehicleHistoryError as e:
        print(f"Error: {e.message}")

asyncio.run(download_bulk_mot_history())

Classes and Data Structures

MOT Test Classes

  • DVSAMotTest
  • DVANIMotTest
  • CVSMotTest

These classes represent the MOT test results from their respective agencies, containing details such as the test result, odometer readings, defects, and more.

MotTestType: This is a type alias that encompasses the possible MOT test classes detailed above.

Vehicle Response Classes

  • VehicleWithMotResponse
  • NewRegVehicleResponse

These classes encapsulate vehicle information, including the make, model, registration details, and a list of MOT tests.

VehicleResponseType: This is a type alias that encompasses the possible vehicle response classes detailed above.

Error Handling

The VehicleHistoryError exception class handles errors returned by the API, providing details about the error, including the status code and message. The previous ErrorResponse class has been removed, and error handling is now done through exceptions.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dvsa_mot_history-1.0.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dvsa_mot_history-1.0.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file dvsa_mot_history-1.0.1.tar.gz.

File metadata

  • Download URL: dvsa_mot_history-1.0.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for dvsa_mot_history-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9b7532a09e61d6f3b2a24696b632a213081b9dbae19825f86a3fd59aa06b4de4
MD5 ed31cf81176f1ed88d09db935f91af9e
BLAKE2b-256 2e407d73d92f1e064c11e65284859ed4e99ef4cffa673e284fda76e73b0093b1

See more details on using hashes here.

File details

Details for the file dvsa_mot_history-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dvsa_mot_history-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3040104a4d1e5b818024b9a7010d442495422d5dc1517277813b7b3592b4a343
MD5 5a6f1da6799c8c0282a246b264ffc2f5
BLAKE2b-256 7b2b2f779232ac79b66e096a7d55d41d471ee093a1f76d72b44c2206afbf316f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page