Personal Data Warehouses: Reclaiming Your Data

Last modified on November 14, 2020

I gave a chat the day sooner than these days about personal information warehouses for GitHub’s OCTO Speaker Series, specializing in my Datasette and Dogsheep tasks. The video of the controversy is now accessible, and I’m presenting that right here alongside with an annotated summary of the controversy, together with hyperlinks to demos and further data.

There’s a brief technical glitch with the present camouflage sharing inside the first small whereas of the controversy—I’ve added screenshots to the notes which mannequin what it is most likely you will keep thought-about if my present camouflage had been precisely shared.

Simon Willison - FOSS Developer and Consultant, Python, Django, Datasette

I’m going to be speaking about personal information warehouses, what they're, why you select one, be taught how one can fabricate them and probably the most attention-grabbing points you can also kind while you’ve assign one up.

I’m going to start with a demo.

Cleo wearing a very fine Golden Gate Bridge costume with a prize rosette attached to it

That is my canine, Cleo—when she gained first plot in a canine costume opponents right here, dressed as a result of the Golden Gate Bridge!

All of my checkins on a map

So the quiz I've to decision is: How crucial of a San Francisco hipster is Cleo?

I will decision it using my personal information warehouse.

I genuinely keep a database of ten 12 months’s worth of my checkins on Foursquare Swarm—generated using my swarm-to-sqlite instrument. Whenever I register someplace with Cleo I reap the benefits of the Wolf emoji inside the checkin message.

All of Cleo's checkins on a map

I will filter for superior checkins the construct the checkin message consists of the wolf emoji.

Which technique I will take into legend superior her checkins—all 280 of them.

Cleo's top categories

If I aspect by venue class, I will take into legend she’s checked in at 57 parks, 32 canine runs, 19 espresso retailers and 12 natural groceries.

A map of coffe shops that Cleo has been to

Then I will aspect by venue class and filter all the scheme through which all the way down to superior her 19 checkins at espresso retailers.

Seems to be she’s a Blue Bottle woman at coronary heart.

Being able to fabricate a scheme of the espresso retailers that your canine likes is clearly a genuinely priceless intention to manufacture your enjoyment of personal information warehouse.

The Datasette website

Let’s devour a step assist and focus on how this demo works.

The most important to this demo is that this internet utility I’m operating referred to as Datasette. I’ve been engaged on this mission for 3 years now, and the intention is to get cling of it as straightforward and low cost as conceivable to look out information in each form of styles and sizes.

A screenshot of the Guardian Data Blog

Ten years inside the previous I used to be working for the Guardian newspaper in London. One of many points I noticed after I joined the group is that newspapers internet substantial quantities of information. Any time they put up a chart or scheme inside the newspaper any particular person has to internet the underlying data.

There was a journalist there referred to as Simon Rogers who was a wizard at amassing any information it is most likely you will maybe assume to quiz for. He knew precisely the construct to win it from, and had clean a protected selection of shiny spreadsheets on his desktop laptop.

We determined we wished to put up the data inside the assist of the tales. We began one thing referred to as the Knowledge Weblog, and aimed to accompany our tales with the uncooked information inside the assist of them.

A Google Sheet containing US public debt figures since 2001

We ended up using Google Sheets to put up the data. It labored, however I repeatedly felt love there must collected be a greater method to put up this roughly structured information in a talent that was as priceless and versatile as conceivable for our viewers.

Serverless hosting? Scale to Zero. ... but databases cost extra!

Posthaste forward to 2017, after I used to be taking a take into legend into this new factor referred to as “serverless” internet plot internet hosting—specifically one referred to as Zeit Now, which has since rebranded as Vercel.

My well-liked aspect of Serverless is “Scale to zero”—the premise that you simply easiest pay for internet plot internet hosting when your mission is receiving guests.

Whenever you’re love me, and in addition you might be caring for setting up facet-projects however you don’t love paying $5/month for them for the the remainder of your life, right here is ideally prime quality.

The get cling of is that serverless suppliers are inclined to price you extra for databases, or require you to rob a hosted database from another provider.

However what in case your database doesn’t change? Are you capable of bundle your database inside the same container as your code?

This was the preliminary inspiration inside the assist of making Datasette.

A GitHub repository containing the Global Power Plant Database

Bask in lots of groups, they put up that information on GitHub.

A Datasette instance showing power plants faceted by country and primary fuel

I genuinely keep a script that grabs their most trendy information and publishes it using Datasette.

Here’s the contents of their CSV file printed using Datasette

Datasette helps plugins. You’ve already thought-about this plugin in my demo of Cleo’s espresso retailers—it’s referred to as datasette-cluster-scheme and it genuinely works by procuring for tables with a latitude and longitude column and plotting the data on a scheme.

A zoomed in map showing two power plants in Antarctica

Straight away taking a take into legend at this information you behold that there’s a couple of vitality vegetation down right here in Antarctica. That is McMurdo station, and it has a 6.6MW oil generator.

And oh take into legend, there’s a wind farm down there too on Ross Island knocking out 1MW {of electrical} vitality.

a screen full of JSON

And one thing i'll take into legend inside the interface, I will win out as JSON. Here’s a JSON file exhibiting all of those nuclear vitality vegetation in France.

A screen full of CSV

And right here’s a CSV export which I will use to tug the data into Excel or different CSV-neatly matched instrument.

An interface for editing a SQL query

If I click on “take into legend and edit SQL” to win assist the SQL quiz that was conventional to generate the web page—and I will edit and re-extinguish that quiz.

I will win these customized outcomes assist as CSV or JSON as neatly!

Results of a custom SQL query

In most internet functions that can also be thought-about as a ugly safety hole—it’s a SQL injection assault, as a documented attribute!

About a causes this isn’t a neighborhood right here:

At the beginning, right here is setup as a be taught-simplest database: INSERT and UPDATE statements which may maybe modify it are not allowed. There’s a one second time prohibit on queries as neatly.

Secondly, all of the items on this database is designed to be printed. There are not any password hashes or personal particular person information that may most likely be uncovered right here.

This moreover technique we now keep a JSON API that lets JavaScript extinguish SQL queries towards a backend! This appears to be like to be genuinely priceless for snappily prototyping.

The SQLite home page

It’s worth speaking concerning the predominant sauce that makes this all conceivable.

That is all constructed on high of SQLite. All folks watching this discuss makes use of SQLite every day, although you don’t be acutely aware it.

Most iPhone apps use SQLite, many desktop apps kind, it’s even operating internal my Apple Stumble on.

One of my well-liked capabilities is {that a} SQLite database is a single file on disk. This makes it straightforward to repeat, ship round and moreover technique I will bundle information up in that single file, encompass it in a Docker file and deploy it to serverless hosts to assist it on the procure.

A Datasette map of power outages

Here’s another demo that helps mannequin how GitHub suits into all of this.

Closing 12 months PG&E—the facility agency that covers crucial of California—turned off the facility to substantial swathes of the convey.

I purchased fortunate: six months earlier I had began scraping their outage scheme and recording the historical past to a GitHub repository.

A list of recent commits to the pge-outages GitHub repository, each one with a commit messages showing the number of incidents added, removed or updated

simonw/pge-outages is a git repository with 34,000 commits monitoring the historical past of outages that PG&E had printed on their outage scheme.

You could maybe maybe take into legend that two minutes inside the previous they added 35 new outages.

I’m using this information to put up a Datasette occasion with runt print of their historic outages. Here’s a web page exhibiting their contemporary outages ordered by probably the most prospects laid low with the outage.

Study Tracking PG&E outages by scraping to a git repo for added runt print on this mission.

A screenshot of my blog entry about Git scraping

I at present determined to provide this process a title. I’m calling it Git scraping—the premise is to devour any information present on the procure that represents some degree-in-time and commit it to a git repository that tells the fable of the historical past of that individual factor.

Here’s my article describing the pattern in further element: Git scraping: uncover changes over time by scraping to a Git repository.

A screenshot of the NYT scraped election results page

This technique genuinely stood out superior closing week throughout the US election.

That is the Novel York Cases election scraper internet plot, constructed by Alex Gaynor and a rising crew of contributors. It scrapes the Novel York Cases election outcomes and makes use of the data over time to mannequin how the outcomes are trending.

The nyt-2020-election-scraper GitHub repository page

It makes use of a GitHub Actions script that runs on a agenda, plus a genuinely luminous Python script that turns it right into a priceless web pages.

Yow will locate further examples of Git scraping beneath the git-scraping matter on GitHub.

A screenshot of the incident map on

I’m going to kind a small little little bit of dwell coding to mannequin you the way these points works.

That is the incidents web page from the convey of California CAL FIRE internet plot.

Any time I take into legend a scheme love this, my first instinct is to beginning up the browser developer devices and devour a take into legend at to resolve out the scheme through which it genuinely works.

The incident map with an open developer tools network console showing XHR requests ordered by size, largest first

If I beginning the community tab, refresh the web page after which filter to superior XHR requests.

A orderly trick is to suppose by measurement—ensuing from inevitably the factor on the pinnacle of the guidelines is probably the most attention-grabbing information on the web page.

a JSON list of incidents

This appears to be like to be a JSON file telling me about the entire contemporary fires inside the convey of California!

(I assign up a Git scraper for this a while inside the previous.)

Now I’m going to devour this a step further and switch it right into a Datasette occasion.

The AllYearIncidents section of the JSON

It appears to be like love the AllYrIncidents secret is probably the most attention-grabbing bit right here.

A screenshot showing the output of curl

I’m going to make use of curl to get cling of that information, then pipe it by means of jq to filter for superior that AllYrIncidents array.

curl '' 
        | jq .AllYrIncidents

Pretty-printed JSON produced by piping to jq

Now I genuinely keep a guidelines of incidents for this 12 months.

A terminal running a command that inserts the data into a SQLite database

Next I’m going to pipe it right into a instrument I’ve been setting up referred to as sqlite-utils—it’s a collection of devices for manipulating SQLite databases.

I’m going to make use of the “insert” repeat and insert the data right into a ca-fires.db in an incidents desk.

curl '' 
        | jq .AllYrIncidents 
        | sqlite-utils insert ca-fires.db incidents -

Now I’ve purchased a ca-fires.db file. I will beginning that in Datasette:

datasette ca-fires.db -o

A map of incidents, where one of them is located at the very bottom of the map in Antarctica

And right here it is miles—a group new database.

You could maybe maybe immediately take into legend that indubitably one in every of many rows has a mistaken house, therefore it appears to be like in Antarctica.

However 258 of them take into legend love they're inside the best plot.

I list of faceted counties, showing the count of fires for each one

I will moreover aspect by county, to survey which county had probably the most fires in 2020—Riverside had 21.

datasette publish --help shows a list of hosting providers - cloudrun, heroku and vercel

I’m going to devour this a step further and construct it on the procure, using a repeat referred to as datasette put up.

Datasette put up helps a selection of various internet plot internet hosting suppliers. I’m going to make use of Vercel.

A terminal running datasette publish

I’m going to point it to put up that database to a mission referred to as “ca-fires”—and current it to place within the datasette-cluster-scheme plugin.

datasette put up vercel ca-fires.db 
        --mission ca-fires 
        --install datasette-cluster-scheme

This then takes that database file, bundles it up with the Datasette utility and deploys it to Vercel.

A page on showing a deployment in process

Vercel offers me a URL the construct I will show display screen the event of the deploy.

The intention right here is to take care of as few steps as conceivable between discovering some attention-grabbing information, turning it right into a SQLite database you can also use with Datasette after which publishing it on-line.

Screenshot of Stephen Wolfram's essay Seeking the Productive Life: Some Details of My Personal Infrastructure

I’ve given you a whistle-cease tour of Datasette for the functions of publishing information, and optimistically doing a small excessive information journalism.

So what does this all should kind with personal information warehouses?

Closing 12 months, I be taught this essay by Stephen Wolfram: In the hunt for the Productive Lifestyles: Some Particulars of My Personal Infrastructure. It’s a fantastic exploration of fourty years of productiveness hacks that Stephen Wolfram has utilized to turn out to be the CEO of a 1,000 particular person agency that works remotely. He’s optimized each aspect of his splendid and personal life.

A screenshot showing the section where he talks about his metasearcher

It’s hundreds.

However there was one section of this that actually caught my peep. He talks a couple of factor he calls a “metasearcher”—a search engine on his personal homepage that searches each e mail, journals, recordsdata, all of the items he’s ever accomplished—multi useful plot.

And I believed to myself, I genuinely select THAT. I maintain this conception of a non-public portal to my enjoyment of stuff.

And ensuing from it was impressed by Stephen Wolfram, however I used to be planning on setting up a crucial a lot much less spectacular mannequin, I made a decision to call it Dogsheep.

Wolf, ram. Dog, sheep.

I’ve been setting up this over the earlier 12 months.

A screenshot of my personal Dogsheep homepage, showing a list of data sources and saved queries

So in reality right here is my personal information warehouse. It pulls in my personal information from as many sources as I will achieve and offers me an interface to browse that information and bustle queries towards it.

I’ve purchased information from Twitter, Apple HealthEquipment, GitHub, Swarm, Hacker News, Photography, a duplicate of my genome... each form of points.

I’ll mannequin a couple of further demos.

Tweets with selfies by Cleo

Here’s another one about Cleo. Cleo has a Twitter legend, and every time she goes to the vet she posts a selfie and says how crucial she weighs.

A graph showing Cleo's weight over time

Here’s a SQL quiz that finds each tweet that mentions her weight, pulls out her weight in kilos using a irregular expression, then makes use of the datasette-vega charting plugin to mannequin a self-reported chart of her weight over time.

    regexp_match('.*?(d+(.d+))lb.*', full_text, 1) as lbs,
        when (media_url_https is not null)
        then json_object('img_src', media_url_https, 'width', 300)
    extinguish as characterize
    left be part of media_tweets on
    left be part of media on
    the construct
    full_text love '%lb%'
    and particular person=3166449535
    and lbs is not null
    neighborhood by
    suppose by
    created_at desc

A screenshot showing the result of running a SQL query against my genome

I did 23AndMe a couple of years inside the previous, so I genuinely keep a duplicate of my genome in Dogsheep. This SQL quiz tells me what color my eyes are.

Apparently they're blue, 99% of the time.

buy rsid, genotype, case genotype
    when 'AA' then 'brown peep color, 80% of the time'
    when 'AG' then 'brown peep color'
    when 'GG' then 'blue peep color, 99% of the time'
    extinguish as interpretation from genome the construct rsid='rs12913832'

A list of tables in my HealthKit database

I genuinely keep HealthEquipment information from my Apple Stumble on.

Something I like about Apple’s approach to these points is that they don’t superior add your entire information to the cloud.

This data lives in your watch and in your mobile phone, and there’s an selection inside the Health app in your mobile phone to export it—as a zipper file fleshy of XML.

I wrote a script referred to as healthkit-to-sqlite that converts that zip file right into a SQLite database, and now I genuinely keep tables for points love my basal vitality burned, my physique fleshy share, flights of stairs I’ve climbed.

Screenshot showing a Datasette map of my San Francisco Half Marathon route

However the genuinely enjoyable section is that it appears to be like any time you uncover an beginning air train in your Apple Stumble on it recordsdata your staunch house each few seconds, and in addition you can also win that information assist out as soon as extra!

That is a scheme of my staunch route for the San Francisco Half of Marathon three years inside the previous.

I’ve began monitoring an “beginning air drag” every time I fling on a drag now, superior so I will win the GPS information out as soon as extra later.

Screeshot showing a list of commits to my projects, faceted by repository

I genuinely keep a type of information from GitHub about my tasks—all of my commits, factors, enviornment suggestions and releases—all of the items I will win out of the GitHub API using my github-to-sqlite instrument.

So I will kind points love take into legend all of my commits throughout all of my tasks, search and aspect them.

I genuinely keep a public demo of a subset of this information at github-to-sqlite.dogsheep.procure.

A faceted interface showing my photos, faceted by city, country and whether they are a favourite

Apple Photography is a very attention-grabbing present of information.

It appears to be like the Apple Photography app makes use of a SQLite database, and should you understand what you’re doing you can also extract characterize metadata from it.

They genuinely bustle machine learning gadgets in your enjoyment of machine to resolve out what your photographs are of!

Some photos I have taken of pelicans, inside Datasette

You could maybe maybe use the machine learning labels to survey the entire photographs it is most likely you will even keep gotten taken of pelicans. Listed beneath are the entire photographs I genuinely keep taken that Apple Photography keep recognized as pelicans.

Screenshot showing some of the columns in my photos table

It moreover appears to be like they've columns referred to as points love ZOVERALLAESTHETICSCORE, ZHARMONIOUSCOLORSCORE, ZPLEASANTCAMERATILTSCORE and further.

So I will form my pelican photographs with probably the most aesthetically dazzling first!

Screenshot of my Dogsheep Beta faceted search interface

And some weeks inside the previous I at closing purchased round to setting up the factor I’d repeatedly wished: the search engine.

I referred to as it Dogsheep Beta, ensuing from Stephen Wolfram has a search engine referred to as Wolfram Alpha.

That is pun-driven sample: I got here up with this pun a while inside the previous and favored it so crucial I dedicated to setting up the instrument.

Search results for Cupertino, showing photos with maps

I wanted to know when the ultimate time I had eaten a waffle-fish ice cream was. I knew it was in Cupertino, so I searched Dogsheep Beta for Cupertino and came upon this characterize.

I hope this illustrates how crucial you can also kind should you pull your entire personal information into one plot!

GDPR really helps

The GDPR regulation that handed in Europe a couple of years inside the previous genuinely helps with these points.

Companies should provide you with win true of entry to to the data that they retailer about you.

Many huge internet firms keep answered to this by offering a self-service export attribute, usually buried someplace inside the settings.

You could maybe maybe moreover demand information straight from firms, however the self-service selection helps them retain their purchaser improve prices down.

These objects turns into more straightforward over time as further firms manufacture out these capabilities.

Democratizing access. The future is already here, it's just not evenly distributed - William Gibson

The different enviornment is how we democratize win true of entry to to this.

Every factor I’ve proven you these days is beginning present: you can also set up this instrument and use it your self, with out price.

However there’s a type of assembly required. It is high to resolve out authentication tokens, achieve someplace to host it, assign up cron jobs and authentication.

However this will collected be accessible to irregular non-uber-nerd people!

Democratizing access. Should users run their own online Dogsheep? So hard and risky! Tailscale and WireGuard are interesting here. Vendors to provide hosted Dogsheep? Not a great business, risky!. Better options: Desktop app, mobile app.

Staring at for irregular people to bustle a gradual internet server someplace is good-looking ugly. I’ve been taking a take into legend at WireGuard and Tailscale to assist get cling of regular win true of entry to between devices more straightforward, however that’s collected very crucial for excellent-customers easiest.

Working this as a hosted service doesn’t attraction: taking accountability for folks’s personal information is hideous, and it’s probably not a wonderful trade.

I really feel the best options are to bustle on different folks’s enjoyment of personal devices—their cellphones and their laptops. I really feel it’s most likely to win Datasette operating in these environments, and I like the premise of shoppers being able to import their personal information onto a machine that they handle an eye fixed on and analyzing it there.

Screenshot of Dogsheep on GitHub

The Dogsheep GitHub group has most of the devices that I’ve conventional to manufacture out my personal Dogsheep warehouse—a type of them using the naming conference of something-to-sqlite.

Q&A, from this Google Doc

Screenshot of the Google Doc

Q: Is there/will there be a Datasette hosted service that I pays $ for? I might favor to pay $5/month to win win true of entry to to probably the most trendy mannequin of Dogsheep with all the most trendy plugins!

I don’t must fabricate an online plot internet hosting plot for personal personal information ensuing from I really feel different folks must collected personal as rather a lot because the ticket of that themselves, plus I don’t assume there’s a very unbiased trade mannequin for that.

As an completely different, I’m setting up a hosted service for Datasette (referred to as Datasette Cloud) which is geared towards firms and organizations. I want in speak in confidence to current newsrooms and different groups with a non-public, regular, hosted environment the construct they're going to piece information with each different and bustle analysis.

Screenshot showing an export running on an iPhone in the Health app

Q: How kind you sync your information out of your mobile phone/watch to the data warehouse? Is it a handbook task?

The neatly being information is handbook: the iOS Health app has an export button which generates a zipper file of XML which you can also then AirDrop to a pocket book laptop. I then bustle my healthkit-to-sqlite script towards it to generate the DB file and SCP that to my Dogsheep server.

Heaps of my different Dogsheep devices use APIs and might bustle on cron, to get cling of probably the most trendy information from Swarm and Twitter and GitHub and so forth.

Q: When accessing Github/Twitter and tons others kind you bustle queries towards their API otherwise you periodically sync (retrieve largely I assume) the data to the warehouse first after which quiz domestically?

I repeatedly attempt to win ALL the data so I will quiz it domestically. The enviornment with APIs that enable you bustle queries is that inevitably there’s one thing I've to kind that may’t be accomplished of the API—so I’d crucial barely suck all of the items down into my enjoyment of database so I will write down my enjoyment of SQL queries.

Screenshot showing how to run swarm-to-sqlite in a terminal

Here’s an occasion of my swarm-to-sqlite script, pulling in superior checkins from the earlier two weeks (using authentication credentials from an surroundings variable).

swarm-to-sqlite swarm.db --since=2w

Here’s a redacted copy of my Dogsheep crontab.

Screenshot of the SQL.js GitHub page

Q: Bask in you ever explored doing this as a single web page app in order that it is miles conceivable to deploy this as a static plot? What are the constraints there?

It’s genuinely conceivable to quiz SQLite databases totally internal consumer-facet JavaScript using SQL.js (SQLite compiled to WebAssembly)

Screenshot of an Observable notebook running SQL.js

This Observable pocket book is an occasion that makes use of this to bustle SQL queries towards a SQLite database file loaded from a URL.

Screenshot of a search for cherry trees on

Datasette’s JSON and GraphQL APIs point out it goes to with out declare act as an API backend to SPAs

I constructed this plot to current a search engine for bushes in San Francisco. Stare present to survey the scheme through which it hits a Datasette API inside the background:

The network pane running against

You could maybe maybe use the community pane to survey that it’s operating queries towards a Datasette backend.

Screenshot of view-source on

Here’s the JavaScript code which calls the API.

Screenshot of Datasette Canned Query documentation

Q: What chances for information entry devices kind the writable canned queries beginning up?

Writable canned queries are a reasonably current Datasette attribute that enable administrators to configure a UPDATE/INSERT/DELETE quiz that's prone to be referred to as by prospects filling in varieties or accessed by means of a JSON API.

The concept is to get cling of it straightforward to manufacture backends that handle straightforward information entry as neatly as to serving be taught-simplest queries. It’s a attribute with a type of talent however so far I’ve not conventional it for one thing important.

Presently it goes to generate a VERY common get cling of (with single-line enter values, equal to this search occasion) however I hope to get cling of higher it at some point to boost customized get cling of widgets by means of plugins for points love dates, scheme places or autocomplete towards different tables.

Q: For the native mannequin the construct you had a 1-line push to deploy a brand new datasette: how kind you handle updates? Is there a equivalent 1-line replace to replace an contemporary deployed datasette?

I deploy a group new set up every time the data changes! This works wonderful for information that easiest changes a couple of times a day. If I genuinely keep a mission that changes a pair of instances an hour I’ll bustle it as a irregular VPS as an completely different as a change of use a serverless internet plot internet hosting provider.

Read More

Similar Products:

Recent Content