gkeepapi package¶
Submodules¶
gkeepapi.node module¶
- members:
- inherited-members:
- class gkeepapi.node.Blob(parent_id: str | None = None, **kwargs: dict)[source]¶
Bases:
Node
Represents a Google Keep blob.
- blob¶
- class gkeepapi.node.BlobType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Valid blob types.
- Audio = 'AUDIO'¶
Audio
- Drawing = 'DRAWING'¶
Drawing
- Image = 'IMAGE'¶
Image
- class gkeepapi.node.Category[source]¶
Bases:
Annotation
Represents a category annotation on a
TopLevelNode
.- property category: CategoryValue¶
Get the category.
- Returns:
The category.
- class gkeepapi.node.CategoryValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Valid note categories.
- Books = 'BOOKS'¶
Books
- Food = 'FOOD'¶
Food
- Movies = 'MOVIES'¶
Movies
- Music = 'MUSIC'¶
Music
- Places = 'PLACES'¶
Places
- Quotes = 'QUOTES'¶
Quotes
- TV = 'TV'¶
TV
- Travel = 'TRAVEL'¶
Travel
- class gkeepapi.node.CheckedListItemsPolicyValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Movement setting for checked list items.
- Default = 'DEFAULT'¶
Default
- Graveyard = 'GRAVEYARD'¶
Graveyard
- class gkeepapi.node.ColorValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Valid note colors.
- Blue = 'BLUE'¶
Blue
- Brown = 'BROWN'¶
Brown
- DarkBlue = 'CERULEAN'¶
Dark blue
- Gray = 'GRAY'¶
Gray
- Green = 'GREEN'¶
Green
- Orange = 'ORANGE'¶
Orange
- Pink = 'PINK'¶
Pink
- Purple = 'PURPLE'¶
Purple
- Red = 'RED'¶
Red
- Teal = 'TEAL'¶
Teal
- White = 'DEFAULT'¶
White
- Yellow = 'YELLOW'¶
Yellow
- class gkeepapi.node.Context[source]¶
Bases:
Annotation
Represents a context annotation, which may contain other annotations.
- all() list[Annotation] [source]¶
Get all sub annotations.
- Returns:
Sub Annotations.
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
- class gkeepapi.node.Element[source]¶
Bases:
object
Interface for elements that can be serialized and deserialized.
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
- class gkeepapi.node.GraveyardStateValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Visibility setting for the graveyard.
- Collapsed = 'COLLAPSED'¶
Collapsed
- Expanded = 'EXPANDED'¶
Expanded
- class gkeepapi.node.Label[source]¶
Bases:
Element
,TimestampsMixin
Represents a label.
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
- id¶
- property merged: datetime¶
Get last merge datetime.
- Returns:
Datetime.
- property name: str¶
Get the label name.
- Returns:
Label name.
- timestamps: NodeTimestamps¶
- class gkeepapi.node.List(**kwargs: dict)[source]¶
Bases:
TopLevelNode
Represents a Google Keep list.
- SORT_DELTA = 10000¶
- add(text: str, checked: bool = False, sort: NewListItemPlacementValue | int | None = None) ListItem [source]¶
Add a new item to the list.
- Parameters:
text – The text.
checked – Whether this item is checked.
sort – Item id for sorting or a placement policy.
- collaborators¶
- labels¶
- sort_items(key: Callable = operator.attrgetter('text'), reverse: bool = False) None [source]¶
Sort list items in place. By default, the items are alphabetized, but a custom function can be specified.
- Parameters:
key – A filter function.
reverse – Whether to reverse the output.
- classmethod sorted_items(items: list[ListItem]) list[ListItem] [source]¶
Generate a list of sorted list items, taking into account parent items.
- Parameters:
items – Items to sort.
- Returns:
Sorted items.
- property text: str¶
Get the text value.
- Returns:
Text value.
- class gkeepapi.node.ListItem(parent_id: str | None = None, parent_server_id: str | None = None, super_list_item_id: str | None = None, **kwargs: dict)[source]¶
Bases:
Node
Represents a Google Keep listitem.
Interestingly enough,
Note`s store their content in a single child :class:`ListItem
.- add(text: str, checked: bool = False, sort: NewListItemPlacementValue | int | None = None) ListItem [source]¶
Add a new sub item to the list. This item must already be attached to a list.
- Parameters:
text – The text.
checked – Whether this item is checked.
sort – Item id for sorting.
- property checked: bool¶
Get the checked state.
- Returns:
Whether this item is checked.
- dedent(node: ListItem, dirty: bool = True) None [source]¶
Dedent an item. Does nothing if the target is not indented under this item.
- Parameters:
node – Item to dedent.
dirty – Whether this node should be marked dirty.
- indent(node: ListItem, dirty: bool = True) None [source]¶
Indent an item. Does nothing if the target has subitems.
- Parameters:
node – Item to indent.
dirty – Whether this node should be marked dirty.
- property indented: bool¶
Get indentation state.
- Returns:
Whether this item is indented.
- parent_item¶
- parent_server_id¶
- prev_super_list_item_id¶
- save(clean: bool = True) dict [source]¶
Serialize into raw representation. Clears the dirty bit by default.
- Parameters:
clean – Whether to clear the dirty bit.
- Returns:
Raw.
- super_list_item_id¶
- class gkeepapi.node.NewListItemPlacementValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Target location to put new list items.
- Bottom = 'BOTTOM'¶
Bottom
- Top = 'TOP'¶
Top
- class gkeepapi.node.Node(id_: str | None = None, type_: str | None = None, parent_id: str | None = None)[source]¶
Bases:
Element
,TimestampsMixin
Node base class.
- annotations¶
- append(node: Node, dirty: bool = True) Node [source]¶
Add a new child node.
- Parameters:
node – Node to add.
dirty – Whether this node should be marked dirty.
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
- get(node_id: str) Node | None [source]¶
Get child node with the given ID.
- Parameters:
node_id – The node ID.
- Returns:
Child node.
- id¶
- property new: bool¶
Get whether this node has been persisted to the server.
- Returns:
True if node is new.
- parent¶
- parent_id¶
- remove(node: Node, dirty: bool = True) None [source]¶
Remove the given child node.
- Parameters:
node – Node to remove.
dirty – Whether this node should be marked dirty.
- save(clean: bool = True) dict [source]¶
Serialize into raw representation. Clears the dirty bit by default.
- Parameters:
clean – Whether to clear the dirty bit.
- Returns:
Raw.
- server_id¶
- settings¶
- property sort: int¶
Get the sort id.
- Returns:
Sort id.
- property text: str¶
Get the text value.
- Returns:
Text value.
- timestamps: NodeTimestamps¶
- type¶
- property version: int¶
Get the node version.
- Returns:
Version.
- class gkeepapi.node.NodeAnnotations[source]¶
Bases:
Element
Represents the annotation container on a
TopLevelNode
.- all() list[Annotation] [source]¶
Get all annotations.
- Returns:
Annotations.
- append(annotation: Annotation) Annotation [source]¶
Add an annotation.
- Parameters:
annotation – An Annotation object.
- Returns:
The Annotation.
- property category: CategoryValue | None¶
Get the category.
- Returns:
The category.
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
- classmethod from_json(raw: dict) Annotation | None [source]¶
Helper to construct an annotation from a dict.
- Parameters:
raw – Raw annotation representation.
- Returns:
An Annotation object or None.
- remove(annotation: Annotation) None [source]¶
Removes an annotation.
- Parameters:
annotation – An Annotation object.
- class gkeepapi.node.NodeAudio[source]¶
Bases:
NodeBlob
Represents an audio blob.
- property length: int¶
Get length of the audio clip.
- Returns:
Audio length.
- class gkeepapi.node.NodeBlob(type_: str | None = None)[source]¶
Bases:
Element
Represents a blob descriptor.
- blob_id¶
- type¶
- class gkeepapi.node.NodeCollaborators[source]¶
Bases:
Element
Represents the collaborators on a
TopLevelNode
.- load(collaborators_raw: list, requests_raw: list) None [source]¶
Unserialize from raw representation. (Wrapper)
- Parameters:
raw – Raw.
- Raises:
ParseException – If there was an error parsing data.
- class gkeepapi.node.NodeDrawing[source]¶
Bases:
NodeBlob
Represents a drawing blob.
- property extracted_text: str¶
Get text extracted from image
- Returns:
Extracted text.
- class gkeepapi.node.NodeDrawingInfo[source]¶
Bases:
Element
Represents information about a drawing blob.
- drawing_id¶
- save(clean: bool = True) dict [source]¶
Serialize into raw representation. Clears the dirty bit by default.
- Parameters:
clean – Whether to clear the dirty bit.
- Returns:
Raw.
- snapshot¶
- class gkeepapi.node.NodeImage[source]¶
Bases:
NodeBlob
Represents an image blob.
- property byte_size: int¶
Get size of image in bytes.
- Returns:
Image byte size.
- property extracted_text: str¶
Get text extracted from image
- Returns:
Extracted text.
- property height: int¶
Get height of image.
- Returns:
Image height.
- property url: str¶
Get a url to the image.
- Returns:
Image url.
- property width: int¶
Get width of image.
- Returns:
Image width.
- class gkeepapi.node.NodeLabels[source]¶
Bases:
Element
Represents the labels on a
TopLevelNode
.
- class gkeepapi.node.NodeSettings[source]¶
Bases:
Element
Represents the settings associated with a
TopLevelNode
.- property checked_listitems_policy: CheckedListItemsPolicyValue¶
Get the policy for checked listitems.
- Returns:
Policy.
- property graveyard_state: GraveyardStateValue¶
Get the visibility state for the list graveyard.
- Returns:
Visibility.
- property new_listitem_placement: NewListItemPlacementValue¶
Get the default location to insert new listitems.
- Returns:
Placement.
- class gkeepapi.node.NodeTimestamps(create_time: float | None = None)[source]¶
Bases:
Element
Represents the timestamps associated with a
TopLevelNode
.- TZ_FMT = '%Y-%m-%dT%H:%M:%S.%fZ'¶
- property created: datetime¶
Get the creation datetime.
- Returns:
Datetime.
- property deleted: datetime | None¶
Get the deletion datetime.
- Returns:
Datetime.
- classmethod dt_to_str(dt: datetime) str [source]¶
Convert a datetime to a str.
- Params:
dt: Datetime.
- Returns:
Datetime string.
- property edited: datetime¶
Get the user edited datetime.
- Returns:
Datetime.
- classmethod int_to_dt(tz: float) datetime [source]¶
Convert a unix timestamp into an object.
- Params:
ts: Unix timestamp.
- Returns:
Datetime.
- classmethod int_to_str(tz: int) str [source]¶
Convert a unix timestamp to a str.
- Returns:
Datetime string.
- classmethod str_to_dt(tzs: str | None) datetime [source]¶
Convert a datetime string into an object.
- Params:
tsz: Datetime string.
- Returns:
Datetime.
- property trashed: datetime | None¶
Get the move-to-trash datetime.
- Returns:
Datetime.
- property updated: datetime¶
Get the updated datetime.
- Returns:
Datetime.
- class gkeepapi.node.NodeType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Valid note types.
- Blob = 'BLOB'¶
A blob (attachment)
- List = 'LIST'¶
A List
- ListItem = 'LIST_ITEM'¶
A List item
- Note = 'NOTE'¶
A Note
- class gkeepapi.node.Note(**kwargs: dict)[source]¶
Bases:
TopLevelNode
Represents a Google Keep note.
- property text: str¶
Get the text value.
- Returns:
Text value.
- class gkeepapi.node.RoleValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Collaborator role type.
- Owner = 'O'¶
Note owner.
- User = 'W'¶
Note collaborator.
- class gkeepapi.node.Root[source]¶
Bases:
Node
Internal root node.
- ID = 'root'¶
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
Bases:
Enum
Collaborator change type.
Grant access.
Remove access.
- class gkeepapi.node.SuggestValue(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Valid task suggestion categories.
- GroceryItem = 'GROCERY_ITEM'¶
Grocery item
- class gkeepapi.node.TaskAssist[source]¶
Bases:
Annotation
Unknown.
- property suggest: str¶
Get the suggestion.
- Returns:
The suggestion.
- class gkeepapi.node.TimestampsMixin[source]¶
Bases:
object
A mixin to add methods for updating timestamps.
- property deleted: bool¶
Get the deleted state.
- Returns:
Whether this item is deleted.
- touch(edited: bool = False) None [source]¶
Mark the node as dirty.
- Parameters:
edited – Whether to set the edited time.
- property trashed: bool¶
Get the trashed state.
- Returns:
Whether this item is trashed.
- class gkeepapi.node.TopLevelNode(**kwargs: dict)[source]¶
Bases:
Node
Top level node base class.
- property archived: bool¶
Get the archive state.
- Returns:
Whether this node is archived.
- collaborators¶
- property color: ColorValue¶
Get the node color.
- Returns:
Color.
- property dirty: bool¶
Get dirty state.
- Returns:
Whether this element is dirty.
- property drawings: list[NodeDrawing]¶
Get all drawing blobs
- labels¶
- property pinned: bool¶
Get the pin state.
- Returns:
Whether this node is pinned.
- save(clean: bool = True) dict [source]¶
Serialize into raw representation. Clears the dirty bit by default.
- Parameters:
clean – Whether to clear the dirty bit.
- Returns:
Raw.
- property title: str¶
Get the title.
- Returns:
Title.
- property url: str¶
Get the url for this node.
- Returns:
Google Keep url.
- class gkeepapi.node.WebLink[source]¶
Bases:
Annotation
Represents a link annotation on a
TopLevelNode
.- property description: str | None¶
Get the link description.
- Returns:
The link description or None.
- property image_url: str | None¶
Get the link image url.
- Returns:
The image url or None.
- property provenance_url: str¶
Get the provenance url.
- Returns:
The provenance url.
- property title: str | None¶
Get the link title.
- Returns:
The link title or None.
- property url: str¶
Get the link url.
- Returns:
The link url.
Module contents¶
- class gkeepapi.API(base_url: str, auth: APIAuth | None = None)[source]¶
Bases:
object
Base API wrapper
- RETRY_CNT = 2¶
- getAuth() APIAuth [source]¶
Get authentication details for this API.
- Returns:
The auth object
- Return type:
auth
- send(**req_kwargs: dict) dict [source]¶
Send an authenticated request to a Google API. Automatically retries if the access token has expired.
- Parameters:
**req_kwargs – Arbitrary keyword arguments to pass to Requests.
- Returns:
The parsed JSON response.
- Raises:
APIException – If the server returns an error.
LoginException – If session is not authenticated.
- class gkeepapi.APIAuth(scopes: str)[source]¶
Bases:
object
Authentication token manager
- load(email: str, master_token: str, device_id: str) bool [source]¶
Authenticate to Google with the provided master token.
- Parameters:
email – The account to use.
master_token – The master token.
device_id – An identifier for this client.
- Raises:
LoginException – If there was a problem logging in.
- login(email: str, password: str, device_id: str) None [source]¶
Authenticate to Google with the provided credentials.
- Parameters:
email – The account to use.
password – The account password.
device_id – An identifier for this client.
- Raises:
LoginException – If there was a problem logging in.
- refresh() str [source]¶
Refresh the OAuth token.
- Returns:
The auth token.
- Raises:
LoginException – If there was a problem refreshing the OAuth token.
- class gkeepapi.Keep[source]¶
Bases:
object
High level Google Keep client.
Manipulates a local copy of the Keep node tree. First, obtain a master token for your account.
To start, first authenticate:
keep.authenticate('...', '...')
Individual Notes can be retrieved by id:
some_note = keep.get('some_id')
New Notes can be created:
new_note = keep.createNote()
These Notes can then be modified:
some_note.text = 'Test' new_note.text = 'Text'
These changes are automatically detected and synced up with:
keep.sync()
- OAUTH_SCOPES = 'oauth2:https://www.googleapis.com/auth/memento https://www.googleapis.com/auth/reminders'¶
- add(node: Node) None [source]¶
Register a top level node (and its children) for syncing up to the server. There’s no need to call this for nodes created by
createNote()
orcreateList()
as they are automatically added.- Parameters:
node – The node to sync.
- Raises:
InvalidException – If the parent node is not found.
- all() list[TopLevelNode] [source]¶
Get all Notes.
- Returns:
All notes.
- authenticate(email: str, master_token: str, state: dict | None = None, sync: bool = True, device_id: str | None = None) None [source]¶
Authenticate to Google with the provided master token & sync.
- Parameters:
email – The account to use.
master_token – The master token.
state – Serialized state to load.
sync – Whether to sync data.
device_id – Device id.
- Raises:
LoginException – If there was a problem logging in.
- createLabel(name: str) Label [source]¶
Create a new label.
- Parameters:
name – Label name.
- Returns:
The new label.
- Raises:
LabelException – If the label exists.
- createList(title: str | None = None, items: list[tuple[str, bool]] | None = None) List [source]¶
Create a new list and populate it. Any changes to the note will be uploaded when
sync()
is called.- Parameters:
title – The title of the list.
items – A list of tuples. Each tuple represents the text and checked status of the listitem.
- Returns:
The new list.
- createNote(title: str | None = None, text: str | None = None) Node [source]¶
Create a new managed note. Any changes to the note will be uploaded when
sync()
is called.- Parameters:
title – The title of the note.
text – The text of the note.
- Returns:
The new note.
- find(query: Pattern | str | None = None, func: Callable | None = None, labels: list[str] | None = None, colors: list[str] | None = None, pinned: bool | None = None, archived: bool | None = None, trashed: bool = False) Iterator[TopLevelNode] [source]¶
Find Notes based on the specified criteria.
- Parameters:
query – A str or regular expression to match against the title and text.
func – A filter function.
labels – A list of label ids or objects to match. An empty list matches notes with no labels.
colors – A list of colors to match.
pinned – Whether to match pinned notes.
archived – Whether to match archived notes.
trashed – Whether to match trashed notes.
- Returns:
Search results.
- findLabel(query: Pattern | str, create: bool = False) Label | None [source]¶
Find a label with the given name.
- Parameters:
query – A str or regular expression to match against the name.
create – Whether to create the label if it doesn’t exist (only if name is a str).
- Returns:
The label.
- get(node_id: str) TopLevelNode [source]¶
Get a note with the given ID.
- Parameters:
node_id – The note ID.
- Returns:
The Note or None if not found.
- getLabel(label_id: str) Label | None [source]¶
Get an existing label.
- Parameters:
label_id – Label id.
- Returns:
The label.
- getMediaLink(blob: Blob) str [source]¶
Get the canonical link to media.
- Parameters:
blob – The media resource.
- Returns:
A link to the media.
- load(auth: APIAuth, state: dict | None = None, sync: bool = True) None [source]¶
Authenticate to Google with a prepared authentication object & sync.
- Parameters:
auth – Authentication object.
state – Serialized state to load.
sync – Whether to sync data.
- Raises:
LoginException – If there was a problem logging in.
- login(email: str, password: str, state: dict | None = None, sync: bool = True, device_id: str | None = None) None [source]¶
Authenticate to Google with the provided credentials & sync.
This flow is discouraged.
- Parameters:
email – The account to use.
password – The account password.
state – Serialized state to load.
sync – Whether to sync data.
device_id – Device id.
- Raises:
LoginException – If there was a problem logging in.
- restore(state: dict) None [source]¶
Unserialize saved note data.
- Parameters:
state – Serialized state to load.
- resume(email: str, master_token: str, state: dict | None = None, sync: bool = True, device_id: str | None = None) None [source]¶
- sync(resync: bool = False) None [source]¶
Sync the local Keep tree with the server. If resyncing, local changes will be destroyed. Otherwise, local changes to notes, labels and reminders will be detected and synced up.
- Parameters:
resync – Whether to resync data.
- Raises:
SyncException – If there is a consistency issue.
- class gkeepapi.KeepAPI(auth: APIAuth | None = None)[source]¶
Bases:
API
Low level Google Keep API client. Mimics the Android Google Keep app.
You probably want to use
Keep
instead.- API_URL = 'https://www.googleapis.com/notes/v1/'¶
- changes(target_version: str | None = None, nodes: list[dict] | None = None, labels: list[dict] | None = None) dict [source]¶
Sync up (and down) all changes.
- Parameters:
target_version – The local change version.
nodes – A list of nodes to sync up to the server.
labels – A list of labels to sync up to the server.
- Returns:
Description of all changes.
- Raises:
APIException – If the server returns an error.
- class gkeepapi.MediaAPI(auth: APIAuth | None = None)[source]¶
Bases:
API
Low level Google Media API client. Mimics the Android Google Keep app.
You probably want to use
Keep
instead.- API_URL = 'https://keep.google.com/media/v2/'¶
- class gkeepapi.RemindersAPI(auth: APIAuth | None = None)[source]¶
Bases:
API
Low level Google Reminders API client. Mimics the Android Google Keep app.
You probably want to use
Keep
instead.- API_URL = 'https://www.googleapis.com/reminders/v1internal/reminders/'¶
- create(node_id: str, node_server_id: str, dtime: datetime) Any [source]¶
Create a new reminder.
- Parameters:
node_id – The note ID.
node_server_id – The note server ID.
dtime – The due date of this reminder.
Return: ???
- Raises:
APIException – If the server returns an error.
- delete(node_server_id: str) Any [source]¶
Delete an existing reminder.
- Parameters:
node_server_id – The note server ID.
Return: ???
- Raises:
APIException – If the server returns an error.
- history(storage_version: str) Any [source]¶
Get reminder changes.
- Parameters:
storage_version – The local storage version.
- Returns:
???
- Raises:
APIException – If the server returns an error.