Skip to main content

Pull data directly from the danish vehicle register with dmr.py

Project description

PyPI - Python Version PyPI PyPI - Downloads
GitHub BuyMeACoffee

dmr.py

You will no longer need an exspensive API for danish license plate lookups with dmr.py, this tool scrapes the danish vehicle registry directly and returns the data for you to use in your application. Be aware, that because of skat.dk's very slow database lookups, it could take about 3-4 seconds before getting a response.

Table of Contents

Installation

From Pip

python -m pip install dmr.py

From Source

Install current code from this repo, you will need to have git installed in order to do this. The code in the repo might not match the current release, if you experience errors you should switch back the the latest release.

python -m pip install git+https://github.com/j4asper/dmr.py

Examples

The library is very easy to use, these two examples might be the only methods you need to know.

Synchronous Get

Get a Vehicle object synchronously.

from dmr import DMR
# Import models directly if needed:
from dmr.models import *

license_plate = "cw87553"

# Get Vehicle object with data
vehicle: Vehicle = DMR.get_by_plate(license_plate)

print("The vehicle make is:", vehicle.make)
# The vehicle make is: Suzuki

Asynchronous Get

Get a Vehicle object asynchronously.

from dmr import DMR

license_plate = "cw87553"

# Get Vehicle object with data
vehicle = await DMR.get_by_plate_async(license_plate)

print("The vehicle make is:", vehicle.make)
# The vehicle make is: Suzuki

Validating License Plates

This is the easiest way to check if a license plate is in a valid format. This will only check if the format is valid, not if the license plate actually exists. This check is also used when using the get_by_plate() method.

from dmr import DMR

is_valid = DMR.validate_license_plate("cw87553")
# True

is_valid = DMR.validate_license_plate("Very Cool")
# False

is_valid = DMR.validate_license_plate("GGGGGGG")
# True

Models to dict/json

The model classes are Pydantic BaseModels or Enums. These are easily converted into a dict or a json string. I have listed 3 main methods of doing it.

from dmr import DMR

# Get Vehicle object
vehicle = DMR.get_by_plate("cw87553")


# If you want your model as a JSON string, this is the method to use. This is the equivalent of using json.dumps() on a dictionary.
vehicle.model_dump_json()

# Preferred method to use if you want sub models to be made into dicts as well
vehicle.model_dump()

# This is not recommeded, because the underlying Insurance object isn't parsed as a dictionary.
dict(vehicle)

Unit Conversion

The default units used in this library is metric. A Converter class has been implemented, to make it easier to convert units to imperial and the other way around.

from dmr import Converter

range_in_km = 100

range_in_miles = Converter.km_to_miles(range_in_km)

print("Range in miles:", range_in_miles)
# Range in miles: 62.14

Contributing

I would be more than happy if those who know how to make pull requests, contribute with code! Sometimes XPaths may not match with the ones on the danish vehicle registry, if that's the case, then you can either make a pull request with XPath fixes or make an issue saying that the XPaths are wrong, then I will fix it. XPaths are kept in this file.

ToDo

  • Add documentation with all possible values.
  • Scrape more parts of the DMR site to get even more data.
  • Add more broad tests with different types of cars or bikes.

Issue we can't do anything about

If you have used this tool, you might notice that it's very slow. That is probably due to our government using multiple 80-100 GB XML files as the databse for all vehicles in Denmark. It roughly takes about 3 seconds to do a lookup on the DMR site. Caching is highly recommended!

License Plates for testing

This is a collectoin of license plates that you can use for testing.

You can find the list here. Most of the license plates in this file should be valid.

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

dmr_py-1.1.3.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

dmr.py-1.1.3-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file dmr_py-1.1.3.tar.gz.

File metadata

  • Download URL: dmr_py-1.1.3.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for dmr_py-1.1.3.tar.gz
Algorithm Hash digest
SHA256 dcaa66d40324f644b5feddda7c1e91114ca53155c147a7a24916f0cc82d7adca
MD5 a90b91f103aeac6a13521f33b0ee42a4
BLAKE2b-256 6c11f62955f26aeef6571197d3d02900565b8b616c30a8c4e1029e8e8e1d861d

See more details on using hashes here.

File details

Details for the file dmr.py-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: dmr.py-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for dmr.py-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e21cc3b8e206bba14e25439f3de90b89d1252b59251ada50f8685a5cbe387ead
MD5 2d93ebb5336aae194ee6f2b66d556313
BLAKE2b-256 a0538ecfc492fe817aa8fd99779e688613188b48f0214bea8f690f948b4c9b6f

See more details on using hashes here.

Supported by

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