Skip to content

Support for async/await #630

Closed
Closed

Description

@aersam

Would be nice to be able to use python's async/await Story for execute_query

Activity

  1. added
    v3milestone label for issues resolved by the upcoming release
    on May 26, 2026
  2. added this to the v3.2.0 milestone on Sep 13, 2026
  3. office365-maintainer commented on Oct 18, 2026

    @office365-maintainer

    Shipped in 3.3.0 — closing this one.

    The scope, precisely: offloaded by default, native async opt-in. await no longer blocks the event loop — the blocking transport call is offloaded to a bounded worker pool (with contextvars carried over) — and if you want zero threads, the [httpx] extra provides a native async transport that the async path uses while the synchronous path keeps its own.

    What you get, all inherited by every generated entity (SharePoint v1/v2 and Graph), because the entry points live on the runtime base classes:

    • execute_query_async, execute_query_async_retry, execute_query_parallel_async (bounded concurrency, per-query retry honouring Retry-After, optional progress hook and on_error collector), execute_batch_async, get_all_async, export_to_async, retry_async, async beforeExecute, RateLimiter.acquire_async.
    • Cancellation: cancelling the awaiting task aborts in-flight siblings and re-queues the queries that were not applied.
    • Streaming and LRO: HttpxTransport.stream_async, File.download_session_async, DriveItem.resumable_upload_async, and awaitable OperationPoller / PollableOperation / MigrationServerJob.monitor_async.
    import asyncio
    
    from office365.sharepoint.client_context import ClientContext
    
    SITE = "https://contoso.sharepoint.com/sites/team"
    
    
    async def main() -> None:
        ctx = ClientContext(SITE).with_client_credentials(client_id, client_secret)  # any existing auth helper
    
        web = ctx.web.get()
        await ctx.execute_query_async()
        print(web.title)
    
        targets = [ctx.web.lists.get_by_title(name) for name in ("Documents", "SitePages", "Tasks")]
        for target in targets:
            target.get()                                          # queue, send nothing yet
        await ctx.execute_query_parallel_async(concurrency=4)      # three round-trips overlapping
        print([(t.title, t.item_count) for t in targets])
    
    
    asyncio.run(main())

    Zero threads (pip install office365-rest-python-client[httpx]):

    from office365.runtime.transport.httpx_transport import HttpxTransport
    
    ctx.pending_request().with_async_transport(HttpxTransport())

    Docs: docs/async.md, runnable examples in examples/patterns/async/, release notes: 3.3.0.

  4. Repository owner deleted a comment from office365-maintainer on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement requestv3milestone label for issues resolved by the upcoming release

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions