Skip to main content

KG-Hub Downloader

| Documentation | Repository | PyPI |

Overview

This is a configuration based file caching downloader with initial support for http requests & queries against elasticsearch.

Installation

KGHub Downloader is available to install via pip:

pip install kghub-downloader

Configure

The downloader requires a YAML file which contains a list of target URLs to download, and local names to save those downloads.
For an example, see example/download.yaml

Available options are:

  • *url: The URL to download from. Currently supported:

    • http(s)
    • ftp
      • with glob: option to download files with specific extensions (only with ftp as of now and looks recursively).
    • Google Cloud Storage (gs://)
    • Google Drive (gdrive:// or https://drive.google.com/...). The file must be publicly accessible.
    • Amazon AWS S3 bucket (s3://)
    • GitHub Release Assets (git://RepositoryOwner/RepositoryName)

    If the URL includes a name in {CURLY_BRACES}, it will be expanded from environment variables.

  • glob: An optional glob pattern to limit downloading files (FTP only)

  • local_name: The name to save the file as locally

  • tag: A tag to use to filter downloads

  • api: The API to use to download the file. Currently supported: elasticsearch

  • elastic search options

    • query_file: The file containing the query to run against the index
    • index: The elastic search index for query

* Note:
Google Cloud Storage URLs require that you have set up your credentials as described here. You must:

Mirorring local files to Amazon AWS S3 bucket requires the following:

You can also include any secrets like API keys you have set as environment variables using {VARIABLE_NAME}, for example:

---
- url: "https://example.com/myfancyfile.json?key={YOUR_SECRET}"
  localname: myfancyfile.json

Note: YOUR_SECRET MUST as an environment variable, and be sure to include the {curly braces} in the url string.

Usage

Downloader can be used directly in Python or via command line

In Python

from kghub_downloader.download_utils import download_from_yaml

report = download_from_yaml(yaml_file="download.yaml", output_dir="data")

# The returned DownloadReport lists the absolute path of each file that was
# downloaded this run, skipped (already present, served from cache), or
# failed (populated when fail_on_error is False)
if report.any_downloaded:
    print(f"Downloaded {len(report.downloaded)} files, skipped {len(report.skipped)}")

Command Line

To download files listed in a download.yaml file:

$ downloader [OPTIONS] [YAML_FILE]

Arguments:

  • [YAML_FILE]: List of files to download in YAML format [default: download.yaml]

Options:

  • --output-dir TEXT: Path to output directory [default: .]
  • --ignore-cache / --no-ignore-cache: Ignoring already downloaded files and download again [default: no-ignore-cache]
  • --progress / --no-progress: Show progress for individual downloads [default: progress]
  • --fail-on-error / --no-fail-on-error: Do not attempt to download more files if one raises an error [default: no-fail-on-error]
  • --snippet-only / --no-snippet-only: Only download a snippet of the file. [HTTP(S) resources only. [default: no-snippet-only]
  • --verbose / --no-verbose: Show verbose output [default: no-verbose]
  • --tags TEXT: Optional list of tags to limit downloading to
  • --mirror TEXT: Optional remote storage URL to mirror download to. Supported buckets: Google Cloud Storage

Examples:

$ downloader --output_dir example_output --tags zfin_gene_to_phenotype example.yaml
$ downloader --output_dir example_output --mirror gs://your-bucket/desired/directory

# Note that if your YAML file is named `download.yaml`,
# the argument can be omitted from the CLI call.
$ downloader --output_dir example_output

Development

Install

git clone https://github.com/monarch-initiative/kghub-downloader.git
cd kghub-downloader
poetry install

Run tests

poetry run pytest

NOTE: The tests require gcloud credentials to be set up as described above, using the Monarch github actions service account.

Metadata

Release files for kghub-downloader 0.5.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 kghub-downloader 0.5.0
File Size Uploaded
kghub_downloader-0.5.0.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kghub-downloader 0.5.0
File Interpreter ABI Platform
kghub_downloader-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.8 kB

Release files / kghub_downloader-0.5.0.tar.gz

Download URL kghub_downloader-0.5.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c4f38a6f50e57354416c2151de6582fc16cc91144c6312071771a6a3bf953fef
BLAKE2b-256 checksum
How to use checksums
a862dd24f935470bdbd6dd2b5df2362c1bae0e53dc55202c6dbfba35fe848653
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / kghub_downloader-0.5.0-py3-none-any.whl

Download URL kghub_downloader-0.5.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a34b207cd1b826b8982dfc99b013006a17259280cb9f176c56594a7d92e1f0bd
BLAKE2b-256 checksum
How to use checksums
5df8650fedf75cf16ef29c9b6ecf51e340c0b1438d6a9e62d8066e2a939eca78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8
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