Skip to main content

Find, download, and build versioned assets

Project description

File Fetcher

Purpose

Many bioinformatics pipeline tasks rely on large data files, often pre-processed in such a way as to support fast lookups. To make libraries re-usable, it should be easy to create the files programmatically, and to download pre-made versions from a remote server. (rather than spending hours generating data structures on first install).

Additionally, it should be possible to get the newest versions based on some automated server process.

This library abstracts the tasks of locating, downloading, or creating the necessary pieces, as appropriate.

Usage

from filefetcher import AssetCLI, AssetManager
from filefetcher.exceptions import AssetAlreadyExists

# For routine use, instantiate a manager. It will locate cached copies of asset files. 
manager = AssetManager('mylib', 'https://downloader-server.example/mylib/')  # site hosts a manifest.json file
manager.locate('snp_to_rsid', genome_build='GRCh38')

# If the file has not yet been downloaded, it can be automatically fetched or built (from a known recipe)
manager.locate('snp_to_rsid', genome_build='GRCh38', auto_fetch=True, auto_build=True)

# Alternately, the asset can be manually fetched or built as a one-time operation during installation.
manager.download('snp_to_rsid', genome_build='GRCh38')
manager.build('snp_to_rsid', genome_build='GRCh38')

# The manager can build assets according to pre-defined recipes (a callable that accepts arguments).
def a_build_func(manager, item_type, temp_build_folder, **kwargs):
    # A build function has access to the manager (so it can check for existing files), and returns metadata calculated 
    #   during the build that will be stored as additional asset tags
    if manager.locate(item_type, auto_build=False, auto_fetch=False, **kwargs):
        # Raise a special exception class to interrupt the build without performing extra steps
        raise AssetAlreadyExists
    # ...do stuff that results in creating a file called filename.txt, and return extra metadata about the file version built
    return 'filename.txt', {'db_snp_build': 'b153'}

manager.add_recipe('snp_to_rsid', a_build_func, label='fast rsID lookups', genome_build='GRCh37')

# With an additional helper, your package can expose a CLI to handle these asset operations. 
#   (this is especially useful as a package entrypoint script, so that filefetcher provides a convenient install 
#   experience for your large data assets)
cli = AssetCLI(manager)
if __name__ == '__main__':
   cli.run()

Development

Install dependencies + unit tests

pip install -e .[test]

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

filefetcher-0.1.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

filefetcher-0.1.2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file filefetcher-0.1.2.tar.gz.

File metadata

  • Download URL: filefetcher-0.1.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for filefetcher-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4e13ef679bab1442a9f4043a70769afb27d6022456e3adea4500762047457e1b
MD5 aa1fc46a7b843c3bf9b0dcabab867a16
BLAKE2b-256 87d7c102fac8b7130bdc9a9705b4a062a7591af3d151d91559d7640d96e4300d

See more details on using hashes here.

File details

Details for the file filefetcher-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: filefetcher-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for filefetcher-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc1c7bb9079a32f0dd44edecddf9182f90abcd89296d621c1dca3823f11ece0
MD5 9d9441afb81df38f8555bd755198ed76
BLAKE2b-256 8ff71575ebe213dcc98465a7fbc5b80199133c0d24b1d19b284aedcd86c23517

See more details on using hashes here.

Supported by

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