I disagree that people new to Python should first learn the Requests method of interacting with LM’s API. That’s like making people learn how to rebuild an internal combustion engine before being allowed to buy an electric car.
I had a similar experience when learning Python. I was trying to learn how to code robots for the Raspberry Pi. I took all their examples, learned all the long methods and studied how those methods perfectly aligned with the physical hardware in a very bare metal way. It was hard, but I was able to do what I needed to do. Then the gpiozero library came out, which is an SDK for the bare metal GPIO calls. Some of my code blocks went from 50-70 lines to two (2). Every time I built something new using gpiozero, I was astounded at how much more simple things were. I didn’t have to create a pulldown resistor object, then instantiate another object with that object and the pin object just so i could call it. I could just create an LED and pass it the pin number and voila, I had a working LED.
Just because the Requests method of interacting with the API exists doesn’t mean it’s the right way for everyone or even most people. Most people who are using LM aren’t full time developers. They’re infrastructure admins who don’t necessarily want to shift to being developers. They’re part time developers for whom the SDK is a great tool.
Consider the example I showed earlier, which is a complete working example of adding a website to LM:
from lm import lm
body = {
"testLocation": {"all": False,"smgIds": [2, 3, 4]},
"groupId": 1,
"description": "",
"type": "webcheck",
"isInternal": False,
"name": "google.com",
"domain": "google.com",
"schema": "https",
"steps": [{}],
"useDefaultAlertSetting": True
}
response = lm.add_website(body)
print(response)
This makes use of my lmwrapper library to simplify all your API interactions. The `from lm import lm` line imports the sdk, sets up the object, passes in your credentials (from a file you have stored outside the script because you should never put your credentials in the script), and otherwise gets everything ready to go. Body creates the definition you want to add and the lm.add_website() method adds it. This is the entirety of the script needed to add a website using the SDK.
Compare this to any script (even any of mine) that use the request library to interact with the API directly. Not only is the code longer, but there are steps in there that aren’t always understood and should never be coded more than once (that’s what imports are for).
Shorter code through the SDK is easier to read and understand what is going on.