Datapipe Weekly #21
Hello friend! This is a newsletter for builders.
What do you like to build?
I hope the ideas in this week’s newsletter can help you get it done.
In this weeks newsletter
💻 Tip: Explore JSON in Jupyter Notebooks
📜 Quote of the week
Tip: Explore JSON in Jupyter Notebooks
Jupyter Notebooks are great. That’s why I used them as the foundation for my Data Science book.
Here’s a trick I used recently when exploring the JSON output from Google’s Page Speeds API.
Pretty neat eh? Being able to expand and close the fields is really key for exploring the data quickly and being able to compare the responses for different API calls.
Here’s the function that allows this to happen. You can copy and past this into your notebook and run it in order to make the RenderJSON function available:
import uuid
from IPython.display import display_javascript, display_html, display
import json
class RenderJSON(object):
def __init__(self, json_data):
if isinstance(json_data, dict):
self.json_str = json.dumps(json_data)
else:
self.json_str = json
self.uuid = str(uuid.uuid4())
def _ipython_display_(self):
display_html('<div id="{}" style="height: 600px; width:100%;"></div>'.format(self.uuid),
raw=True
)
display_javascript("""
require(["https://rawgit.com/caldwell/renderjson/master/renderjson.js"], function() {
document.getElementById('%s').appendChild(renderjson(%s))
});
""" % (self.uuid, self.json_str), raw=True)
Most of the magic in this code (which I found on reddit, linked to above) comes from this JS script, which is included in the “require:” statement above.
Here’s a full example you can try out:
resp = requests.get("https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://developers.google.com")
resp_json = resp.json()
RenderJSON(resp_json)
Since this request doesn’t include an API token (which is free, if you’re curious to actually try it out) it may return an error. That’s what happened to my anyway:
Quote of the week
“Living things tend to change unrecognizably as they grow. Flora or fauna, we are all shapeshifters and magical reinventors.”
- Diane Ackerman
I’ve been having a health issue the last couple weeks. It’s made me feel heavy and tired, especially late in the day. And it’s been hard mentally - not knowing when I will be back to myself again.
The truth is I will never be back to myself, because we are never the same person even from day to day.
Every day bring change, directed by the food, books or media we consume - by our interactions with others or introspection. Even abstinence brings change, because life is flux.
If you are sick as well, then I hope this helps you accept and start to unwind any suffering you’re feeling. If not - I invite you to reflect on what this quote means to you.
From one shapeshifter to another.
-Alex
Thank you for reading Datapipe 👋
Subscribe the Datapipe weekly newsletter ⬇️