markji package

class markji.Markji(token: str)[源代码]

基类:object

客户端

参数:

token (str) -- 用户令牌

from markji import Markji
from markji.auth import Auth

auth = Auth("username", "password")
token = await auth.login()
client = Markji(token)
async get_profile() Profile[源代码]

获取用户信息

返回:

用户信息

返回类型:

Profile

抛出:

aiohttp.ClientResponseError -- 获取用户信息失败

async query_users(user_ids: Iterable[UserID | int]) list[UserBrief][源代码]

查询用户信息

参数:

user_ids (Iterable[UserID | int]) -- 用户ID列表

返回:

用户简要信息列表

返回类型:

list[UserBrief]

抛出:

aiohttp.ClientResponseError -- 查询用户失败

async search_users(nickname: str, offset: int = 0, limit: int = 10) tuple[list[User], int][源代码]

搜索用户

昵称长度必须在 1 到 8000 个字符之间

offset 和 limit 必须大于等于 0

offset + limit 必须小于等于 10000

参数:

nickname (str) -- 用户昵称

返回:

用户列表, 总数

返回类型:

tuple[list[User], int]

抛出:
  • ValueError -- 昵称长度错误

  • ValueError -- offset 或 limit 错误

  • ValueError -- offset + limit 错误

  • aiohttp.ClientResponseError -- 搜索用户失败

async search_collaborators(deck_id: DeckID | str, keyword: str | UserID | int) list[Collaborator][源代码]

搜索协作者

关键词长度必须在 1 到 8000 个字符之间

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • keyword (str | UserID | int) -- 关键词(UserID,手机,邮箱,昵称)

返回:

协作者列表

返回类型:

list[Collaborator]

抛出:
  • ValueError -- 关键词长度错误

  • aiohttp.ClientResponseError -- 搜索协作者失败

async get_folder(folder_id: FolderID | str) Folder | RootFolder[源代码]

获取文件夹

参数:

folder_id (FolderID | str) -- 文件夹ID

返回:

文件夹

返回类型:

Folder | RootFolder

抛出:

aiohttp.ClientResponseError -- 获取文件夹失败

async get_root_folder() RootFolder[源代码]

获取根文件夹

返回:

根文件夹

返回类型:

RootFolder

抛出:
  • aiohttp.ClientResponseError -- 获取根文件夹失败

  • FileNotFoundError -- 未找到根文件夹

async list_folders() list[Folder][源代码]

获取用户的所有文件夹

不包含根文件夹

使用 get_root_folder 获取根文件夹

返回:

文件夹列表

返回类型:

list[Folder]

抛出:

aiohttp.ClientResponseError -- 获取文件夹列表失败

async new_folder(name: str) Folder[源代码]

创建文件夹

文件名长度必须在 2 到 8 个字符之间

参数:

name (str) -- 文件夹名

返回:

创建的文件夹

返回类型:

Folder

抛出:
  • ValueError -- 文件夹名长度错误

  • aiohttp.ClientResponseError -- 创建文件夹失败

async delete_folder(folder_id: FolderID | str) RootFolder[源代码]

删除文件夹

参数:

folder_id (FolderID | str) -- 文件夹ID

返回:

删除后的根文件

返回类型:

RootFolder

抛出:

aiohttp.ClientResponseError -- 删除文件夹失败

async rename_folder(folder_id: FolderID | str, name: str) Folder[源代码]

重命名文件夹

文件名长度必须在 2 到 8 个字符之间

参数:
  • folder_id (FolderID | str) -- 文件夹ID

  • name (str) -- 新文件夹名

返回:

重命名后的文件夹

返回类型:

Folder

抛出:
  • ValueError -- 文件夹名长度错误

  • aiohttp.ClientResponseError -- 重命名文件夹失败

async sort_folders(folder_ids: Iterable[FolderID | str]) RootFolder[源代码]

排序文件夹

参数:

folder_ids (Iterable[FolderID | str]) -- 排序后的文件夹ID列表

返回:

排序后的根文件夹

返回类型:

RootFolder

抛出:

aiohttp.ClientResponseError -- 排序文件夹失败

async get_deck(deck_id: str) Deck[源代码]

获取卡组

参数:

deck_id (str) -- 卡组ID

返回:

卡组

返回类型:

Deck

抛出:

aiohttp.ClientResponseError -- 获取卡组失败

async list_decks(folder_id: FolderID | str) list[DeckInfo][源代码]

获取文件夹的所有卡组

参数:

folder_id (FolderID | str) -- 文件夹ID

返回:

卡组列表

返回类型:

list[DeckInfo]

抛出:

aiohttp.ClientResponseError -- 获取卡组列表失败

async new_deck(folder_id: FolderID | str, name: str, description: str = '', is_private: bool = False) DeckBrief[源代码]

创建卡组

卡组名长度必须在 2 到 48 个字符之间

参数:
  • folder_id (FolderID | str) -- 文件夹ID

  • name (str) -- 卡组名

  • description (str) -- 卡组描述

  • is_private (bool) -- 是否私有

返回:

创建的卡组

返回类型:

DeckBrief

抛出:
  • ValueError -- 卡组名长度错误

  • aiohttp.ClientResponseError -- 创建卡组失败

async delete_deck(deck_id: DeckID | str)[源代码]

删除卡组

或取消收藏卡组

参数:

deck_id (DeckID | str) -- 卡组ID

抛出:

aiohttp.ClientResponseError -- 删除卡组失败

async update_deck_info(deck_id: DeckID | str, name: str | None = None, description: str | None = None, is_private: bool | None = None, card_price: int | None = None) DeckBrief[源代码]

更新卡组信息

卡组名长度必须在 2 到 48 个字符之间

卡片价格必须大于等于 0,且只有可用马克量大于 10000 的用户才能设置为0

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • name (str | None) -- 卡组名

  • description (str | None) -- 卡组描述

  • is_private (bool | None) -- 是否私有

  • card_price (int | None) -- 卡片价格

返回:

更新后的卡组

返回类型:

DeckBrief

抛出:
  • ValueError -- 更新信息为空

  • ValueError -- 卡组名长度错误

  • ValueError -- 卡片价格错误

  • aiohttp.ClientResponseError -- 更新卡组信息失败

async update_deck_name(deck_id: DeckID | str, name: str) DeckBrief[源代码]

重命名卡组

卡组名长度必须在 2 到 48 个字符之间

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • name (str) -- 新卡组名

返回:

更新后的卡组

返回类型:

DeckBrief

抛出:

ValueError -- 卡组名长度错误

async update_deck_description(deck_id: DeckID | str, description: str) DeckBrief[源代码]

更新卡组描述

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • description (str) -- 卡组描述

返回:

更新后的卡组

返回类型:

DeckBrief

async update_deck_privacy(deck_id: DeckID | str, is_private: bool) DeckBrief[源代码]

更新卡组隐私状态

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • is_private (bool) -- 是否私有

返回:

更新后的卡组

返回类型:

DeckBrief

async update_deck_card_price(deck_id: DeckID | str, card_price: int) DeckBrief[源代码]

更新卡组卡片价格

卡片价格必须大于等于 0,且只有可用马克量大于 10000 的用户才能设置为0

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • card_price (int) -- 卡片价格

返回:

更新后的卡组

返回类型:

DeckBrief

抛出:

ValueError -- 卡片价格错误

async update_deck_access_setting(deck_id: DeckID | str, is_searchable: bool | None = None, validation_request_access: bool | None = None, validation_password: str | None = None) DeckAccessSettingBrief | DeckAccessSettingInfo | DeckAccessSetting[源代码]

更新卡组访问设置

密码必须为 4 ~ 12 位,,由数字字母组成

密码为空则取消密码

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • is_searchable (bool | None) -- 是否可被搜索

  • validation_request_access (bool | None) -- 是否需要验证访问

  • validation_password (str | None) -- 验证密码

返回:

更新后的卡组

返回类型:

DeckAccessSettingBrief | DeckAccessSettingInfo | DeckAccessSetting

抛出:
  • ValueError -- 更新设置为空

  • ValueError -- 密码长度错误

  • ValueError -- 密码格式错误

  • aiohttp.ClientResponseError -- 更新卡组设置失败

async update_deck_searchable(deck_id: DeckID | str, is_searchable: bool) DeckAccessSettingBrief | DeckAccessSettingInfo | DeckAccessSetting[源代码]

更新卡组是否可被搜索

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • is_searchable (bool) -- 是否可被搜索

返回:

更新后的卡组

返回类型:

DeckAccessSettingBrief | DeckAccessSettingInfo | DeckAccessSetting

async update_deck_validation_request_access(deck_id: DeckID | str, validation_request_access: bool) DeckAccessSettingBrief | DeckAccessSettingInfo | DeckAccessSetting[源代码]

更新卡组是否需要验证访问

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • validation_request_access (bool) -- 是否需要验证访问

返回:

更新后的卡组

返回类型:

DeckAccessSettingBrief | DeckAccessSettingInfo | DeckAccessSetting

async update_deck_validation_password(deck_id: DeckID | str, validation_password: str) DeckAccessSettingInfo | DeckAccessSetting[源代码]

更新卡组验证密码

密码必须为 4 ~ 12 位,,由数字字母组成

密码为空则取消密码

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • validation_password (str) -- 验证密码

返回:

更新后的卡组

返回类型:

DeckAccessSettingInfo | DeckAccessSetting

抛出:
  • ValueError -- 密码长度错误

  • ValueError -- 密码格式错误

async sort_decks(folder_id: FolderID | str, deck_ids: Iterable[DeckID | str]) Folder[源代码]

排序卡组

参数:
  • folder_id (FolderID | str) -- 文件夹ID

  • deck_ids (Iterable[DeckID | str]) -- 排序后的卡组ID列表

返回:

排序后的文件夹

返回类型:

Folder

抛出:

aiohttp.ClientResponseError -- 排序卡组失败

async move_decks(folder_id_from: FolderID | str, folder_id_to: FolderID | str, deck_ids: Iterable[DeckID | str], order: int | None = None) FolderDiff[源代码]

移动卡组

参数:
  • folder_id_from (FolderID | str) -- 旧文件夹ID

  • folder_id_to (FolderID | str) -- 新文件夹ID

  • deck_ids (Iterable[DeckID | str]) -- 卡组ID列表

  • order (int) -- 排序

返回:

文件夹变化

返回类型:

FolderDiff

抛出:

aiohttp.ClientResponseError -- 移动卡组失败

async search_decks(keyword: str, offset: int = 0, limit: int = 10, self_only: bool = False) tuple[list[DeckBasic], int][源代码]

搜索卡组

关键词长度必须在 1 到 8000 个字符之间

offset 必须在 0 到 1000 之间

limit 必须在 1 到 100 之间

参数:
  • keyword (str) -- 关键词

  • offset (int) -- 偏移

  • limit (int) -- 限制

  • self_only (bool) -- 仅自己

返回:

卡组基本信息列表, 总数

返回类型:

tuple[list[DeckBasic], int]

抛出:
  • ValueError -- 关键词长度错误

  • ValueError -- offset 错误

  • ValueError -- limit 错误

  • aiohttp.ClientResponseError -- 搜索卡组失败

async fork_deck(deck_id: DeckID | str) DeckForked[源代码]

收藏卡组

无法收藏自己的卡组

参数:

deck_id (DeckID | str) -- 卡组ID

返回:

复制的卡组

返回类型:

DeckForked

抛出:

aiohttp.ClientResponseError -- 复制卡组失败

获取卡组访问链接

参数:

deck_id (DeckID | str) -- 卡组ID

返回:

访问链接

返回类型:

str

抛出:

aiohttp.ClientResponseError -- 获取访问链接失败

async get_chapter(deck_id: DeckID | str, chapter_id: ChapterID | str) Chapter[源代码]

获取章节

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

返回:

章节

返回类型:

Chapter

抛出:

aiohttp.ClientResponseError -- 获取章节失败

async get_chapter_set(deck_id: DeckID | str) ChapterSet[源代码]

获取章节集合

参数:

deck_id (DeckID | str) -- 卡组ID

返回:

章节集合

返回类型:

ChapterSet

抛出:

aiohttp.ClientResponseError -- 获取章节集合失败

async list_chapters(deck_id: DeckID | str) list[Chapter][源代码]

获取卡组的所有章节

参数:

deck_id (DeckID | str) -- 卡组ID

返回:

章节列表

返回类型:

list[Chapter]

抛出:

aiohttp.ClientResponseError -- 获取章节列表失败

async new_chapter(deck_id: DeckID | str, name: str) Chapter[源代码]

创建章节

章节名长度必须在 1 到 48 个字符之间

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • name (str) -- 章节名

返回:

创建的章节

返回类型:

Chapter

抛出:
  • ValueError -- 章节名长度错误

  • aiohttp.ClientResponseError -- 创建章节失败

async delete_chapter(deck_id: DeckID | str, chapter_id: ChapterID | str) ChapterSet[源代码]

删除章节

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

返回:

删除后的章节集

返回类型:

ChapterSet

抛出:

aiohttp.ClientResponseError -- 删除章节失败

async rename_chapter(deck_id: DeckID | str, chapter_id: ChapterID | str, name: str) Chapter[源代码]

重命名章节

章节名长度必须在 1 到 48 个字符之间

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

  • name (str) -- 新章节名

返回:

重命名后的章节

返回类型:

Chapter

抛出:
  • ValueError -- 章节名长度错误

  • aiohttp.ClientResponseError -- 重命名章节失败

async sort_chapters(deck_id: DeckID | str, chapter_ids: Iterable[ChapterID | str]) ChapterSet[源代码]

排序章节

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_ids (Iterable[ChapterID | str]) -- 排序后的章节ID列表

返回:

排序后的章节集合

返回类型:

ChapterSet

抛出:

aiohttp.ClientResponseError -- 排序章节失败

async get_card(deck_id: DeckID | str, card_id: str) Card[源代码]

获取卡片

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • card_id (str) -- 卡片ID

返回:

卡片

返回类型:

Card

抛出:

aiohttp.ClientResponseError -- 获取卡片失败

async list_cards(deck_id: DeckID | str, chapter_id: ChapterID | str) list[Card][源代码]

获取章节的所有卡片

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

返回:

卡片列表

返回类型:

list[Card]

抛出:

aiohttp.ClientResponseError -- 获取卡片列表失败

async new_card(deck_id: DeckID | str, chapter_id: ChapterID | str, content: str, grammar_version: int = 3) Card[源代码]

创建卡片

卡片内容长度必须在 1 到 2500 个字符之间

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

  • content (str) -- 卡片内容

  • grammar_version (int) -- 语法版本

返回:

创建的卡片

返回类型:

Card

抛出:
  • ValueError -- 卡片内容长度错误

  • aiohttp.ClientResponseError -- 创建卡片失败

async delete_card(chapter_id: ChapterID | str, deck_id: DeckID | str, card_id: str) Chapter[源代码]

删除卡片

参数:
  • chapter_id (ChapterID | str) -- 章节ID

  • deck_id (DeckID | str) -- 卡组ID

  • card_id (str) -- 卡片ID

返回:

删除后的章节

返回类型:

Chapter

抛出:

aiohttp.ClientResponseError -- 删除卡片失败

async edit_card(deck_id: DeckID | str, card_id: str, content: str, grammar_version: int = 3) Card[源代码]

编辑卡片

卡片内容长度必须在 1 到 2500 个字符之间

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • card_id (str) -- 卡片ID

  • content (str) -- 卡片内容

  • grammar_version (int) -- 语法版本

返回:

编辑后的卡片

返回类型:

Card

抛出:
  • ValueError -- 卡片内容长度错误

  • aiohttp.ClientResponseError -- 编辑卡片失败

async sort_cards(deck_id: DeckID | str, chapter_id: ChapterID | str, card_ids: Iterable[CardID | str]) Chapter[源代码]

排序卡片

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

  • card_ids (Iterable[str]) -- 排序后的卡片ID列表

返回:

排序后的章节

返回类型:

Chapter

抛出:

aiohttp.ClientResponseError -- 排序卡片失败

async move_cards(deck_id: DeckID | str, chapter_id_from: ChapterID | str, chapter_id_to: ChapterID | str, card_ids: Iterable[CardID | str], order: int | None = None) ChapterDiff[源代码]

移动卡片

参数:
  • deck_id (DeckID | str) -- 卡组ID

  • chapter_id (ChapterID | str) -- 章节ID

  • card_id (CardID | str) -- 卡片ID

  • new_chapter_id (ChapterID | str) -- 新章节ID

返回:

章节变化

返回类型:

ChapterDiff

抛出:

aiohttp.ClientResponseError -- 移动卡片失败

async search_cards(keyword: str, offset: int = 0, limit: int = 10, self_only: bool = False, deck_id: DeckID | str | None = None) tuple[list[CardResult], int][源代码]

搜索卡片

关键词长度必须在 1 到 8000 个字符之间

offset 必须在 0 到 1000 之间

limit 必须在 10 到 100 之间

设置 deck_id 时,self_only 无效

参数:
  • keyword (str) -- 关键词

  • offset (int) -- 偏移

  • limit (int) -- 限制

  • self_only (bool) -- 仅自己的

  • deck_id (DeckID | str | None) -- 卡组ID

返回:

卡片列表, 总数

返回类型:

tuple[list[Card], int]

抛出:
  • ValueError -- 关键词长度错误

  • ValueError -- offset 错误

  • ValueError -- limit 错误

  • aiohttp.ClientResponseError -- 搜索卡片失败

async upload_file(path: Path | str | IO[bytes]) File[源代码]

上传文件(图片和音频)

参数:

path (Path | str | IO[bytes]) -- 文件路径或字节流

返回:

上传后的文件

返回类型:

File

抛出:

aiohttp.ClientResponseError -- 上传文件失败

async tts(text: str, lang: LanguageCode | str) File[源代码]

语音合成

参数:
  • text (str) -- 文本

  • lang (LanguageCode | str) -- 语言代码

返回:

语音文件

返回类型:

File

抛出:
  • aiohttp.ClientResponseError -- 语音合成失败

  • aiohttp.ClientResponseError -- 获取语音文件失败

async upload_mask(mask: Iterable[MaskItem | dict] | Path | str) File[源代码]

上传图片遮罩

参数:

mask (Iterable[MaskItem | dict] | Path | str) -- 遮罩或文件路径

返回:

上传后的文件

返回类型:

File

抛出:

aiohttp.ClientResponseError -- 上传文件失败

Subpackages

Submodules

markji.auth module

class markji.auth.Auth(username: str, password: str)[源代码]

基类:object

登陆认证

参数:
  • username (str) -- 用户名(手机号、邮箱)

  • password (str) -- 密码

from markji.auth import Auth

auth = Auth("username", "password")
token = await auth.login()
async login() str[源代码]

登陆

获取用户token

返回:

用户token

返回类型:

str

抛出:

aiohttp.ClientResponseError -- 登陆失败