The fastest way to get data from the Open Data Blend Dataset API
Project description
Open Data Blend for Python
Open Data Blend for Python is the fastest way to get data from the Open Data Blend Dataset API. It is a lightweight, easy-to-use extract and load (EL) tool.
It has a single function called get_data
that can be used to get any data file belonging to an Open Data Blend dataset. The function transparently downloads and caches the data locally, mirroring the same folder hierarchy as on the remote server. It also caches a copy of the dataset metadata file (datapackage.json) at the point that the data file request is made. The local cache is persistent which means the files will be kept until they are deleted.
The versioned dataset metadata can be used to re-download a specific version of a data file (sometimes referred to as 'time travel'). You can learn more about how we version our datasets in the Open Data Blend Docs.
After downloading the data and metadata files, get_data
returns an object called Output
containing the local paths of the files. From there, you can load the data in Pandas, Koalas, or something similar to begin your analysis or feature engineering.
Installation
Install the latest version of opendatablend
from PyPI:
pip install opendatablend
Usage Examples
The following examples require the pandas
and pyarrow
packages to be installed:
pip install pandas
pip install pyarrow
Making Public API Requests
Note: Public API requests are limited per month.
Get The Data
import opendatablend as odb
import pandas as pd
dataset_path = 'https://packages.opendatablend.io/v1/open-data-blend-road-safety/datapackage.json'
# Specify the resource name of the data file. In this example, the 'date' data file will be requested in .parquet format.
resource_name = 'date-parquet'
# Get the data and store the output object
output = odb.get_data(dataset_path, resource_name)
# Print the file locations
print(output.data_file_name)
print(output.metadata_file_name)
Use The Data
# Read a subset of the columns into a dataframe
df_date = pd.read_parquet(output.data_file_name, columns=['drv_date_key', 'drv_date', 'drv_month_name', 'drv_month_number', 'drv_quarter_name', 'drv_quarter_number', 'drv_year'])
# Check the contents of the dataframe
df_date
Making Authenticated API Requests
Get The Data
import opendatablend as odb
import pandas as pd
dataset_path = 'https://packages.opendatablend.io/v1/open-data-blend-road-safety/datapackage.json'
access_key = '<ACCESS_KEY_HERE>'
# Specify the resource name of the data file. In this example, the 'date' data file will be requested in .parquet format.
resource_name = 'date-parquet'
# Get the data and store the output object
output = odb.get_data(dataset_path, resource_name, access_key=access_key)
# Print the file locations
print(output.data_file_name)
print(output.metadata_file_name)
Use The Data
# Read a subset of the columns into a dataframe
df_date = pd.read_parquet(output.data_file_name, columns=['drv_date_key', 'drv_date', 'drv_month_name', 'drv_month_number', 'drv_quarter_name', 'drv_quarter_number', 'drv_year'])
# Check the contents of the dataframe
df_date
Additional Examples
For more in-depth examples, see the examples folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for opendatablend-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80749824e06892e3d2cf2980588d3852adecc4af7da82b63f2feb0e7be3a7c19 |
|
MD5 | 19334661602f757a71941d6b21864541 |
|
BLAKE2b-256 | ef492bb10837ea2cdd8b98113dc49bacc800264598ed052cfbb0bd6baa8624d2 |