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 project:

MGnipy contributors (2026). MGni.py: a lightweight Python client and toolkit for the MGnify API. Version 0.2.1. https://github.com/EBI-Metagenomics/mgnipy

BibTeX:

@software{mgnipy2026,
  author = {MGnipy contributors},
  title = {MGni.py: a lightweight Python client and toolkit for the MGnify API},
  year = {2026},
  version = {0.2.1},
  url = {https://github.com/EBI-Metagenomics/mgnipy}
}

Metadata

Release files for mgnipy 0.3.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.3.0
File Size Uploaded
mgnipy-0.3.0.tar.gz 40.3 MB Details

Release files / mgnipy-0.3.0.tar.gz

Download URL mgnipy-0.3.0.tar.gz
Size 40.3 MB
Tags Source
SHA-256 checksum
How to use checksums
fe168a4ad47747d00edf3d0c5c3ce924f0088632fb3da0e72fe71ec09668ca39
BLAKE2b-256 checksum
How to use checksums
d01f8ebfd20bc4c07d7d7af371089fcb407ce3980762c9300b5ab368742bfb54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.1

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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