Package: dmr.py
dmr.pyYou will no longer need an exspensive API for danish license plate lookups with dmr.py, this tool scrapes thedanish vehicle registrydirectly 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 ContentsInstallationFrom PipFrom SourceExamplesSynchronous GetAsynchronous GetValidating License PlatesModels to dict/jsonUnit ConversionContributingIssue we can't do anything aboutLicense Plates for testingInstallationFrom Pippython -m pip install dmr.pyFrom SourceInstall current code from this repo, you will need to havegitinstalled 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.pyExamplesThe library is very easy to use, these two examples might be the only methods you need to know.Synchronous GetGet aVehicle objectsynchronously.fromdmrimportDMR# Import models directly if needed:fromdmr.modelsimport*license_plate="cw87553"# Get Vehicle object with datavehicle:Vehicle=DMR.get_by_plate(license_plate)print("The vehicle make is:",vehicle.make)# The vehicle make is: SuzukiAsynchronous GetGet aVehicle objectasynchronously.fromdmrimportDMRlicense_plate="cw87553"# Get Vehicle object with datavehicle=awaitDMR.get_by_plate_async(license_plate)print("The vehicle make is:",vehicle.make)# The vehicle make is: SuzukiValidating License PlatesThis 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.fromdmrimportDMRis_valid=DMR.validate_license_plate("cw87553")# Trueis_valid=DMR.validate_license_plate("Very Cool")# Falseis_valid=DMR.validate_license_plate("GGGGGGG")# TrueModels to dict/jsonThe model classes arePydantic BaseModelsor Enums. These are easily converted into a dict or a json string. I have listed 3 main methods of doing it.fromdmrimportDMR# Get Vehicle objectvehicle=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 wellvehicle.model_dump()# This is not recommeded, because the underlying Insurance object isn't parsed as a dictionary.dict(vehicle)Unit ConversionThe default units used in this library is metric. AConverterclass has been implemented, to make it easier to convert units to imperial and the other way around.fromdmrimportConverterrange_in_km=100range_in_miles=Converter.km_to_miles(range_in_km)print("Range in miles:",range_in_miles)# Range in miles: 62.14ContributingI 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 thedanish 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 inthis file.ToDoAdd 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 aboutIf 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 ishighlyrecommended!License Plates for testingThis is a collectoin of license plates that you can use for testing.You can find the listhere. Most of the license plates in this file should be valid.