Examples and use-cases
Python examples with tools and integrations
1. Who is doing what where
import json
from urllib import request
APP_IDENTIFIER = "{your app identifier}"
THEME = "coordination-context/operational-presence"
LOCATION = "AFG"
LIMIT = 1000
def fetch_all(base_url, limit):
results = []
idx = 0
while True:
offset = idx * limit
url = f"{base_url}&offset={offset}&limit={limit}"
with request.urlopen(url) as response:
page = json.loads(response.read())["data"]
results.extend(page)
if len(page) < limit:
break
idx += 1
return results
base_url = (
f"https://hapi.humdata.org/api/v2/{THEME}"
f"?location_code={LOCATION}"
f"&output_format=json"
f"&app_identifier={APP_IDENTIFIER}"
)
data = fetch_all(base_url, LIMIT)
print(f"Retrieved {len(data)} records")2. Combine two sources for a food security snapshot
3. Population by admin level, with pagination
4. Conflict events over time
See it in action
Tools and integrations
Last updated
Was this helpful?
