跳转至

events

feishu.calendar.events

EventsNamespace

Bases: Namespace

日程接口命名空间。

通过 client.calendar.events 访问,封装飞书日历中日程(event)相关的服务端接口,包括日程的创建、 查询、更新、删除与列举等能力。日程隶属于某个日历,以 event_id 标识。

通常无需直接实例化,应通过 client.calendar.events 访问。

飞书文档

日程

源代码位于: feishu/calendar/events.py
Python
class EventsNamespace(Namespace):
    r"""
    日程接口命名空间。

    通过 `client.calendar.events` 访问,封装飞书日历中日程(event)相关的服务端接口,包括日程的创建、
    查询、更新、删除与列举等能力。日程隶属于某个日历,以 `event_id` 标识。

    通常无需直接实例化,应通过 `client.calendar.events` 访问。

    飞书文档:
        [日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/create)
    """

    async def create(
        self, calendar_id: str, event: dict[str, Any], *, idempotency_key: str | None = None
    ) -> NestedDict:
        r"""
        创建日程。

        `event` 是描述待创建日程的请求体,原样作为 JSON 发送,常见键包括 `summary`、
        `description`、`start_time`、`end_time`、`vchat`、`visibility`、`reminders` 等。
        仅当显式传入 `idempotency_key` 时才将其并入查询参数,用于幂等创建。

        Args:
            calendar_id: 日历的 `calendar_id`。
            event: 日程定义对象,例如
                `{"summary": "周会", "start_time": {...}, "end_time": {...}}`。
            idempotency_key: 幂等键;设置后在一段时间内重复请求只会创建一个日程,
                为空时省略该参数。

        Returns:
            包含 `event` 字段的数据,`event` 内含新建日程的 `event_id`、`summary`、
            `start_time`、`end_time` 等字段。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [创建日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/create)

        Examples:
            >>> await client.calendar.events.create("feishu.cn_xxx", {"summary": "周会"})  # doctest:+SKIP
            {'event': {'event_id': 'xxx', 'summary': '周会', ...}}  # noqa: E501
        """
        params = {}
        if idempotency_key is not None:
            params["idempotency_key"] = idempotency_key
        return await self._request_data(
            "POST", f"calendar/v4/calendars/{quote_segment(calendar_id)}/events", params=params, json=event
        )

    async def delete(self, calendar_id: str, event_id: str) -> NestedDict:
        r"""
        删除日程。

        Args:
            calendar_id: 日历的 `calendar_id`。
            event_id: 待删除日程的 `event_id`。

        Returns:
            接口返回的数据(通常为空)。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [删除日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/delete)

        Examples:
            >>> await client.calendar.events.delete("feishu.cn_xxx", "evtxxx")  # doctest:+SKIP
            {}
        """
        return await self._request_data(
            "DELETE",
            f"calendar/v4/calendars/{quote_segment(calendar_id)}/events/{quote_segment(event_id)}",
        )

    async def get(self, calendar_id: str, event_id: str) -> NestedDict:
        r"""
        获取日程信息。

        Args:
            calendar_id: 日历的 `calendar_id`。
            event_id: 日程的 `event_id`。

        Returns:
            包含 `event` 字段的数据,`event` 内含 `event_id`、`summary`、`description`、
            `start_time`、`end_time` 等字段。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [获取日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/get)

        Examples:
            >>> await client.calendar.events.get("feishu.cn_xxx", "evtxxx")  # doctest:+SKIP
            {'event': {'event_id': 'evtxxx', 'summary': '周会', ...}}  # noqa: E501
        """
        return await self._request_data(
            "GET",
            f"calendar/v4/calendars/{quote_segment(calendar_id)}/events/{quote_segment(event_id)}",
        )

    async def list(
        self,
        calendar_id: str,
        *,
        page_size: int = 50,
        max_items: int | None = None,
        start_time: str | None = None,
        end_time: str | None = None,
    ) -> list[NestedDict]:
        r"""
        获取日程列表。

        自动翻页并将各页结果拼接为单个列表返回。`page_size` 会被限制在
        [feishu.consts.MAX_PAGE_SIZE][] 以内。仅将显式传入的可选查询参数并入请求,
        未设置的项会被省略。

        Args:
            calendar_id: 日历的 `calendar_id`。
            page_size: 每页条数,默认为 50,超过上限时按上限截断。
            max_items: 最多返回的条数;为空表示返回全部。
            start_time: 时间范围的起始(Unix 秒时间戳字符串);为空时省略该参数。
            end_time: 时间范围的结束(Unix 秒时间戳字符串);为空时省略该参数。

        Returns:
            日程数据列表,每项包含 `event_id`、`summary`、`start_time`、`end_time` 等字段。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [获取日程列表](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/list)

        Examples:
            >>> await client.calendar.events.list("feishu.cn_xxx")  # doctest:+SKIP
            [{'event_id': 'evtxxx', 'summary': '周会', ...}, ...]  # noqa: E501
        """
        params: dict[str, Any] = {}
        if start_time is not None:
            params["start_time"] = start_time
        if end_time is not None:
            params["end_time"] = end_time
        return await self._client.paginate_get(
            f"calendar/v4/calendars/{quote_segment(calendar_id)}/events",
            params=params,
            page_size=page_size,
            max_items=max_items,
        )

    async def update(self, calendar_id: str, event_id: str, event: dict[str, Any]) -> NestedDict:
        r"""
        更新日程。

        `event` 是描述待更新字段的请求体,原样作为 JSON 发送;仅传入的字段会被更新,
        未传入的字段保持不变,常见键包括 `summary`、`description`、`start_time`、`end_time`
        等。

        Args:
            calendar_id: 日历的 `calendar_id`。
            event_id: 待更新日程的 `event_id`。
            event: 待更新字段的映射,例如 `{"summary": "已改期的周会"}`。

        Returns:
            包含 `event` 字段的数据,`event` 内含更新后日程的 `event_id`、`summary` 等字段。

        Raises:
            feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

        飞书文档:
            [更新日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/patch)

        Examples:
            >>> await client.calendar.events.update("feishu.cn_xxx", "evtxxx", {"summary": "改期"})  # doctest:+SKIP
            {'event': {'event_id': 'evtxxx', 'summary': '改期', ...}}  # noqa: E501
        """
        return await self._request_data(
            "PATCH",
            f"calendar/v4/calendars/{quote_segment(calendar_id)}/events/{quote_segment(event_id)}",
            json=event,
        )

create async

Python
create(calendar_id: str, event: dict[str, Any], *, idempotency_key: str | None = None) -> NestedDict

创建日程。

event 是描述待创建日程的请求体,原样作为 JSON 发送,常见键包括 summarydescriptionstart_timeend_timevchatvisibilityreminders 等。 仅当显式传入 idempotency_key 时才将其并入查询参数,用于幂等创建。

参数:

名称 类型 描述 默认
calendar_id
str

日历的 calendar_id

必需
event
dict[str, Any]

日程定义对象,例如 {"summary": "周会", "start_time": {...}, "end_time": {...}}

必需
idempotency_key
str | None

幂等键;设置后在一段时间内重复请求只会创建一个日程, 为空时省略该参数。

None

返回:

类型 描述
NestedDict

包含 event 字段的数据,event 内含新建日程的 event_idsummary

NestedDict

start_timeend_time 等字段。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

创建日程

示例:

Python Console Session
>>> await client.calendar.events.create("feishu.cn_xxx", {"summary": "周会"})
{'event': {'event_id': 'xxx', 'summary': '周会', ...}}  # noqa: E501
源代码位于: feishu/calendar/events.py
Python
async def create(
    self, calendar_id: str, event: dict[str, Any], *, idempotency_key: str | None = None
) -> NestedDict:
    r"""
    创建日程。

    `event` 是描述待创建日程的请求体,原样作为 JSON 发送,常见键包括 `summary`、
    `description`、`start_time`、`end_time`、`vchat`、`visibility`、`reminders` 等。
    仅当显式传入 `idempotency_key` 时才将其并入查询参数,用于幂等创建。

    Args:
        calendar_id: 日历的 `calendar_id`。
        event: 日程定义对象,例如
            `{"summary": "周会", "start_time": {...}, "end_time": {...}}`。
        idempotency_key: 幂等键;设置后在一段时间内重复请求只会创建一个日程,
            为空时省略该参数。

    Returns:
        包含 `event` 字段的数据,`event` 内含新建日程的 `event_id`、`summary`、
        `start_time`、`end_time` 等字段。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [创建日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/create)

    Examples:
        >>> await client.calendar.events.create("feishu.cn_xxx", {"summary": "周会"})  # doctest:+SKIP
        {'event': {'event_id': 'xxx', 'summary': '周会', ...}}  # noqa: E501
    """
    params = {}
    if idempotency_key is not None:
        params["idempotency_key"] = idempotency_key
    return await self._request_data(
        "POST", f"calendar/v4/calendars/{quote_segment(calendar_id)}/events", params=params, json=event
    )

delete async

Python
delete(calendar_id: str, event_id: str) -> NestedDict

删除日程。

参数:

名称 类型 描述 默认
calendar_id
str

日历的 calendar_id

必需
event_id
str

待删除日程的 event_id

必需

返回:

类型 描述
NestedDict

接口返回的数据(通常为空)。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

删除日程

示例:

Python Console Session
>>> await client.calendar.events.delete("feishu.cn_xxx", "evtxxx")
{}
源代码位于: feishu/calendar/events.py
Python
async def delete(self, calendar_id: str, event_id: str) -> NestedDict:
    r"""
    删除日程。

    Args:
        calendar_id: 日历的 `calendar_id`。
        event_id: 待删除日程的 `event_id`。

    Returns:
        接口返回的数据(通常为空)。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [删除日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/delete)

    Examples:
        >>> await client.calendar.events.delete("feishu.cn_xxx", "evtxxx")  # doctest:+SKIP
        {}
    """
    return await self._request_data(
        "DELETE",
        f"calendar/v4/calendars/{quote_segment(calendar_id)}/events/{quote_segment(event_id)}",
    )

get async

获取日程信息。

参数:

名称 类型 描述 默认
calendar_id
str

日历的 calendar_id

必需
event_id
str

日程的 event_id

必需

返回:

类型 描述
NestedDict

包含 event 字段的数据,event 内含 event_idsummarydescription

NestedDict

start_timeend_time 等字段。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

获取日程

示例:

Python Console Session
>>> await client.calendar.events.get("feishu.cn_xxx", "evtxxx")
{'event': {'event_id': 'evtxxx', 'summary': '周会', ...}}  # noqa: E501
源代码位于: feishu/calendar/events.py
Python
async def get(self, calendar_id: str, event_id: str) -> NestedDict:
    r"""
    获取日程信息。

    Args:
        calendar_id: 日历的 `calendar_id`。
        event_id: 日程的 `event_id`。

    Returns:
        包含 `event` 字段的数据,`event` 内含 `event_id`、`summary`、`description`、
        `start_time`、`end_time` 等字段。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [获取日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/get)

    Examples:
        >>> await client.calendar.events.get("feishu.cn_xxx", "evtxxx")  # doctest:+SKIP
        {'event': {'event_id': 'evtxxx', 'summary': '周会', ...}}  # noqa: E501
    """
    return await self._request_data(
        "GET",
        f"calendar/v4/calendars/{quote_segment(calendar_id)}/events/{quote_segment(event_id)}",
    )

list async

Python
list(calendar_id: str, *, page_size: int = 50, max_items: int | None = None, start_time: str | None = None, end_time: str | None = None) -> list[NestedDict]

获取日程列表。

自动翻页并将各页结果拼接为单个列表返回。page_size 会被限制在 [feishu.consts.MAX_PAGE_SIZE][] 以内。仅将显式传入的可选查询参数并入请求, 未设置的项会被省略。

参数:

名称 类型 描述 默认
calendar_id
str

日历的 calendar_id

必需
page_size
int

每页条数,默认为 50,超过上限时按上限截断。

50
max_items
int | None

最多返回的条数;为空表示返回全部。

None
start_time
str | None

时间范围的起始(Unix 秒时间戳字符串);为空时省略该参数。

None
end_time
str | None

时间范围的结束(Unix 秒时间戳字符串);为空时省略该参数。

None

返回:

类型 描述
list[NestedDict]

日程数据列表,每项包含 event_idsummarystart_timeend_time 等字段。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

获取日程列表

示例:

Python Console Session
>>> await client.calendar.events.list("feishu.cn_xxx")
[{'event_id': 'evtxxx', 'summary': '周会', ...}, ...]  # noqa: E501
源代码位于: feishu/calendar/events.py
Python
async def list(
    self,
    calendar_id: str,
    *,
    page_size: int = 50,
    max_items: int | None = None,
    start_time: str | None = None,
    end_time: str | None = None,
) -> list[NestedDict]:
    r"""
    获取日程列表。

    自动翻页并将各页结果拼接为单个列表返回。`page_size` 会被限制在
    [feishu.consts.MAX_PAGE_SIZE][] 以内。仅将显式传入的可选查询参数并入请求,
    未设置的项会被省略。

    Args:
        calendar_id: 日历的 `calendar_id`。
        page_size: 每页条数,默认为 50,超过上限时按上限截断。
        max_items: 最多返回的条数;为空表示返回全部。
        start_time: 时间范围的起始(Unix 秒时间戳字符串);为空时省略该参数。
        end_time: 时间范围的结束(Unix 秒时间戳字符串);为空时省略该参数。

    Returns:
        日程数据列表,每项包含 `event_id`、`summary`、`start_time`、`end_time` 等字段。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [获取日程列表](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/list)

    Examples:
        >>> await client.calendar.events.list("feishu.cn_xxx")  # doctest:+SKIP
        [{'event_id': 'evtxxx', 'summary': '周会', ...}, ...]  # noqa: E501
    """
    params: dict[str, Any] = {}
    if start_time is not None:
        params["start_time"] = start_time
    if end_time is not None:
        params["end_time"] = end_time
    return await self._client.paginate_get(
        f"calendar/v4/calendars/{quote_segment(calendar_id)}/events",
        params=params,
        page_size=page_size,
        max_items=max_items,
    )

update async

更新日程。

event 是描述待更新字段的请求体,原样作为 JSON 发送;仅传入的字段会被更新, 未传入的字段保持不变,常见键包括 summarydescriptionstart_timeend_time 等。

参数:

名称 类型 描述 默认
calendar_id
str

日历的 calendar_id

必需
event_id
str

待更新日程的 event_id

必需
event
dict[str, Any]

待更新字段的映射,例如 {"summary": "已改期的周会"}

必需

返回:

类型 描述
NestedDict

包含 event 字段的数据,event 内含更新后日程的 event_idsummary 等字段。

引发:

类型 描述
FeishuError

请求失败或返回错误码时抛出。

飞书文档

更新日程

示例:

Python Console Session
>>> await client.calendar.events.update("feishu.cn_xxx", "evtxxx", {"summary": "改期"})
{'event': {'event_id': 'evtxxx', 'summary': '改期', ...}}  # noqa: E501
源代码位于: feishu/calendar/events.py
Python
async def update(self, calendar_id: str, event_id: str, event: dict[str, Any]) -> NestedDict:
    r"""
    更新日程。

    `event` 是描述待更新字段的请求体,原样作为 JSON 发送;仅传入的字段会被更新,
    未传入的字段保持不变,常见键包括 `summary`、`description`、`start_time`、`end_time`
    等。

    Args:
        calendar_id: 日历的 `calendar_id`。
        event_id: 待更新日程的 `event_id`。
        event: 待更新字段的映射,例如 `{"summary": "已改期的周会"}`。

    Returns:
        包含 `event` 字段的数据,`event` 内含更新后日程的 `event_id`、`summary` 等字段。

    Raises:
        feishu.errors.FeishuError: 请求失败或返回错误码时抛出。

    飞书文档:
        [更新日程](https://open.feishu.cn/document/server-docs/calendar-v4/calendar-event/patch)

    Examples:
        >>> await client.calendar.events.update("feishu.cn_xxx", "evtxxx", {"summary": "改期"})  # doctest:+SKIP
        {'event': {'event_id': 'evtxxx', 'summary': '改期', ...}}  # noqa: E501
    """
    return await self._request_data(
        "PATCH",
        f"calendar/v4/calendars/{quote_segment(calendar_id)}/events/{quote_segment(event_id)}",
        json=event,
    )