Skip to main content
Latest Version Latest Docs https://travis-ci.org/sinhrks/pyopendata.svg?branch=master

Overview

pyopendata is a Python utility to offer an unified API to read world various data sources, and output pandas.DataFrame. Which covers:

Documentation

http://pyopendata.readthedocs.org/

Installation

pip install pyopendata

Basic Usage

This section explains how to retrieve data from website which uses CKAN API.You can create DataStore instance to access CKAN website by passing CKAN URL to DataStore class.

In this example, we’re going to retrieve the ‘California Unemployment Statistics’ data from data.gov. The target URL is:

We can read above URL as:

  • CKAN API URL: https://catalog.data.gov/

  • Package ID: california-unemployment-statistics

  • Resource ID: ffd05307-4528-4d15-a370-c16222119227

>>> import pyopendata as pyod

>>> store = pyod.DataStore('http://catalog.data.gov/')
>>> store
CKANStore (http://catalog.data.gov)

DataStore.serch performs search by keyword. Results will be the list of packages. You can select a target package by slicing.

>>> packages = store.search('Unemployment Statistics')
>>> packages
[annual-survey-of-school-system-finances (1 resource),
 current-population-survey (1 resource),
 federal-aid-to-states (1 resource),
 current-population-survey-labor-force-statistics (2 resources),
 dataferrett (1 resource),
 mass-layoff-statistics (1 resource),
 unemployment-rate (3 resources),
 consolidated-federal-funds-report (1 resource),
 annual-survey-of-state-and-local-government-finances (1 resource),
 local-area-unemployment-statistics (2 resources)]

>>> packages[0]
annual-survey-of-school-system-finances (1 resource)

Otherwise, specify the package name to be retrieved.

>>> package = store.get('california-unemployment-statistics')
>>> package
california-unemployment-statistics (4 resources)

A package has resources (files) which contains actual data. You use get method to retrieve the resource.

>>> resource = package.get('ffd05307-4528-4d15-a370-c16222119227')
>>> resource
Resource ID: ffd05307-4528-4d15-a370-c16222119227
Resource Name: Comma Separated Values File
Resource URL: https://data.lacity.org/api/views/5zrb-xqhf/rows.csv?accessType=DOWNLOAD
Format: CSV, Size: None

Once you get the resource, use read method to read data as pandas DataFrame.

>>> df = resource.read()
>>> df.head()
   Year Period                Area   Unemployment Rate  Labor Force  \
0  2013    Jan          California               10.4%     18556500
1  2013    Jan  Los Angeles County               10.9%      4891500
2  2013    Jan    Los Angeles City                 12%      1915600
3  2013    Feb          California  9.699999999999999%     18648300
4  2013    Feb  Los Angeles County               10.3%      4924000

   Employment  Unemployment Adjusted Preliminary
0    16631900       1924600  Not Adj  Not Prelim
1     4357800        533800  Not Adj  Not Prelim
2     1684800        230800  Not Adj  Not Prelim
3    16835900       1812400  Not Adj  Not Prelim
4     4418000        506000  Not Adj  Not Prelim

Or you can get raw data by specifying raw=True.

>>> raw = resource.read(raw=True)
>>> raw[:100]
'Year,Period,Area,Unemployment Rate,Labor Force,Employment,Unemployment,Adjusted,Preliminary\n2013,Jan'

Metadata

Release files for pyopendata 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyopendata 0.0.3
File Size Uploaded Provenance
pyopendata-0.0.3.tar.gz 12.0 kB Without provenance Details

Release files / pyopendata-0.0.3.tar.gz

Download URL pyopendata-0.0.3.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
88af960f76269ced9f1c034ecd5be90a640ae3a515a487e07fd6de82e12278f0
BLAKE2b-256 checksum
How to use checksums
3f9e66353403e163fc1406d7ce0b1cfc02972540435d2bfd9713a4f207b982ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pyopendata 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page