Skip to main content

Pooch manages your Python library's sample data files: it automatically downloads and stores them in a local directory, with support for versioning and corruption checks.

Project description

Pooch

Documentation | Documentation (dev version) | Contact | Part of the Fatiando a Terra project

Latest version on PyPI Latest version on conda-forge GitHub Actions workflow status Test coverage status Compatible Python versions. Digital Object Identifier for the JOSS paper

About

Does your Python package include sample datasets? Are you shipping them with the code? Are they getting too big?

Pooch is here to help! It will manage a data registry by downloading your data files from a server only when needed and storing them locally in a data cache (a folder on your computer).

Here are Pooch’s main features:

  • Pure Python and minimal dependencies.

  • Download a file only if necessary (it’s not in the data cache or needs to be updated).

  • Verify download integrity through SHA256 hashes (also used to check if a file needs to be updated).

  • Designed to be extended: plug in custom download (FTP, scp, etc) and post-processing (unzip, decompress, rename) functions.

  • Includes utilities to unzip/decompress the data upon download to save loading time.

  • Can handle basic HTTP authentication (for servers that require a login) and printing download progress bars.

  • Easily set up an environment variable to overwrite the data cache location.

Are you a scientist or researcher? Pooch can help you too!

  • Automatically download your data files so you don’t have to keep them in your GitHub repository.

  • Make sure everyone running the code has the same version of the data files (enforced through the SHA256 hashes).

Example

For a scientist downloading a data file for analysis:

from pooch import retrieve


# Download the file and save it locally. Running this again will not cause
# a download. Pooch will check the hash (checksum) of the downloaded file
# against the given value to make sure it's the right file (not corrupted
# or outdated).
fname = retrieve(
    url="https://some-data-server.org/a-data-file.nc",
    known_hash="md5:70e2afd3fd7e336ae478b1e740a5f08e",
)

For package developers including sample data in their projects:

"""
Module mypackage/datasets.py
"""
import pkg_resources
import pandas
import pooch

# Get the version string from your project. You have one of these, right?
from . import version


# Create a new friend to manage your sample data storage
GOODBOY = pooch.create(
    # Folder where the data will be stored. For a sensible default, use the
    # default cache folder for your OS.
    path=pooch.os_cache("mypackage"),
    # Base URL of the remote data store. Will call .format on this string
    # to insert the version (see below).
    base_url="https://github.com/myproject/mypackage/raw/{version}/data/",
    # Pooches are versioned so that you can use multiple versions of a
    # package simultaneously. Use PEP440 compliant version number. The
    # version will be appended to the path.
    version=version,
    # If a version as a "+XX.XXXXX" suffix, we'll assume that this is a dev
    # version and replace the version with this string.
    version_dev="master",
    # An environment variable that overwrites the path.
    env="MYPACKAGE_DATA_DIR",
    # The cache file registry. A dictionary with all files managed by this
    # pooch. Keys are the file names (relative to *base_url*) and values
    # are their respective SHA256 hashes. Files will be downloaded
    # automatically when needed (see fetch_gravity_data).
    registry={"gravity-data.csv": "89y10phsdwhs09whljwc09whcowsdhcwodcydw"}
)
# You can also load the registry from a file. Each line contains a file
# name and it's sha256 hash separated by a space. This makes it easier to
# manage large numbers of data files. The registry file should be packaged
# and distributed with your software.
GOODBOY.load_registry(
    pkg_resources.resource_stream("mypackage", "registry.txt")
)


# Define functions that your users can call to get back the data in memory
def fetch_gravity_data():
    """
    Load some sample gravity data to use in your docs.
    """
    # Fetch the path to a file in the local storage. If it's not there,
    # we'll download it.
    fname = GOODBOY.fetch("gravity-data.csv")
    # Load it with numpy/pandas/etc
    data = pandas.read_csv(fname)
    return data

Projects using Pooch

If you’re using Pooch, send us a pull request adding your project to the list.

Contacting Us

Citing Pooch

This is research software made by scientists (see AUTHORS.md). Citations help us justify the effort that goes into building and maintaining this project. If you used Pooch for your research, please consider citing us.

See our CITATION.rst file to find out more.

Contributing

Code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Contributing Guidelines

Please read our Contributing Guide to see how you can help and give feedback.

Imposter syndrome disclaimer

We want your help. No, really.

There may be a little voice inside your head that is telling you that you’re not ready to be an open source contributor; that your skills aren’t nearly good enough to contribute. What could you possibly offer?

We assure you that the little voice in your head is wrong.

Being a contributor doesn’t just mean writing code. Equally important contributions include: writing or proof-reading documentation, suggesting or implementing tests, or even giving feedback about the project (including giving feedback about the contribution process). If you’re coming to the project with fresh eyes, you might see the errors and assumptions that seasoned contributors have glossed over. If you can write any code at all, you can contribute code to open source. We are constantly trying out new skills, making mistakes, and learning from those mistakes. That’s how we all improve and we are happy to help others learn.

This disclaimer was adapted from the MetPy project.

License

This is free software: you can redistribute it and/or modify it under the terms of the BSD 3-clause License. A copy of this license is provided with distributions of the software.

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

pooch-1.5.2.tar.gz (61.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pooch-1.5.2-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file pooch-1.5.2.tar.gz.

File metadata

  • Download URL: pooch-1.5.2.tar.gz
  • Upload date:
  • Size: 61.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for pooch-1.5.2.tar.gz
Algorithm Hash digest
SHA256 5969b2f1defbdc405df932767e05e0b536e2771c27f1f95d7f260bc99bf13581
MD5 5ec984b376c9906a72a5d9a11cd1d02e
BLAKE2b-256 b345d2eaf68ab809155caef416f7281318b4b7753311ea415c9b066dac2dbf9a

See more details on using hashes here.

File details

Details for the file pooch-1.5.2-py3-none-any.whl.

File metadata

  • Download URL: pooch-1.5.2-py3-none-any.whl
  • Upload date:
  • Size: 57.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for pooch-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 debb159655de9eeccc366deb111fe1e33e76efac19724436b6878c09deca4293
MD5 6d6573b397afdeb03fa49d4496bfaa40
BLAKE2b-256 761e5092523703289aa1a9c14b1ed09d4eda6de76d7eee9ee6b26b54d675e73f

See more details on using hashes here.

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