client: JMAP calendar client#
Synchronous JMAP client.
Wraps session establishment, HTTP communication, and method dispatching into a single object with a clean public API.
Auth note: JMAP has no 401-challenge-retry dance (unlike CalDAV). Credentials are sent upfront on every request. A 401/403 is a hard failure.
- class calendaring_jmap.client.JMAPClient(url: str, username: str | None = None, password: str | None = None, auth=None, auth_type: str | None = None, timeout: int = 30)[source]#
Bases:
_JMAPClientBaseSynchronous JMAP client for calendar operations.
Usage:
from calendaring_jmap import get_jmap_client client = get_jmap_client(url="https://jmap.example.com/.well-known/jmap", username="alice", password="secret") calendars = client.get_calendars()
- Parameters:
url – URL of the JMAP session endpoint (
/.well-known/jmap).username – Username for Basic auth.
password – Password for Basic auth, or bearer token if no username.
auth – A pre-built requests-compatible auth object. Takes precedence over username/password if provided.
auth_type – Force a specific auth type:
"basic"or"bearer".timeout – HTTP request timeout in seconds.
- close() None[source]#
Release the persistent HTTP session and its connection pool.
Only needed when the client was not used as a context manager – the documented Quick Start builds one directly, and without this there was no way to hand the sockets back. Idempotent; the session is recreated on the next request.
- create_event(calendar_id: str, ical_str: str) str[source]#
Create a calendar event from an iCalendar string.
- Parameters:
calendar_id – The JMAP calendar ID to create the event in.
ical_str – A VCALENDAR string representing the event.
- Returns:
The server-assigned JMAP event ID.
- Raises:
JMAPMethodError – If the server rejects the create request.
- create_task(task_list_id: str, title: str, **kwargs) str[source]#
Create a task in a task list.
- Parameters:
task_list_id – The JMAP task list ID to create the task in.
title – Task title (maps to VTODO
SUMMARY).**kwargs – Optional JMAP Task fields using wire names:
description,due,start,timeZone,estimatedDuration,percentComplete,progress,priority.
- Returns:
The server-assigned JMAP task ID.
- Raises:
JMAPMethodError – If the server rejects the create request.
- delete_event(event_id: str) None[source]#
Delete a calendar event.
- Parameters:
event_id – The JMAP event ID to delete.
- Raises:
JMAPMethodError – If the server rejects the delete.
- delete_task(task_id: str) None[source]#
Delete a task.
- Parameters:
task_id – The JMAP task ID to delete.
- Raises:
JMAPMethodError – If the server rejects the delete.
- get_calendars() list[JMAPCalendar[Literal[False]]][source]#
Fetch all calendars for the authenticated account.
- Returns:
List of
JMAPCalendarobjects.
- get_event(event_id: str) JMAPCalendarObject[source]#
Fetch a calendar event by JMAP event ID.
- Parameters:
event_id – The JMAP event ID to retrieve.
- Returns:
A
JMAPCalendarObjectwrapping the raw JSCalendar dict.parentisNonesince noJMAPCalendaris available at the client level.- Raises:
JMAPMethodError – If the event is not found.
- get_objects_by_sync_token(sync_token: str) tuple[list[JMAPCalendarObject], list[JMAPCalendarObject], list[str], str][source]#
Fetch events changed since a previous sync token.
Calls
CalendarEvent/changesto discover which events were created, modified, or destroyed sincesync_tokenwas issued. Created and modified events are returned asJMAPCalendarObjectinstances; destroyed events are returned as IDs (the objects no longer exist on the server).- Parameters:
sync_token – A state string previously returned by
get_sync_token()or by a prior call to this method.- Returns:
added: objects for newly created events (parentisNone).modified: objects for updated events (parentisNone).deleted: Event IDs that were destroyed.new_sync_token: Pass to the next call to this method assync_token.
- Return type:
A 4-tuple
(added, modified, deleted, new_sync_token)- Raises:
JMAPMethodError – If the server reports
hasMoreChanges: true.
- get_sync_token() str[source]#
Return the current CalendarEvent state string for use as a sync token.
Calls
CalendarEvent/getwith an empty ID list — no event data is transferred, only thestatefield from the response.- Returns:
Opaque state string. Pass to
get_objects_by_sync_token()to retrieve only what changed since this point.
- get_task(task_id: str) dict[source]#
Fetch a task by ID.
- Parameters:
task_id – The JMAP task ID to retrieve.
- Returns:
Raw JMAP Task dict as returned by the server.
- Raises:
JMAPMethodError – If the task is not found.
- get_task_lists() list[dict][source]#
Fetch all task lists for the authenticated account.
- Returns:
List of raw JMAP TaskList dicts as returned by the server.
- search_events(calendar_id: str | None = None, start: str | None = None, end: str | None = None, text: str | None = None) list[JMAPCalendarObject][source]#
Search for calendar events.
All parameters are optional; omitting all returns every event in the account. Results are fetched in a single batched JMAP request using a result reference from
CalendarEvent/queryintoCalendarEvent/get.- Parameters:
calendar_id – Limit results to this calendar.
start – Only events ending after this datetime (
YYYY-MM-DDTHH:MM:SS).end – Only events starting before this datetime (
YYYY-MM-DDTHH:MM:SS).text – Free-text search across title, description, locations, and participants.
- Returns:
List of
JMAPCalendarObjectinstances.parentisNoneon these objects since noJMAPCalendaris available at the client level; useJMAPCalendar.search()if you needparentset.