Make the 51Did client asynchronous with no synchronous form - #78
Merged
Conversation
Every method that reaches the cloud is now a coroutine and the synchronous forms are removed. This is one of a set of changes making every 51Did client and every OWID port asynchronous where the network is involved, so the libraries behave the same way in every language. The injectable transport is now an async callable with the same request in, status and body out shape it had before, so a test stub changes only by becoming a coroutine. The default wraps the standard library's urllib on a worker thread through asyncio.to_thread, which the documentation says plainly, pointing at aiohttp or httpx for a fully non-blocking one. No dependency was added and the supported Python version is unchanged. The key cache now holds the in-flight fetch, so concurrent callers waiting on one key list make a single request.
# Conflicts: # fiftyone_pipeline_did/tests/test_did_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Every method on
DidClientthat reaches the cloud is now a coroutine, and the synchronous forms are removed outright. This is one of a set of changes making every 51Did client and every OWID port asynchronous where the network is involved, so the libraries behave the same way in every language.Methods that never touch the network are unchanged, so
endpoint,resource_key,has_licence_key, the parsing helpers and the key selection helpers all stay synchronous.Removed
def public_keys(self) -> List[PublicKeyEntry]def public_key_for(self, fod_id) -> Optional[PublicKeyEntry]def verify_signature(self, fod_id) -> booldef verify_signature_detailed(self, fod_id) -> SignatureCheckdef verify(self, fod_id) -> booldef redeem(self, fod_id, result, ...) -> RedeemResultNew
The same six with the same names, arguments and return types, as
async def. The transport type changes with them.The default transport wraps the existing urllib call on a worker thread through
asyncio.to_thread, so it is not fully non-blocking. The module documentation says so and points at aiohttp or httpx for a transport that is. No dependency was added and the supported Python version is unchanged.Kept exactly
The two step verification, the licence key handling, the redeem outcome types, key selection by the latest start at or before the date, and the 401 handling, all as the tests pin them. The key cache now also holds the in-flight fetch, so concurrent callers waiting on one key list make a single request.
The example server and the package documentation were converted with the client, and there are no callers of the removed methods anywhere else in the repository.
Verification
pytestover the package with the owid submodule on the path: 150 passed, 2 skipped. New tests cover two concurrent key list requests making one HTTP call, and concurrent selections past the newest start sharing one fetch.This client does not use the OWID library's fetch, only its cryptography, so it does not wait on the OWID asynchronous work in SWAN-community.
Notes
Written with AI assistance and reviewed before merging.