Package: census-data-downloader
census-data-downloaderDownloadAmerican Community Survey datafrom the U.S. Census Bureau and reformat it for humans.What's availableAll of the data files processed by this repository are published in thedata/processed/folder. They can be called in to applications via their raw URLs, likehttps://raw.githubusercontent.com/datadesk/census-data-downloader/master/data/processed/acs5_2017_population_counties.csvThe command-line interfaceThe library can be installed as a command-line interface that lets you download files on demand.Installation$pipenvinstallcensus-data-downloaderCommand-line usageThere's now a tool namedcensusdatadownloaderready for you.Usage:censusdatadownloader[OPTIONS]TABLECOMMAND[ARGS]...DownloadCensusdataandreformatitforhumans

Options:--data-dirTEXTThefolderwhereyouwanttodownloadthedata--year[2009-2021]Theyearsofdatatodownload.Bydefaultitgetsonlythelatestyear.Notalldataareavailableforeveryyear.Submit'all'togeteveryyear.--forceForcethedownloadingofthedata--helpShowthismessageandexit.

Commands:aiannhhomelandsDownloadAmericanIndian,AlaskaNativeand...cnectasDownloadcombinedNewEnglandcityandtown...congressionaldistrictsDownloadCongressionaldistrictscountiesDownloadcountiesinallstatescountysubdivisionDownloadcountysubdivisionscsasDownloadcombinedstatisticalareasdivisionsDownloaddivisionselementaryschooldistrictsDownloadelementaryschooldistrictseverythingDownloadeverythingfromeverywheremsasDownloadmetropolitianstatisticalareasnationwideDownloadnationwidedatanectasDownloadNewEnglandcityandtownareasplacesDownloadCensus-designatedplacespumasDownloadpublicusemicrodataareasregionsDownloadregionssecondaryschooldistrictsDownloadsecondaryschooldistrictsstatelegislativedistrictsDownloadstatehousedistrictsstatesDownloadstatestractsDownloadCensustractsunifiedschooldistrictsDownloadunifiedschooldistrictsurbanareasDownloadurbanareaszctasDownloadZIPCodetabulationareasBefore you can use it you will need to add your CENSUS_API_KEY to your environment. If you don't have an API key, you can gohere.One quick way to add your key:$exportCENSUS_API_KEY='<your API key>'Using it is as simple as providing one our processed table names to one of the download subcommands.Here's an example of downloading all state-level data from themedianagedataset.$censusdatadownloadermedianagestatesYou can specify the download directory with--data-dir.$censusdatadownloader--data-dir./my-special-folder/medianagestatesAnd you can change the year you download with--year.$censusdatadownloader--year2010medianagestatesThat's it. Mix and match tables and subcommands to get whatever you need.Python usageYou can also download tables from Python scripts. Import the class of theprocessed tableyou wish to retrieve and pass in your API key. Then call one of the download methods.This example brings in all state-level data from the medianhouseholdincomeblack dataset.>>>fromcensus_data_downloader.tablesimportMedianHouseholdIncomeBlackDownloader>>>downloader=MedianHouseholdIncomeBlackDownloader('<YOUR KEY>')>>>downloader.download_states()You can specify the data directory and the years by passing in thedata_dirandyearskeyword arguments.>>>downloader=MedianHouseholdIncomeBlackDownloader('<YOUR KEY>',data_dir='./',years=2016)>>>downloader.download_states()Usage examplesA gallery of graphics powered by our data is available onObservable.The Los Angeles Times used this library foran analysis of Census undercountson Native American reservations. The code that powers it is available as anopen-source computational notebook.Contributing to the libraryAdding support for a new tableSubclass our downloader and provided it with its required inputs.importcollectionsfromcensus_data_downloader.core.tablesimportBaseTableConfigfromcensus_data_downloader.core.decoratorsimportregister@registerclassMedianHouseholdIncomeDownloader(BaseTableConfig):PROCESSED_TABLE_NAME="medianhouseholdincome"# Your humanized table nameUNIVERSE="households"# The universe value for this tableRAW_TABLE_NAME='B19013'# The id of the source tableRAW_FIELD_CROSSWALK=collections.OrderedDict({# A crosswalk between the raw field name and our humanized field name."001":"median"})Add it to the imports in the__init__.pyfile and it's good to go.Developing the CLIThe command-line interface is implemented using Click and setuptools. To install it locally for development inside your virtual environment, run the following installation command, asprescribed by the Click documentation.$pipinstall--editable.That's it. If you make some good ones, please consider submitting them as pull requests so everyone can benefit.