Using books data in Scratch

In this post, I want to share a Scratch extension that I’ve been working on today: enabling access to books data from the OpenLibrary API through new Scratch blocks.

Most of the work I do on Machine Learning for Kids involves adding machine learning models into Scratch. To enable students to create interesting projects, it also helps to make it easier to get external data into Scratch that they can use for training and classifying. A few examples of where I’ve done this in the past include creating Scratch blocks to access weather data, data from Spotify, and data from Wikipedia.

New blocks

The new blocks I’ve worked on today use the OpenLibrary API to enable access to information about books.

Search by ISBN

This tries to find a specific book using an International Standard Book Number.

Search by title

This tries to find a specific book using the provided title.

Search by author

This selects a random book by the provided author. Each time this block is executed, a different book will be selected.

Search by subject

This selects a random book that includes the selected subject in the categories in OpenLibrary. Each time this block is executed, a different book will be selected.

Title, Author, Number of pages, Year, ISBN

These blocks let you use the attributes of the most recent book search result in the Scratch project.

Add cover to costume

This downloads a picture of the cover of the most recent book search result. It adds it as a costume to the sprite, and switches to it.

Try them for yourself

To try these blocks for yourself, you can access my fork of Scratch at

Simple project

This means that you can do something like this:

  • search for a random book by your favourite author
  • display the details of it in your Scratch project
  • switch your sprite costume to be a picture of the front cover

open screenshot in new window

Machine Learning project

To show an example of how this could be used as part of a machine learning project, I also wrote a new worksheet for Machine Learning for Kids.

The instructions guide you through how to use the new Books extension to collect examples of front covers for books on a subject of your choice. It shows you how to short them into two groups:

  • covers you like – covers that would encourage you to pick up a book, and maybe try reading it
  • covers you don’t like – covers that make you think maybe that book isn’t for you

The instructions then explain how to use these to train a machine learning model to predict whether you will like a new book cover.

This can be used to make a recommendation system in Scratch, that predicts what you will think of new book covers.

If you’d like to give this a try, you can find the instructions at

Tags: ,

Leave a Reply