Instant serverless APIs,
powered by SQLite
Simon Willison @simonw
PyCon US 2019
Slide 2
Slide 2 text
Serverless?
Slide 3
Slide 3 text
Serverless
Scale-to-zero
Slide 4
Slide 4 text
Serverless
Only pay for the computing
resources you use.
Scale-to-zero
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
Stateless
Slide 8
Slide 8 text
What if you ship static
data as part of your app?
Slide 9
Slide 9 text
Data Journalism
Slide 10
Slide 10 text
No content
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
A better way of
publishing data?
Slide 14
Slide 14 text
Datasette
A tool for exploring and publishing data
datasette.io
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
No content
Slide 17
Slide 17 text
No content
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
Some handy features
• Filtering and faceting
• Custom SQL queries
• JSON API to everything
• Export table (or query results) as CSV
Slide 20
Slide 20 text
The secret sauce is SQLite
• Small, fast, ubiquitous
• A database is a single file
• Doesn’t scale well for writes…
• … but who cares if your data is read-only?
• Ship your data and code in the same container!
Slide 21
Slide 21 text
pip install datasette
(Python 3 only)
Slide 22
Slide 22 text
find ~/Library -iname '*.sqlite*' \
-type f -exec du -h {} + | sort -r -h
Slide 23
Slide 23 text
find ~/Library -iname '*.sqlite*' \
-type f -exec du -h {} + | sort -r -h
https://glitch.com/edit/#!/pypi-top-1500-autocomplete
Based on the technique described in
https://24ways.org/2018/fast-autocomplete-search-for-
your-website/
Slide 46
Slide 46 text
No content
Slide 47
Slide 47 text
Some more
interesting projects
Slide 48
Slide 48 text
Russian IRA ads
https://simonwillison.net/2018/Aug/6/russian-facebook-ads/
Credit: Ed Summers, for cleaning the data
Slide 49
Slide 49 text
No content
Slide 50
Slide 50 text
Baltimore Salaries
https://salaries.news.baltimoresun.com/
Credit: Carl Johnson, Baltimore Sun
Slide 51
Slide 51 text
No content
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
The world is full of
interesting data…
Slide 54
Slide 54 text
… let’s publish it in the
most useful way possible