mgnipy.V2.query_set module#

class mgnipy.V2.query_set.QuerySet(resource, *, config=None, params=None, **param_kwargs)[source]#

Bases: object

Builds and stores the current state of a query, including the resource type, parameters, and results.

Parameters:
  • resource (Literal ['biomes', 'biome', 'studies', 'study', 'samples', 'sample', 'runs', 'run', 'genomes', 'genome', 'analyses', 'analysis', 'assemblies', 'assembly'])

  • config (MGnipyConfig)

  • params (dict [str , Any ] | None)

property base_url: str #
property cache_dir: Path | None #
clear_cache()[source]#

Clear the cached results for the current resource and parameters. This will delete any cached files associated with the current query parameters.

config: MGnipyConfig#
count: int | None #
emgapi_handler: DescribeEmgapiModule#
property endpoint_module: Callable #
filter(**filters)[source]#

Update the parameters for the API call to filter results.

Parameters:

**filters – Keyword arguments corresponding to the supported parameters for the current resource. These will be used to filter the results returned by the API.

Returns:

A new QuerySet instance with updated parameters for filtering results.

Return type:

QuerySet

list_urls()[source]#

Generate and return a list of URLs for all the API requests that would be made to retrieve the data based on the current parameters. This allows the user to see exactly which endpoints and query parameters will be used in the API calls before executing them.

Returns:

A list of URLs corresponding to each API request that would be made.

Return type:

list of str

num_requests: int | None #
property params: dict [str , Any ]#
queries(**httpx_kwargs)[source]#

Generate a list of query parameter dictionaries for each API request that would be made based on the current parameters. This allows the user to see the specific query parameters for each request before executing them.

Returns:

A list of dictionaries, each containing the query parameters for a corresponding API request.

Return type:

list of dict

property records: chain | None #

Get an iterator of individual metadata records from the retrieved results, if available. This property provides a convenient way to access the metadata records without needing to handle pagination.

Returns:

An iterator that yields individual metadata records if results are available, otherwise None.

Return type:

chain or None

property request_url: str #

Get the URL for the API request based on the current resource and parameters. This is a single URL that represents the request for the current page of results.

Returns:

The constructed URL for the API request.

Return type:

str

property resource: SupportedEndpoints#
property results: dict [int , list [dict ]]#

Get the retrieved metadata results, if available. Results are stored in a dictionary with request number (e.g. page number) as keys.