farmOS / farmOS.py

A Python library for interacting with farmOS over API.
GNU General Public License v3.0
27 stars 12 forks source link

Add models for farmOS record types #25

Open paul121 opened 4 years ago

paul121 commented 4 years ago

There's been some discussion about how it would be useful to have models for creating and validating farmOS records. I think this library would be a great place to provide such models for Python, and would allow us to do it in a very "pythonic" way.

Models could be stored under a farmOS.models module and be imported like from farmOS.models import log, area, asset

I'd like to propose we use pydantic for this - https://pydantic-docs.helpmanual.io/. Basically, this library allows you to define models which are classes that inherit from the pydantic BaseModel class which already has a bunch of properties and features built in. You can easily create objects from the models you define, and pass them around as if they were types in a strictly typed language.

Another benefit is that the farmOS-aggregator could use these models to further document it's auto-generated OpenAPI schema. Other tools such as SQLAlchemy have support for pydantic models as well. I'm sure there are lots of other benefits.