MGni.py: A Python Wrapper for the MGnify API
Project description
MGni.py
MGni.py (pronounced MAG-nee-pie) is a Python wrapper for the MGnify API. It provides a high-level, Pythonic interface to query metagenomics data and metadata from the MGnify database.
Features
- Simple, Pythonic API — Query MGnify studies, samples, analyses, etc. using an intuitive syntax
- Sync and Async support — Built on
httpxwith async/await support - Data export — Multiple output formats including pandas and polars DataFrames
- Caching — Option for disk caching to reduce redundant API calls and allow resuming
Available API Endpoints
- Studies: MGnify studies (collections of samples, runs, assemblies and analyses derived from ENA studies/projects).
- Samples: MGnify samples (based on ENA/BioSamples; individual biological samples).
- Runs: Sequencing runs (ENA run accessions; individual sequencing runs of a sample).
- Assemblies: Metagenome assemblies (equivalent to ENA assemblies for one or more runs).
- Analyses: Pipeline analyses (results of running MGnify pipelines on runs or assemblies; includes taxonomic and functional annotations).
- Publications: Publications that describe or analyse MGnify Studies/datasets.
- Genomes: Annotated draft genomes (isolates or MAGs) arranged in biome-specific catalogues.
- Biomes: List all biomes in the MGnify database.
Note on private data:
- To access your private data in any of these API endpoints you just need your MGnify user and password to obtain a valid sliding auth token via the MGnify Authentication endpoints.
- for example you can put your login credentials in a
.envfile in your working directory (see .env.example) and mgnipy.MGnipyConfigtakes care of getting and caching the auth token so that you can easily access your private data using MGni.py 🎉
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
Initialize and explore
from mgnipy import MGnipy
# Create the main client, with default configuration
mg = MGnipy()
# See available endpoints
mg.list_resources()
Query resources with filtering
# Search for studies keyword
studies = mg.studies(
search="disease"
)
# Can preview requests before fetching
studies.explain()
# get page by page via .get(), getting 3 pages
for _ in range(3)
studies.get()
# or via .page(), getting another 3 pages
for i in range(4,7):
studies.page(i)
# OR potentially all at once in large batches (also async option .abulk_fetch())
studies.bulk_fetch()
Multiple output formats
pd_metadata = studies.to_df()
# As polars DataFrame
pl_metadata = studies.to_polars()
# as json
json_metadata = studies.to_json()
Downloading the analyzed data
# accessing the mgazine of datasets
mgazine = studies.datasets
# preview
print(mgazine)
# download file by file
mgazine.download(to_dir="downloads_folder", alias="mgnify_file_alias.fasta.gz")
# or download all
mgazine.download_all(to_dir="downloads_folder")
Additional Documentation
Development
see Contributing.md
License
TODO
Citation
TODO
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mgnipy-0.1.1.tar.gz
(467.4 kB
view details)
File details
Details for the file mgnipy-0.1.1.tar.gz.
File metadata
- Download URL: mgnipy-0.1.1.tar.gz
- Upload date:
- Size: 467.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1e508b23b7be8848a3ee829f1f8ae20837874f3204ce04a6d9f9fdd75c69371
|
|
| MD5 |
b8b6f949198d3a497c858d70a58c22fa
|
|
| BLAKE2b-256 |
65ab3e74b195650d711626b651fa71054260cb66d202a765b91e07ed3a97d2b7
|
Provenance
The following attestation bundles were made for mgnipy-0.1.1.tar.gz:
Publisher:
cicd.yml on EBI-Metagenomics/mgnipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mgnipy-0.1.1.tar.gz -
Subject digest:
f1e508b23b7be8848a3ee829f1f8ae20837874f3204ce04a6d9f9fdd75c69371 - Sigstore transparency entry: 1573285827
- Sigstore integration time:
-
Permalink:
EBI-Metagenomics/mgnipy@871b2ae497cf163f0df6f5bf7d27496ec9a95d72 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/EBI-Metagenomics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cicd.yml@871b2ae497cf163f0df6f5bf7d27496ec9a95d72 -
Trigger Event:
push
-
Statement type: