Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x changes #67

Open
wants to merge 16 commits into
base: 1.x
Choose a base branch
from
Open

2.x changes #67

wants to merge 16 commits into from

Conversation

paul121
Copy link
Member

@paul121 paul121 commented Mar 21, 2024

This PR includes proposed (breaking) changes for a 2.x version of farmOS.py. Likely will not merge these changes here but into a new 2.x or main branch.

An overview:

  • 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:

This library has been restructured so it could be easier to create your own FarmClient class using a different library/transport instead of HTTPX but still leverage the Resource helper methods provided here.

@paul121
Copy link
Member Author

paul121 commented Mar 21, 2024

I still need to update documentation and fix some linting errors caused by async -> sync code generation. Existing code should only need to change how the client is instantiated and authorized, all other resource methods should continue to behave as before.

Before:

from farmOS import farmOS

farm = farmOS(
    hostname=FARMOS_HOSTNAME,
    scope="farm_manager",
    client_id="farm",
    version=2,
)
farm.authorize(USERNAME, PASSWORD)

After:

from httpx_auth import OAuth2ResourceOwnerPasswordCredentials
from farmOS import FarmClient

auth = OAuth2ResourceOwnerPasswordCredentials(
    token_url=f"{FARMOS_HOSTNAME}/oauth/token",
    username=USERNAME,
    password=PASSWORD,
    client_id="farm",
    scope="farm_manager",
)
farm = FarmClient(hostname=FARMOS_HOSTNAME, auth=auth)

@paul121
Copy link
Member Author

paul121 commented Mar 21, 2024

@symbioquine this async -> sync code generation is using the unasync approach implemented here: https://github.com/encode/httpcore/blob/master/scripts/unasync.py

Curious what you think. I know we had talked about async maybe "isn't worth it" but this is a pretty easy add and includes both sync and async tests (with automation to make sure async->sync changes are committed). I do think async is overkill for most use-cases but its nice to make it available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant