gkeepapi Client for Google Keep

0.17.1 · active · verified Fri Apr 17

An unofficial Python client for the Google Keep API. It enables programmatic interaction with notes, lists, and reminders, supporting CRUD operations. The library is currently at version 0.17.1 and receives maintenance releases as needed to adapt to API changes or address issues.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to log in to Google Keep using an app password, create a new note, sync changes, and retrieve all notes. Environment variables are used for credentials for security. Remember to replace placeholders or set actual environment variables.

import os
from gkeepapi import Keep
from gkeepapi.exception import InvalidUsernameOrPassword

# Recommended: Use a Google App Password for programmatic access.
# Generate one at: myaccount.google.com/apppasswords
# Store in environment variables or directly replace placeholders.
USERNAME = os.environ.get('GKEEP_USERNAME', 'your_email@example.com')
APP_PASSWORD = os.environ.get('GKEEP_APP_PASSWORD', 'your_app_password')

if not USERNAME or not APP_PASSWORD or APP_PASSWORD == 'your_app_password':
    print("Please set GKEEP_USERNAME and GKEEP_APP_PASSWORD environment variables (or replace placeholders).")
    print("Consider using a Google App Password for better security.")
    exit(1)

keep = Keep()

try:
    # Login using username and app password
    success = keep.login(USERNAME, APP_PASSWORD)

    if success:
        print("Login successful!")

        # Create a new text note
        note = keep.createNote('gkeepapi Quickstart Note', 'This note was created programmatically.')
        print(f"Created note: '{note.title}' (ID: {note.id})")

        # Sync changes to Google Keep
        keep.sync()
        print("Changes synced.")

        # Fetch and print titles of all notes
        print("\nAll notes in Keep:")
        for n in keep.all():
            print(f"- {n.title}")

    else:
        print("Login failed for an unknown reason.")

except InvalidUsernameOrPassword:
    print("Login failed: Invalid username or app password. Double-check your credentials and ensure an App Password is used.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →