fetch_data module

This module contains helper functions used to obtain shape files required to determine the intersections of Census tracts, PUMAs, and ZIP codes. Downloaded data is stored in the computer’s temporary cache and should be deleted automatically at termination.

ziptool.fetch_data.download_file(url: str, output_filename: Union[str, pathlib.Path], session: Optional[requests.sessions.Session] = None)

Downloads a file from the provided URL and saves it at the desired path.

Parameters
  • url – a string representing the URL of the file you want to download

  • output_filename – a FilenameType representing the desired download path

Returns

None

ziptool.fetch_data.get_shape_files(state_fips_code, year)

For a given state (in particular its FIPS code), downloads its census tracts and PUMA shapefiles from the Census Bureau. The functions skips the download if the file already has been fetched!

Parameters
  • state_fips_code – string representing the state of interest

  • year – string representing the year

Returns

Saves .shp files for both PUMA and census tracts within the data directory.