mgnipy.V2.mgnifier.query_set module#

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

Bases: object

Query Builder and State Manager for MGnify API interactions.

Builds a set of .build_queries() that represent the API calls to be made based on the current resource (API endpoint) and parameters.

Stores the current state of the query set (including the resource type, parameters) and any results.

Parameters:
  • resource (str ) – The type of resource to query (e.g., “studies”, “samples”, “runs”, etc.).

  • config (MGnipyConfig, optional) – Configuration object for MGnipy, including settings like base URL and authentication.

  • params (dict , optional) – A dictionary of parameters to include in the API request. These will be used to filter results.

  • **param_kwargs – Additional keyword arguments that will be merged into the params dictionary. These provide a convenient way to specify parameters directly when initializing the QuerySet.

resource#

The type of resource being queried, represented as an instance of SupportedEndpoints.

Type:

SupportedEndpoints

base_url#

The base URL for the API, derived from the configuration.

Type:

str

config#

The configuration for MGnipy, including settings like base URL and authentication.

Type:

MGnipyConfig

count#

The total number of results for the query.

Type:

Optional[int ]

num_requests#

The number of API requests made for the query.

Type:

Optional[int ]

results#

The results of the API requests, stored by page number.

Type:

dict [int , list [dict ]]

params#

The parameters for the API request.

Type:

dict [str , Any]

emgapi_handler#

The handler for interacting with the EMGAPI module.

Type:

DescribeEmgapiModule

filter(**filters) QuerySet[source]#

Return a new QuerySet instance with updated parameters for filtering results.

Return type:

QuerySet

list_urls() list [str ][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.

Return type:

list [str ]

queries(**httpx_kwargs) list [dict [str , Any]]#

Generate a list of query parameter dictionaries for each API request that would be made based on the current parameters.

property base_url: str #

The base URL for the API, derived from the configuration.

build_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

config: MGnipyConfig#
property count: int | None #
emgapi_handler: DescribeEmgapiModule#
property endpoint_module: ModuleType #
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

property num_requests: int | None #
property params: dict [str , Any ]#

Get the current parameters for the API request. These parameters are used to filter results and construct the request URL.

property request_url: str #
  • Get the request URL to API 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#

The type of resource being queried, represented as an instance of 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.