Open Library API
The Open Library is a project of the Internet Archive. Its goal is to create an online catalog that contains one web page for every book ever published. To do this, it accepts data from a variety of sources: libraries, publishers, book-sellers, and individuals.
Read API
Infogami provides an API to query the database for objects matching particular criteria or to
getan object from the database. All the requests take input either as part of the URL or query string. You can try sample requests and practice building requests in the API sandbox.
Querying for Objects (/things)
Getting an Object (/get)
Queries for Versions (/versions)
Search queries (/search)
The database structure, developed by the Open Library, is called infogami. Infogami stores a collection of objects, called "things". For example, on the Open Library site, each page, book, author, and user is a thing in the database. Each thing then has a series of arbitrary key-value pairs as properties. For example, a book thing may have the key "title" with the value "A Heartbreaking Work of Staggering Genius" and the key "genre" with the value "Memoir". Each collection of key-value pairs is stored as a version, along with the time it was saved and the person who saved it.
Because in infogami everything is an object, you can query for any object in infogami space, such as templates, editions, authors, or individual infogami fields in any page type. Each object has an object type. (List of types.) For example, there is
/type/editionwhich represents all of the information about a book, andtype/edition/isbn_10which is the property for the 10-character ISBN in the edition record.
Querying for Objects (/things)
To find objects matching a particular query, send a GET request to http://openlibrary.org/api/things with
queryas parameter. In this documentation we use curl as a simple command line query client; any software that supports httpGETcan be used.
The
querymust use JSON dictionary syntax.This query searches for all editions with a particular ISBN value, and returns the keys of all matching records. Since there can be only one book with the any ISBN, the result contains only one key. (In practice unfortunately you will see publishers have reused an ISBN for otherwise unrelated works.)
A curl request for the above, then, would read as follows:
$ curl -G --data-urlencode 'query={"type":"\/type\/edition", "isbn_10":"0789312239"}' \ http://openlibrary.org/api/thingsPattern matching
The API supports querying for objects based of string matching.
Here is an example to get all object with key starting from
/about/.Due to performance reasons,
*is allowed only at the end of a string.The Sort Directive
The
sortdirective can be used to tell Infogami to sort the results of a query before returning.The following query gives the list of all documents sorted in the order of their keys.
By default sort operation returns the results in the ascending order. To reverse that order, prepend minus (
-) to the value ofsortdirective.Limiting Queries
By default every results of every query are limited to 100 values. Alternate limit can be specified by using the
limitdirective.Here is an example to get first 10 templates.
The
offsetdirective can be used to ask infogami to give results from a specific offset.The following query gives the next 10 templates.
Expression AND in queries
All the keys in the query other than special directives (
sort,limit,offset) are implicitly ANDed.For example, the following query finds all objects having type as
/type/editionand author as Mark Twain (/a/OL18319A).Getting an Object (/get)
In Infogami, every object is identified by a unique key. In the example above, we queried the database on an ISBN and were returned the unique key for the edition that matches that ISBN. We can then retrieve the edition with a
getcommand:$ curl http://openlibrary.org/api/get?key=/b/OL1001932MThis returns:
{ "status": "ok", "result": { "subject_place": [ "Venice (Italy)"], "lc_classifications": [ "DG674.2 .S3 2005" ], "latest_revision": 1, "genres": [ "Juvenile literature."], "title": "This is Venice", "languages": [ { "key": "\/l\/eng" }], "subjects": [ "Venice (Italy) -- Description and travel -- Juvenile literature."], "publish_country": "nyu", "by_statement": "M. Sasek.","type": { "key": "\/type\/edition" }, "revision": 1, publishers": [ "Universe"], "last_modified": "2008-04-01T03:28:50.625462", "key": "\/b\/OL3315616M", "authors": [ { "key": "\/a\/OL1396639A" } ], "publish_places": [ "New York, NY" ], "pagination": "56 p. :", "lccn": [ "2004110229" ], "notes": "\"A children's classic\"--Cover.\nOriginally published: New York : Macmillan, 1961.", "number_of_pages": 56, "isbn_10": [ "0789312239" ], publish_date": "2005" }}Because this string is hard to read, you may want to add the parameter "prettyprint=true" when you are testing your queries.
$ curl http://openlibrary.org/api/get?key=/b/OL1001932M&prettyprint=trueThis returns a more eye-readable version of the same string.
# response { "status": "ok", "result": { "subject_place": "Venice (Italy)", "lc_classifications": "DG674.2 .S3 2005", "latest_revision": 1, "genres": [ "Juvenile literature." ], "title": "This is Venice", "languages": [ { "key": "\/l\/eng" } ], "subjects": [ "Venice (Italy) -- Description and travel -- Juvenile literature." ], "publish_country": "nyu", "by_statement": "M. Sasek.", "type": { "key": "\/type\/edition" }, "revision": 1, "publishers": [ "Universe" ], "last_modified": "2008-04-01T03:28:50.625462", "key": "\/b\/OL3315616M", "authors": [ { "key": "\/a\/OL1396639A" } ], "publish_places": [ "New York, NY" ], "pagination": "56 p. :", "lccn": [ "2004110229" ], "notes": "\"A children's classic\"--Cover.\nOriginally published: New York : Macmillan, 1961.", "number_of_pages": 56, "isbn_10": [ "0789312239" ], "publish_date": "2005" } }The following example gets the page
/pagelistusing the API.$ curl http://openlibrary.org/api/get?key=/pagelist?prettyprint=true { "status": "ok", "result": { "body": "{{PageList(\"\/\")}}", "title": "Page List", "last_modified": "2008-04-18T09:19:56.978194", "latest_revision": 1, "key": "\/pagelist", "type": {"key": "\/type\/page"}, "revision": 1 } }
Since the response is in JSON format, the Content-Type is set to
application/json, which may not be displayed by the browsers as text. To enable thattext=truemust be passed in the query string.Queries for Versions (/versions)
In Infogami, modification of every object creates a new version of that object. To find versions matching a particular query, send a GET request to http://openlibrary.org/api/versions with
queryas parameter. Thequerymust be a JSON dictionary, just like the things query. Thesortandlimitdirectives work similar to the things query.For example the following query finds the most 10 versions of
/object.
# Query { "key": "/", "limit": 3, "sort": "-created" }⇒ # Response { "status": "ok", "result": [ { "comment": "", "created": "2008-04-18T15:40:04.279578", "ip": "207.241.226.140", "author": "/user/webchick", "thing_id": 9875590, "key": "/", "id": 9894268, "machine_comment": null, "revision": 14 }, { "comment": "", "created": "2008-04-18T15:39:30.588136", "ip": "207.241.226.140", "author": "/user/webchick", "thing_id": 9875590, "key": "/", "id": 9894267, "machine_comment": null, "revision": 13 }, { "comment": "", "created": "2008-04-16T00:18:32.743829", "ip": "207.241.226.140", "author": "/user/webchick", "thing_id": 9875590, "key": "/", "id": 9894257, "machine_comment": null, "revision": 12 } ] }Search queries (/search)
There is an incomplete search API as the final interface has not been decided. Only rudimentary search functions are supported for now. Development in progress is being discussed in the Open Library bug tracker at https://bugs.launchpad.net/openlibrary/+bug/236947; interested parties are invited to post comments and requests in that tracker item.
A search API query is a JSON dictionary passed as the "q" http parameter. The dictionary just one meaningful entry, "query". The response is a json object containing a list of openlibrary id's. The optional argument "prettyprint" http parameter controls formatting of the response, as above. In the example below, the query is
http://openlibrary.org/api/search?q={"query":"Felix Klein"}&prettyprint=true
# Query { "query": "Felix Klein", }⇒ # Response { "status": "ok", "result": [ "/b/OL1618362M", "/b/OL3253308M", "/b/OL2532653M", "/b/OL2628261M", "/b/OL5501881M", "/b/OL1299055M", "/b/OL2099784M", "/b/OL2418293M", "/b/OL3303109M", "/b/OL4412463M", "/b/OL5068782M", "/b/OL5305191M", "/b/OL5550601M", "/b/OL5550830M", "/b/OL5550831M", "/b/OL5876614M","/b/OL5888524M", "/b/OL6088137M", "/b/OL6088190M", "/b/OL6272774M" ]}
Performance Issues
To have a bound on the amount of resources consumed by a query, the runtime of each query is limited to 60 sec. Any query that takes longer is aborted.