Hi all - opening this topic to request some feedback on some changes + improvements to the farmOS.py library.
We’ve had this on our list for some time now. I actually opened a PR #67 with most of the implementation many months ago. I’ve just dusted this off today, made sure tests are still passing (yay!) and also updated documentation (including async docs - yay!).
There still are a few small things to do, but I think this is ready for a proper review now!
An overview of the proposed changes: (quoted from the PR #67)
- Remove support for farmOS v1
- Update to pydantic v2
- Use HTTPX for requests library
- Use HTTPX-Auth for OAuth2
- Expose async functions
- Auto-generate sync code from async code (and async tests!)
Using the HTTPX library gives us a few things:
- Pluggable authentication support #63 via the
auth
parameter- Most of Pluggable transport backend #64 via HTTPX async support
What is really great about these changes is that it should have very minimal impact on existing Python scripts using farmOS.py. All you need to change is how you instantiate the client
and configure authentication. The resource
helper methods all behave the same as before, largely thanks to how the HTTPX library’s request methods are nearly identical to Python Requests.
from httpx_auth import OAuth2ResourceOwnerPasswordCredentials
from farmOS import FarmClient
FARMOS_HOSTNAME="https://myfarm.farmos.net"
auth = OAuth2ResourceOwnerPasswordCredentials(
token_url=f"{FARMOS_HOSTNAME}/oauth/token",
username=USERNAME,
password=PASSWORD,
client_id="farm",
scope="farm_manager",
)
farm_client = FarmClient(hostname=FARMOS_HOSTNAME, auth=auth)