Skip to main content

MGni.py

MGni.py (🔉IPA:'mæɡni-paɪ') is a lightweight python client and toolkit for the MGnify API v2.

PyPI cicd.yml GitHub Pages docs
Python 3.11 to 3.14 GitHub issues GitHub license GitHub last commit GitHub stars

mgnipy schematic

Contents

Features

  • FAIR: More findable MGnify analyses and metadata, returned in familiar metagenomics data formats (e.g., GFF, Darwin Core, Dataframes [pandas, polars, anndata])
  • Simplifies API interactions: Let MGni.Py handle the complexity of building, executing, and parsing API calls so you can focus on the data!
  • Fast: MGni.Py uses caching to speed up API expolation, as well as supports both sync and async API calls

Supported MGnify API resources

Installation

From PyPI

pip install mgnipy

Development installation

git clone https://github.com/EBI-Metagenomics/mgnipy.git
cd mgnipy
uv sync --all-groups  # or: pip install -e ".[dev,docs]"

Quick Start

🚀 1. Initialize mgnipy.MGnipy

from mgnipy import MGnipy

# Create the main client, with default configuration
mg = MGnipy()

# See available endpoints
mg.list_resources()

🔎 2. Search resources with a mgnipy.MGnifier

Building the query set

# Search for studies keyword
studies = mg.studies(
    search="disease"
)

# Can preview requests before fetching
studies.explain()

Executing the queries

# client context manager
with MG: 

    # get page by page via .get()
    studies.get()
    # or via .page(), getting a specific pg num 
    studies.page(2)
    # OR potentially all at once in large batches (also async option .aget_all())
    studies.get_all()

    # then can enrich list with detailed metadata
    studies.enrich_details()

Viewing the search results

# the mgnify list (without details)
study_list = studies.search_results
# detailed metadata, e.g. with enriched details
detailed_study_list = studies.metadata

# e.g. as dataframes
pl_metadata = detailed_study_metadata.to_polars()
pd_metadata = detailed_study_metadata.to_pandas()

# e.g. as json
json_metadata = detailed_study_metadata.to_json()

🗃️ 3. Explore a mgnipy.MGazine of datasets

# accessing the mgazine of datasets
mgazine = studies.datasets

# preview
print(mgazine)

Downloading datasets from MGnify

# download file by file 
mgazine.download(
    alias="mgnify_file_alias.fasta.gz", 
    to_dir="downloads_folder"
)

# or download all 
mgazine.download_all(to_dir="downloads_folder")

Reading in datasets from MGnify

# support for tsv, csv, txt, jsonl
taxa_table = mgazine.stream(
    alias="mgnify_file_alias.tsv", 
    df_engine="polars"
)

# support for fasta, gff, biom via skbio
skbio_fasta = mgazine.stream(alias="mgnify_file_alias.fasta.gz")

Additional Documentation

Development

see Contributing.md

License

This project is licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later). See the included LICENSE file for full terms.

Citation

If you use MGni.py in your work, please cite the software:

BibTeX:

@software{phanthanourak2026mgnipy,
  author  = {Phanthanourak, Angel L. and
             Shehu, Mahfouz and
             Atallah, Christian and
             Rogers, Alexander and
             Beracochea, Martin and
             Barranco-Altirriba, Maria and
             Ayala Ruano, Sebastian and
             Finn, Robert D. and
             Santos, Alberto},
  title   = {{MGni.py}: Harmonizing access to microbiome data and metadata from public repositories},
  year    = {2026},
  version = {0.3.0},
  url     = {https://github.com/EBI-Metagenomics/mgnipy}
}

Metadata

Release files for mgnipy 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mgnipy 0.4.0
File Size Uploaded Provenance Actions
mgnipy-0.4.0.tar.gz 40.5 MB With provenance Details for mgnipy-0.4.0.tar.gz

Release files / mgnipy-0.4.0.tar.gz

Download URL mgnipy-0.4.0.tar.gz
Size 40.5 MB
Tags Source
SHA-256 checksum
How to use checksums
1ee070342e9065deee7101d876876445e21059a7b1290bc8eb4a1d2387281c52
BLAKE2b-256 checksum
How to use checksums
87bae61620e0097ab71fa17510e5459e1976975559fe6020e3a1e7d2a39ef7cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for mgnipy 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for mgnipy-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page