mgnipy.mgnipy module#

class MGnipy(config=None, interactive_auth=False, **config_kwargs)[source]#

Bases: ClientManagerMixin

MGnipy is a Python client for interacting with the MGnify API (https://www.ebi.ac.uk/metagenomics/api/v2/ ).

Provides methods to access different resources (e.g., studies, samples, analyses) and their details, as well as utility methods for listing resources and describing endpoints.

Parameters:
  • config (MGnipyConfig or dict , optional) – Configuration for MGnipy, either as an MGnipyConfig instance or a dictionary of configuration parameters (default is None).

  • interactive_auth (bool , optional) – Whether to prompt for authentication interactively if needed (default is False).

  • **config_kwargs – Additional keyword arguments to pass to the MGnipyConfig constructor if config is not provided. For example, cache_dir can be specified as a keyword argument. e.g. MGnipy(cache_dir=”/path/to/cache”)

Examples

>>> MG = MGnipy(cache_dir=None)  # or MGnipy(cache_dir="/path/to/cache")
>>> MG.cache_dir
async aclose()#
property async_httpx_client: AsyncClient#

Get the asynchronous httpx client instance from the AuthenticatedClient.

Returns:

The asynchronous httpx client instance.

Return type:

httpx.AsyncClient

clear_subcaches()[source]#

Clear the cache for a specific resource or all resources.

Parameters:

resource (str , optional) – The name of the resource to clear the cache for. If None, clears the cache for all resources (default is None).

Return type:

None

close()#
describe_resource(resource, as_dict=False)[source]#

Provides a description of the endpoint from the openapi documentation i.e., https://www.ebi.ac.uk/metagenomics/api/v2/openapi.json

Parameters:
  • resource (str ) – The name of the resource to describe.

  • as_dict (bool , optional) – Whether to return the description as a dictionary mapping parameter names to their descriptions (default is False).

Returns:

A dictionary mapping parameter names to their descriptions if as_dict is True, otherwise None.

Return type:

dict of str to str or None

describe_resources(resource=None, as_dict=False)[source]#

Provides a description of the endpoint from the openapi documentation i.e., https://www.ebi.ac.uk/metagenomics/api/v2/openapi.json

Parameters:
  • resource (str , optional) – The name of the resource to describe.

  • as_dict (bool , optional) – Whether to return the description as a dictionary mapping parameter names to their descriptions (default is False).

Returns:

A dictionary mapping parameter names to their descriptions if as_dict is True, otherwise None.

Return type:

dict of str to str or None

property httpx_client: Client#

Get the synchronous httpx client instance from the AuthenticatedClient.

Returns:

The synchronous httpx client instance.

Return type:

httpx.Client

list_resources()[source]#

List all supported resources (endpoints) from MGnify API that are supported by mgnipy.

renew_client()#

Init a new client instance and replace the existing one. This is useful if the current client has been closed or is no longer valid, allowing for a fresh start with a new HTTP client session.

status()#

Print the status of the MGnipy client, including the type of client and whether the synchronous and asynchronous httpx client sessions are open.

Return type:

None