M-TEAM API SDK
Project description
M-TEAM API SDK
M-TEAM API 的 Python SDK,提供了简单易用的接口封装。
安装
pip install mteam
快速开始
- 配置环境变量
cp .env.example .env
编辑 .env 文件,填入你的 API 密钥:
MTEAM_API_KEY=your_api_key_here
MTEAM_BASE_URL=http://test2.m-team.cc/api
- 基本使用
from mteam import MTeamClient
# 创建客户端实例
client = MTeamClient()
# 搜索种子
from mteam.torrent import TorrentSearch, TorrentCategory
search = TorrentSearch(
keyword="测试",
categories=[TorrentCategory.MOVIE],
page_size=10
)
result = client.torrent.search(search)
# 获取用户资料
profile = client.member.get_profile()
功能模块
用户模块
from mteam.member import LoginForm, RegisterForm
# 用户登录
form = LoginForm(username="test", password="password")
result = client.member.login(form)
# 获取用户资料
profile = client.member.get_profile()
种子模块
from mteam.torrent import TorrentSearch, TorrentCategory
# 搜索种子
search = TorrentSearch(keyword="测试")
results = client.torrent.search(search)
# 获取种子详情
torrent = client.torrent.get_detail(torrent_id=123)
字幕模块
from mteam.subtitle import SubtitleSearch
# 搜索字幕
search = SubtitleSearch(keyword="测试")
subtitles = client.subtitle.search(search)
# 上传字幕
form = SubtitleUploadForm(
title="测试字幕",
torrent_id=123,
language_id=1
)
result = client.subtitle.upload(form, "path/to/subtitle.srt")
测试
- 安装测试依赖
pip install pytest python-dotenv
- 运行测试
# 运行所有测试
pytest
# 运行特定模块测试
pytest tests/test_member.py
pytest tests/test_torrent.py
# 运行单个测试
pytest tests/test_member.py::test_login
# 显示详细输出
pytest -v
注意事项
-
API 密钥安全
- 不要在代码中硬编码 API 密钥
- 使用环境变量或配置文件管理密钥
- 不要将密钥提交到版本控制系统
-
错误处理
- 所有 API 调用都可能抛出
APIError异常 - 检查响应的
code和message字段 - 合理处理网络错误和超时
- 所有 API 调用都可能抛出
-
请求限制
- 注意 API 的请求频率限制
- 合理设置超时时间
- 必要时实现请求重试机制
常见问题
-
API 密钥无效
- 检查
.env文件中的MTEAM_API_KEY是否正确 - 确认 API 密钥未过期
- 检查
-
请求失败
- 检查网络连接
- 确认 API 基础 URL 是否正确
- 查看错误响应的具体信息
-
类型错误
- 确保传入参数符合类型要求
- 使用 IDE 的类型提示功能
- 参考 API 文档中的参数说明
API 文档
完整的 API 文档请参考:[API 文档链接]
贡献指南
- Fork 本仓库
- 创建功能分支
- 提交代码
- 创建 Pull Request
许可证
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mteam-0.1.4.tar.gz
(26.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
mteam-0.1.4-py3-none-any.whl
(13.1 kB
view details)
File details
Details for the file mteam-0.1.4.tar.gz.
File metadata
- Download URL: mteam-0.1.4.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c529435b0aa7b7e94fc1932dd56c91b14e8ff3ac3c137368a97cae04e82e7440
|
|
| MD5 |
caad7d9a534848d77bc63837af3ef35f
|
|
| BLAKE2b-256 |
cba7fbed2053b90b222216c2cfa1e5befb8645a3d217c650d2fffa04275c17d2
|
File details
Details for the file mteam-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mteam-0.1.4-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21d8765465dbccc3773fefb1faff2961d3836f6af67bb1fdac7d27629271167e
|
|
| MD5 |
6ae0a01712d34fe34cd525a720fe4184
|
|
| BLAKE2b-256 |
04c4e07abade06e07584396ead2bf4bacf0890c8e05423bb5af7926aa73cc84c
|