Skip to main content

python driver for mgnipy 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 httpx with 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.
  • mgnipy.MGnipyConfig takes care of getting and caching the auth token so that you can easily access your private data using MGni.py :)

Installation

From PyPI (stable)

pip install mgnipy

From TestPyPI (development)

pip install mgnipy \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple

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_df = studies.to_df()

# As polars DataFrame
pl_df = studies.to_polars()

# as json
results_json = studies.to_json()

Additional Documentation

Development

see Contributing.md

License

TODO

Citation

TODO

Project details


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.0.tar.gz (374.0 kB view details)

Uploaded Source

File details

Details for the file mgnipy-0.1.0.tar.gz.

File metadata

  • Download URL: mgnipy-0.1.0.tar.gz
  • Upload date:
  • Size: 374.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mgnipy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 32b0a8b31079f54d1461e8dcdb24aaf50f2787ba72ea2f4a81422c6fe3406218
MD5 55756481600b9f64c87e5001e75dd0cf
BLAKE2b-256 e6bc757d5ab9232cadade9f8e1b5154e7db89817ab495392184eee112346eee8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgnipy-0.1.0.tar.gz:

Publisher: cicd.yml on EBI-Metagenomics/mgnipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page