import os
import pandas as pd
from sodapy import Socrata
# Import keys
%store -r APPTOKEN
%store -r KEYID
%store -r KEYSECRET
# Unauthenticated client only works with public data sets. Note 'None'
# in place of application token, and no username or password:
client = Socrata("data.lacity.org", None)
# First 2000 results, returned as JSON from API / converted to Python list of
# dictionaries by sodapy.
results = client.get("6rrh-rzua", limit=2000)
# Convert to pandas DataFrame
results_df = pd.DataFrame.from_records(results)
results_df.head(2)
client = Socrata(data.lacity.org,
MyAppToken,
userame="user@example.com",
password="AFakePassword")
data.lacity.org
: the website that contains the dataMyAppToken
: the App Token code assigned when request is approved.userame="user@example.com"
: Apply for the API Key and use the KEYID here.password="AFakePassword"
: Apply for the API Key and use the KEY SECRET.# Example authenticated client (needed for non-public datasets):
client = Socrata("data.lacity.org",
APPTOKEN,
username=KEYID,
password=KEYSECRET)
# First 2000 results, returned as JSON from API / converted to Python list of
# dictionaries by sodapy.
results = client.get("6rrh-rzua", limit=2000)
# Convert to pandas DataFrame
results_df = pd.DataFrame.from_records(results)
results_df.head(5)