-
Notifications
You must be signed in to change notification settings - Fork 18
Add async support for Dataverse SDK #171
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
base: main
Are you sure you want to change the base?
Changes from all commits
e7df299
a4f69cd
16084a1
c610af5
3113d45
9cb9d4a
c4d5614
774102a
170b550
836ca29
7a360c1
5c6bdc7
0d71bd3
255a798
f37b9b4
58fe82e
bd74d02
d738377
e4680f8
6c32c6b
e37fe4d
5fba6de
1a9d566
51e653f
d7310be
cb0d711
da41fcc
562e8b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
abelmilash-msft marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning ADO PR pipeline YAML change detected This PR modifies Action required (post-merge): Re-enable / approve the updated YAML for:
Please resolve this comment after completing the post-merge steps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning ADO PR pipeline YAML change detected This PR modifies Action required (post-merge): Re-enable / approve the updated YAML for:
Please resolve this comment after completing the post-merge steps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning ADO PR pipeline YAML change detected This PR modifies Action required (post-merge): Re-enable / approve the updated YAML for:
Please resolve this comment after completing the post-merge steps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning ADO PR pipeline YAML change detected This PR modifies Action required (post-merge): Re-enable / approve the updated YAML for:
Please resolve this comment after completing the post-merge steps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning ADO PR pipeline YAML change detected This PR modifies Action required (post-merge): Re-enable / approve the updated YAML for:
Please resolve this comment after completing the post-merge steps. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| """ | ||
| Async credential helper for the async example scripts. | ||
|
|
||
| azure-identity's InteractiveBrowserCredential is only available in the sync | ||
| namespace (azure.identity), not the async one (azure.identity.aio). This | ||
| module wraps the sync credential so it satisfies the AsyncTokenCredential | ||
| protocol required by AsyncDataverseClient. | ||
|
|
||
| Usage:: | ||
|
|
||
| from _auth import AsyncInteractiveBrowserCredential | ||
|
|
||
| credential = AsyncInteractiveBrowserCredential() | ||
| try: | ||
| async with AsyncDataverseClient(org_url, credential) as client: | ||
| ... | ||
| finally: | ||
| await credential.close() | ||
| """ | ||
|
|
||
| import asyncio | ||
| from concurrent.futures import ThreadPoolExecutor | ||
|
|
||
| from azure.identity import InteractiveBrowserCredential | ||
|
|
||
|
|
||
| class AsyncInteractiveBrowserCredential: | ||
| """ | ||
| Async wrapper around the sync InteractiveBrowserCredential. | ||
|
|
||
| get_token() is dispatched to a dedicated thread so the event loop stays | ||
| free during the browser popup / token exchange. Subsequent calls hit the | ||
| in-process token cache and return almost immediately. | ||
| """ | ||
|
|
||
| def __init__(self, **kwargs): | ||
| self._credential = InteractiveBrowserCredential(**kwargs) | ||
| self._executor = ThreadPoolExecutor(max_workers=1) | ||
|
|
||
| async def get_token(self, *scopes, **kwargs): | ||
| loop = asyncio.get_running_loop() | ||
| return await loop.run_in_executor( | ||
| self._executor, | ||
| lambda: self._credential.get_token(*scopes, **kwargs), | ||
| ) | ||
|
|
||
| async def close(self): | ||
| self._executor.shutdown(wait=False) | ||
|
|
||
| async def __aenter__(self): | ||
| return self | ||
|
|
||
| async def __aexit__(self, *_): | ||
| await self.close() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| """Advanced async examples showcasing complex Dataverse SDK features.""" |
Uh oh!
There was an error while loading. Please reload this page.