<jupyter_start><jupyter_text>Datahub Metadata Query ExampleThis notebook outlines how to capture a list of available datasets using the Datahub API. The output here is quite simple, but the avaialble metadata keys are displayed and output can be tailored to include additional attributes as needed.API documentation is available at http://docs.planetos.com. If you have questions or comments, join our [Slack community](http://slack.planetos.com/) to chat with our development team.For general information on usage of IPython/Jupyter and Matplotlib, please refer to their corresponding documentation. https://ipython.org/ and http://matplotlib.org/<jupyter_code>from urllib.request import urlopen, Request
from urllib.parse import urlencode
import simplejson as json<jupyter_output><empty_output><jupyter_text>**Important!** You'll need to replace `apikey` below with your actual Planet OS API key, which you'll find on the [Planet OS account settings page](http://data.planetos.com/account/settings/?utm_source=github&utm_medium=notebook&utm_campaign=dataset-metadata-api).<jupyter_code>apikey = open('APIKEY').readlines()[0].strip() #'<YOUR API KEY HERE>'
url = "http://api.planetos.com/v1/datasets?apikey=%s" % apikey
print(url)
request = Request(url)
response = urlopen(request)
dataset_ids = json.loads(response.read())
# inspect the available keys and metadata structure from a single dataset
api_endpoint = "http://api.planetos.com/v1/datasets/"
query_dict = {'apikey': apikey}
query = urlencode(query_dict)

datasets = []

for id in dataset_ids:
    api_query = "%s%s?%s" % (api_endpoint, id, query)
    request = Request(api_query)
    response = urlopen(request)
    response_json = json.loads(response.read())

    datasets.append(response_json)

datasets[0].keys()
# Alphabetically sort by dataset title
alpha_datasets = sorted(datasets, key=lambda k: k['Title'])

print("%s Datasets Available on Datahub\nhttp://data.planetos.com/\n" % len(datasets))

for ds in alpha_datasets:
    datahub_url = "http://data.planetos.com/datasets/%s" % ds['Key']
    # output Title, publisher, and Datahub url
    print("(%s) %s\n%s\n" % (ds['Publisher'], ds['Title'], datahub_url))
    # output Title, publisher, Datahub url and full abstract
#     print("%s (%s)\n%s\n--\n%s\n" % (ds['Publisher'], ds['Title'], datahub_url, ds['Abstract']))<jupyter_output>82 Datasets Available on Datahub
http://data.planetos.com/

(Bureau of Meteorology, Australia)  Bureau of Meteorology (BOM) Daily Rain, Temperature and Vapour Pressure for Australia
http://data.planetos.com/datasets/bom_clim_australia

(Bureau of Meteorology, Australia)  Bureau of Meteorology (BOM) Daily solar exposure for Australia
http://data.planetos.com/datasets/bom_solar_australia

(Bureau of Meteorology, Australia)  Bureau of Meteorology (BOM) Monthly NDVI Average for Australia
http://data.planetos.com/datasets/bom_ndvi_australia

(Copernicus)  Copernicus Atmosphere Monitoring Service (CAMS) global near-real-time production system
http://data.planetos.com/datasets/cams_nrt_forecasts_global

(NOAA) 3-day cumulative USF AFAI Fields
http://data.planetos.com/datasets/noaa_aoml_afai

(Copernicus Marine Environment Monitoring System (CMEMS)) Baltic Sea - in situ near real time observations
http://data.planetos.com/datasets/cmems_baltic_observations_daily

(Copernicus) Baltic Sea Biogeo[...]
{'fraction_non_alphanumeric': 0.11398809523809524, 'fraction_numerical': 0.0020833333333333333, 'mean_word_length': 5.577299412915851, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '574856', 'license': 'MIT', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1073, 'n_words': 301, 'path': 'api-examples/dataset-metadata-api.ipynb', 'repo_name': 'evan1997123/PlanetOSDatathon', 'size': '3360'}