mgnipy.V2.query_executor module#
- class mgnipy.V2.query_executor.QueryExecutor(query_set)[source]#
Bases:
object- Parameters:
query_set (QuerySet)
- async abulk_fetch(limit=1000, *, pages=None, safety=False, hide_progress=False)[source]#
Fetch pages in bulk asynchronously.
Example
>>> # Async bulk fetch (doctest skipped) >>> executor = QueryExecutor(qs) >>> import asyncio >>> asyncio.run(executor.abulk_fetch(limit=50))
- async afirst()[source]#
Asynchronously retrieve the first page of metadata for the current resource and parameters. Same as preview() but returns the raw dictionary instead of a DataFrame.
- Return type:
- async aget()[source]#
Async alternative to fetch the next page.
- Return type:
The next page dict or
Nonewhen iteration is complete.
Example
>>> # Async fetch via helper (doctest skipped) >>> import asyncio >>> executor = QueryExecutor(qs) >>> asyncio.run(executor.aget())
- async apage(page_num, client=None)[source]#
Async fetch for a single page.
Example
>>> import asyncio >>> executor = QueryExecutor(qs) >>> asyncio.run(executor.apage(1))
- bulk_fetch(limit=1000, *, pages=None, safety=False, hide_progress=False)[source]#
Fetch pages in bulk synchronously.
Example
>>> # Bulk fetch usage (doctest skipped) >>> executor = QueryExecutor(qs) >>> executor.bulk_fetch(limit=50)
- continue_iterator(start_page=None)[source]#
Continue iterating from a given page or next batch after pages_limit
For resuming after hitting the page limit
- Parameters:
start_page (int , optional) – The page number to start from. If None, starts from the next page after the current limit.
Examples
>>> # Continue from a specific page >>> executor = QueryExecutor(qs) >>> executor.continue_iterator(start_page=50) >>> # Continue from next batch after previous pages >>> executor.continue_iterator()
- first()[source]#
Retrieve the first page of metadata for the current resource and parameters. Same as preview() but returns the raw dictionary instead of a DataFrame.
- Return type:
- get()[source]#
Alternative to getting the next page of results.
- Return type:
The next page dict or
Nonewhen iteration is complete.
Example
>>> # Fetch next page via helper (doctest skipped) >>> executor = QueryExecutor(qs) >>> executor.get()
- async map_with_concurrency(items, worker, hide_progress=False)[source]#
Map a worker function over a list of items with controlled concurrency. In plain English, it is a “process these things in parallel, but not too many at once” helper.
Example
>>> # Map worker over pages with concurrency (doctest skipped) >>> executor = QueryExecutor(qs) >>> pages = [1,2,3] >>> results = await executor.map_with_concurrency( ... items=pages, ... worker=lambda p: executor.apage(p), ... )
- Parameters:
hide_progress (bool )
- page(page_num, client=None)[source]#
Retrieve a specific page of metadata for the current resource and parameters. This method allows the user to retrieve metadata one page at a time, which can be useful for previewing data or for manual pagination control.
- Parameters:
- Returns:
A dictionary containing the metadata from the specified page of results, or None if the page is not found.
- Return type:
Examples
>>> # Fetch a single page (doctest skipped) >>> executor = QueryExecutor(qs) >>> executor.page(1)
- property progress#
- reset_iterator()[source]#
Reset the iterator to start from the beginning.
Example
>>> executor = QueryExecutor(qs) >>> executor.reset_iterator()