Package: pooch
Documentation(latest)•Documentation(main branch)•Contributing•ContactPart of theFatiando a TerraprojectAboutJust want to download a file without messing withrequestsandurllib?
Trying to add sample datasets to your Python package?Pooch is here to help!Poochis aPython librarythat can manage data bydownloading filesfrom a server (only when needed) and storing them locally in a datacache(a folder on your computer).Pure Python and minimal dependencies.Download files over HTTP, FTP, and from data repositories like Zenodo and figshare.Built-in post-processors to unzip/decompress the data after download.Designed to be extended: create custom downloaders and post-processors.Are you ascientistor researcher? Pooch can help you too!Host your data on a repository and download using the DOI.Automatically download data using code instead of telling colleagues to do it themselves.Make sure everyone running the code has the same version of the data files.Projects using PoochSciPy,scikit-image,Ensaio,MetPy,napari,icepack,histolab,seaborn-image,Open AR-Sandbox,climlab,mne-python,GemGISIf you're using Pooch,send us a pull requestadding your project to the list.ExampleFor ascientist downloading a data filefor analysis:importpoochimportpandasaspd# Download a file and save it locally, returning the path to it.# 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_bathymetry=pooch.retrieve(url="https://github.com/fatiando-data/caribbean-bathymetry/releases/download/v1/caribbean-bathymetry.csv.xz",known_hash="md5:a7332aa6e69c77d49d7fb54b764caa82",)# Pooch can also download based on a DOI from certain providers.fname_gravity=pooch.retrieve(url="doi:10.5281/zenodo.5882430/southern-africa-gravity.csv.xz",known_hash="md5:1dee324a14e647855366d6eb01a1ef35",)# Load the data with Pandasdata_bathymetry=pd.read_csv(fname_bathymetry)data_gravity=pd.read_csv(fname_gravity)Forpackage developersincluding sample data in their projects:"""Module mypackage/datasets.py"""importpkg_resourcesimportpandasimportpooch# Get the version string from your project. You have one of these, right?from.importversion# Create a new friend to manage your sample data storageGOODBOY=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="main",# 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 memorydeffetch_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/etcdata=pandas.read_csv(fname)returndataGetting involved🗨️Contact us:Find out more about how to reach us atfatiando.org/contact.👩🏾‍💻Contributing to project development:Please read ourContributing Guideto see how you can help and give feedback.🧑🏾‍🤝‍🧑🏼Code of conduct:This project is released with aCode of Conduct.
By participating in this project you agree to abide by its terms.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, that you aren't skilled
enough to contribute. We assure you that the little voice in your head is
wrong. Most importantly,there are many valuable ways to contribute besides
writing code.This disclaimer was adapted from theMetPy project.LicenseThis is free software: you can redistribute it and/or modify it under the terms
of theBSD 3-clause License. A copy of this license is provided inLICENSE.txt.