OAuth for iCloud developer guide

Turn Apple Books Highlights into Study Material

Apple Books keeps each highlight and note as a row in a local SQLite database that iCloud syncs to your Mac. One SQL join maps every annotation to its book and returns rows for flashcards, Obsidian or JSON.

Figment editorial teamPublished Updated Facts checked November 12, 2026

Apple Books stores every highlight and attached note as a row in a local SQLite database that iCloud syncs to your Mac, so no export button is needed. A SQL query joins each annotation to its source book and returns structured rows ready for Anki, Obsidian, or any tool that accepts JSON.

What does Apple Books record when I highlight?

Each highlight creates a row in the ZAEANNOTATION table, inside:

~/Library/Containers/com.apple.iBooksX/Data/Documents/AEAnnotation/*.sqlite
ColumnWhat it holds
ZANNOTATIONASSETIDForeign key linking this annotation to its book
ZANNOTATIONSELECTEDTEXTThe exact text you highlighted
ZANNOTATIONNOTEYour typed note, if any
ZANNOTATIONSTYLEAnnotation style as an integer; community sources observe values 0–5 including one for underline; Apple does not publish the integer-to-name mapping
ZANNOTATIONCREATIONDATECreation timestamp in Apple Core Data format (seconds since 1 January 2001)
ZANNOTATIONMODIFICATIONDATELast-edited timestamp
ZANNOTATIONDELETEDSoft-delete flag; 1 means removed in the app

Filter WHERE ZANNOTATIONDELETED = 0 to skip deleted annotations. Deleting in the app flips the flag, and the row stays in the database until the app data is cleared.

Apple timestamps use the Core Data epoch: 1 January 2001, which is 978,307,200 seconds after the Unix epoch. Add that offset before calling datetime() in SQLite or converting in code.

How do highlights from my iPhone reach the Mac?

They sync through iCloud, and two settings must both be on.

System Settings (macOS 13+): Open the Apple menu, choose System Settings, click your name, then iCloud › Drive. Turn on Sync this Mac, open Apps Syncing to iCloud Drive, and enable Books.

Books app: Open Books, choose Books › Settings › General, and select Reading Now and Collections, bookmarks, and highlights (Apple iCloud setup guide).

With both on, annotations from every signed-in Apple device appear in the same SQLite files on the Mac. Sync is not instant, so a workflow that reads these files should tolerate incomplete results on the first run.

Highlighting is not available for all book types (Apple Support). Content where the app disables highlighting produces no rows in ZAEANNOTATION.

How do I map each highlight to its title and author?

Join the annotation database to the library database. Book metadata lives in a separate file:

~/Library/Containers/com.apple.iBooksX/Data/Documents/BKLibrary/*.sqlite

That database holds ZBKLIBRARYASSET with columns ZASSETID, ZTITLE, and ZAUTHOR. Because the two files are separate SQLite databases, use ATTACH DATABASE to link them in one session. The query below maps every active highlight to its source book and is the core of a study-material workflow:

-- Open the AEAnnotation database first (e.g. in DB Browser for SQLite),
-- then run this query. File paths must match your actual Mac username.
-- Untested example — confirm paths and schema before use in production.

ATTACH DATABASE
  '/Users/YOUR_USERNAME/Library/Containers/com.apple.iBooksX/Data/Documents/BKLibrary/BKLibrary-1-091020131601.sqlite'
  AS bk;

SELECT
  bk.ZBKLIBRARYASSET.ZTITLE                                                   AS book_title,
  bk.ZBKLIBRARYASSET.ZAUTHOR                                                  AS author,
  a.ZANNOTATIONSELECTEDTEXT                                                    AS highlight,
  a.ZANNOTATIONNOTE                                                            AS note,
  a.ZANNOTATIONSTYLE                                                           AS color_index,
  datetime(a.ZANNOTATIONCREATIONDATE + 978307200, 'unixepoch', 'localtime')   AS created_at
FROM  ZAEANNOTATION         AS a
JOIN  bk.ZBKLIBRARYASSET    ON bk.ZBKLIBRARYASSET.ZASSETID = a.ZANNOTATIONASSETID
WHERE a.ZANNOTATIONDELETED  = 0
ORDER BY book_title, created_at;

The BKLibrary filename includes a date string that may differ on your Mac. List ~/Library/Containers/com.apple.iBooksX/Data/Documents/BKLibrary/ to find the exact filename before connecting.

What can I make from the raw rows?

Each row holds the book title, author, highlight text, your note, the color index, and a timestamp. That maps onto several study formats:

  • Flashcards. A note attached to a highlight makes a natural answer side, and the highlighted sentence is the prompt. Tools like Anki (via AnkiConnect) accept JSON input and can ingest these rows in bulk.
  • Chapter outline. Order rows by book_title then created_at for a chronological record of what you marked in each book.
  • Spaced-repetition export. Export rows to JSON, keep created_at on each object, and import into any SRS tool that accepts a standard format.

The snippet below builds that JSON from Python. It is an untested design reference, so confirm file paths and schema details before production use:

# Integration design — untested; confirm paths and schema before shipping.
import sqlite3

EPOCH_OFFSET = 978_307_200  # seconds between 1970-01-01 and 2001-01-01

def load_highlights(ae_path: str, bk_path: str) -> list[dict]:
    con = sqlite3.connect(ae_path)
    con.execute(f"ATTACH DATABASE '{bk_path}' AS bk")
    cur = con.execute("""
        SELECT
            bk.ZBKLIBRARYASSET.ZTITLE,
            bk.ZBKLIBRARYASSET.ZAUTHOR,
            a.ZANNOTATIONSELECTEDTEXT,
            a.ZANNOTATIONNOTE,
            a.ZANNOTATIONSTYLE,
            a.ZANNOTATIONCREATIONDATE + 978307200
        FROM  ZAEANNOTATION AS a
        JOIN  bk.ZBKLIBRARYASSET
              ON bk.ZBKLIBRARYASSET.ZASSETID = a.ZANNOTATIONASSETID
        WHERE a.ZANNOTATIONDELETED = 0
        ORDER BY 1, 6
    """)
    return [
        {
            "book":      r[0],
            "author":    r[1],
            "highlight": r[2],
            "note":      r[3],
            "color":     r[4],
            "ts":        r[5],
        }
        for r in cur.fetchall()
    ]

Does Apple Books already export highlights?

Yes, in small amounts. You can Control-click a note or highlight and share it through AirDrop, Mail, Messages, or another app (Apple Support). Quote sharing is available in the United States and is limited to 200 words. For interactive books, the app converts highlights into study cards automatically, with no code (Apple Books study cards).

The SQLite approach is worth the extra step when you need bulk extraction, programmatic source-book mapping, or integration with an external tool that Apple's sharing sheet does not support.

What are the limits of this workflow?

  • Not all books support highlights. DRM-protected titles and certain publisher-restricted formats may produce no rows in ZAEANNOTATION even when the book appears in the library.
  • No protected content. This workflow reads annotations: your highlighted selections and typed notes. It does not provide DRM bypass or bulk export of the underlying book text.
  • PDFs versus EPUBs. Both formats can live in Apple Books, but the annotation table structure may differ. Test your query against the content types in your library before treating a schema assumption as universal.
  • Soft-delete is not permanent delete. Rows with ZANNOTATIONDELETED = 1 stay in the database until the app data is cleared. Confirm the filter is applied if your workflow produces duplicates on later runs.
  • Sync timing. Run an annotation pipeline only after iCloud Books sync has completed. A pipeline that starts while the database is still receiving changes may miss recent highlights.

How do I build this for multiple users?

Each user's Books data lives on their own device, so a product serving several users needs per-user access. Figment's OAuth for iCloud provides per-user Apple account access on a hosted Mac through a Figment consent flow. Your app receives a Figment access token and never the user's Apple password. The connection endpoint confirms service readiness:

GET https://figment.so/api/icloud/v1/connections/{connection_id}
Authorization: Bearer ACCESS_TOKEN

The response is {connection: {id, mode, services, ...}}, where mode is sandbox or live.

There is currently no public Figment REST endpoint for Books annotations. The SQLite extraction design above is an Apple-native local workflow. For a multi-user implementation you would run that same logic on the hosted Mac as a developer-owned process, within the bounds of the connection and the Apple Books sync state. Sandbox access is free, and plans are $14 or $29 per month per connected Apple Account. Register your app and start with the sandbox at /icloud/developers.

For the full OAuth and PKCE reference, see OAuth for iCloud: Connect Apple Data to Your App. For other native Apple data sources, see Connect Apple Notes, Photos, Files, and Safari.

Next step: Connect Apple Account to register your app and start with the sandbox.

Related reading:

Connect Apple data to your app

Register your app and start with synthetic sandbox data. Choose the permissions your app needs.

Connect Apple Account

Sandbox is free. Live access is $14 or $29 per connected Apple Account, per month.