batch¶
This module provides a core batch retrieval engine for the Gmail API, enabling efficient fetching of multiple messages or threads in a single request to minimize HTTP overhead and improve performance.
- pythonic_gmail.batch.batch_get(gmail: GmailResource, method: Callable, ids: list[Any], id_arg_name: str, batch_size: int = 50, kwargs: dict[str, Any] | None = None)[source]¶
Core batch retrieval engine for Gmail API get methods.
Provides the underlying batch mechanism used by
batch_get_messages()andbatch_get_threads(). Groups multiple API calls into efficient batch requests to reduce HTTP overhead.- Parameters:
gmail – Gmail API client resource
method – Gmail API method that returns a Resource for execution
ids – List of IDs to retrieve (message IDs or thread IDs)
id_arg_name – Parameter name for the ID in the API method
batch_size – Number of items to fetch per batch request
kwargs – Additional parameters for the API call
- Returns:
List of retrieved objects from the API responses
- Examples:
Direct usage with messages get API:
messages = batch_get( gmail=gmail_client, method=gmail_client.users().messages().get, ids=["msg1", "msg2", "msg3"], id_arg_name="id", batch_size=2, kwargs={"userId": "me", "format": "minimal"} )
Direct usage with threads get API:
threads = batch_get( gmail=gmail_client, method=gmail_client.users().threads().get, ids=["thread1", "thread2", "thread3"], id_arg_name="id", batch_size=2, kwargs={"userId": "me", "format": "minimal"} )
Note
This is a low-level function. Most users should use
batch_get_messages()orbatch_get_threads()instead.Uses Gmail’s batch API for efficient retrieval. See the batch guide for more details.
See also
batch_get_messages()andbatch_get_threads()for high-level interfaces.