Skip to content

Hochfrequenz/malo-ident-python-models

Repository files navigation

MaLo Ident Python Models

License: MIT Python Versions (officially) supported Pypi status badge Unittests status badge Coverage status badge Linting status badge Black status badge

This package provides mostly autogenerated pydantic-based model classes for the MaLo ident API.

We also maintain a C#/.NET Version of this data model.

It does not provide you with an HTTP client.

Installation

Install it from PyPI

pip install maloident

Then use it:

from maloident.models import ResultNegative
my_json = {
    "decisionTree": "E_0594",
    "responseCode": "A10",
    "reason": "Ich bin ein Freitext.",
    "networkOperator": 9900987654321,
}
result = ResultNegative.model_validate(my_json)

The request payload type for the Lieferant➡️Netzbetreiber identification request is maloident.models.IdentificationParameter.

See the tests for more examples.

Project Structure

This project is based on datamodel-code-generator. Most of the classes are autogenerated from the openapi.yml which can be found on SwaggerHub.

Note that we fixed some errors in the official OpenAPI spec. Our changes are mentioned at the beginning of the openapi.yml file.

# 1. The enum 'marketLocationProperty':
# a) It's missing the 'measured' valued which is given as example but not part of the enum members.
# b) there is a typo: 'nonActice' should be 'nonActive'
# 2. Some yaml parsers fail, because: Multi-line double-quoted strings are not sufficiently indented (can be found with prettier in CI)
# 3. Datetimes are poorly designed. Instead of using the OpenAPI format:date-time, a regex with good intentions is used. This leads to code-generators using type string instead of datetime.
# 4. 'format: UUID RFC4122' may not be recognized but is valid: "Formats such as "email", "uuid", and so on, MAY be used even though undefined by this specification".
# 5. Typing the marketPartnerId as integer is a poor decision. For better compatability, we added the `format: int64`, so that the 13digit values fit (and they don't fit in 32bit).

After updating the openapi.yml file, use

tox -e codegen

to re-generate the model classes.

Contribute

You are very welcome to contribute to this template repository by opening a pull request against the main branch.