123Pan Open API SDK - 专业的异步网盘SDK
Project description
V123Pan Python SDK
专业的 123Pan Open API 异步 Python SDK,提供完整的文件管理、上传、下载功能。
特性
- ✨ 纯异步设计 - 基于
asyncio和httpx,高性能并发 - 📦 完整功能 - 支持文件管理、上传、下载、查询等所有 API
- 🚀 生产级 - 完善的错误处理、重试机制、类型注解
- 📝 类型安全 - 完整的类型注解,支持
mypy静态检查 - 🧪 测试覆盖 - 完善的单元测试和集成测试
- 🔧 工程化 - 遵循 PEP 8 规范,支持
black、isort、flake8
安装
使用 pip 安装
pip install v123pan
从源码安装
git clone https://github.com/v123pan/v123pan-python.git
cd v123pan-python
pip install -e .
快速开始
初始化客户端
import asyncio
from v123pan import V123Pan
async def main():
# 使用 access_token 初始化
client = V123Pan(access_token="your_access_token")
# 或者使用 client_id 和 client_secret
client = V123Pan(
client_id="your_client_id",
client_secret="your_client_secret"
)
try:
# 获取用户信息
user_info = await client.user_info()
print(f"用户信息: {user_info}")
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(main())
文件上传
from v123pan import V123Pan
from v123pan.api.combine import FileUploader
async def upload_file():
client = V123Pan(client_id="id", client_secret="secret")
async with FileUploader(client) as uploader:
result = await uploader.upload(
"/path/to/file.txt",
parent_id=0,
progress_callback=lambda p: print(f"进度: {p.percentage:.1f}%")
)
if result["code"] == 0:
print(f"上传成功,fileID: {result['data']['fileID']}")
await client.close()
文件管理
async def file_operations():
client = V123Pan(access_token="token")
# 创建目录
dir_result = await client.directory("我的文件夹", parent_id=0)
dir_id = dir_result["data"]["dirID"]
# 列出文件
file_list = await client.file_list(parent_file_id=0)
# 获取文件详情
file_detail = await client.file_detail(file_id=12345)
await client.close()
项目结构
v123pan/
├── v123pan/ # 主包目录
│ ├── __init__.py # 包入口,导出公共 API
│ ├── client.py # 主客户端类
│ ├── const.py # 常量配置
│ ├── exceptions.py # 异常定义
│ ├── api/ # API 模块
│ │ ├── __init__.py
│ │ ├── base.py # 基础 Mixin 类
│ │ ├── auth.py # 认证 API
│ │ ├── user.py # 用户 API
│ │ ├── upload.py # 上传 API
│ │ ├── file_management.py # 文件管理 API
│ │ ├── file_query.py # 文件查询 API
│ │ ├── download.py # 下载 API
│ │ └── combine/ # 高级组合 API
│ │ └── uploader.py # 文件上传器
│ ├── utils/ # 工具模块
│ │ ├── __init__.py
│ │ ├── log.py # 日志配置
│ │ └── slice/ # 分片处理
│ └── crypto/ # 加密模块
│ └── __init__.py
├── tests/ # 测试目录
├── examples/ # 示例代码目录
├── doc/ # API 文档
├── pyproject.toml # 项目配置
├── requirements.txt # 依赖列表
└── README.md # 主文档
开发指南
详细开发规范请参考 DEVELOPMENT.md。
安装开发依赖
pip install -e ".[dev]"
代码格式化
# 使用 black 格式化代码
black v123pan/ tests/
# 使用 isort 整理导入
isort v123pan/ tests/
代码检查
# flake8 检查
flake8 v123pan/ tests/
# mypy 类型检查
mypy v123pan/
运行测试
# 运行所有测试
pytest
# 运行测试并生成覆盖率报告
pytest --cov=v123pan --cov-report=html
# 只运行单元测试
pytest -m unit
# 只运行集成测试
pytest -m integration
模块导出
核心类
from v123pan import V123Pan # 主客户端
常量
from v123pan import API_PATHS, BASE_URL, PLATFORM, FILE_TYPE, FILE_CATEGORY
异常
from v123pan import (
V123PanError,
APIError,
NetworkError,
AuthError,
RateLimitError,
FileUploadError,
FileReadError,
HashComputationError,
ResourceClosedError,
TimeoutError,
ValidationError,
CryptoError,
)
工具类
from v123pan import (
SimpleSlice,
FileSlice,
DataSlice,
MixSlice,
ChaCha20Poly1305Slice,
LogConfig,
get_logger,
)
加密类
from v123pan import (
AESEncryptor,
ChaCha20Encryptor,
Poly1305Authenticator,
FilenameEncryptor,
create_encryptor,
)
组合 API
from v123pan import (
FileUploader,
FileUploadProgress,
ProgressCallback,
FileUploadError,
)
配置
环境变量
可以通过环境变量配置 SDK:
# .env 文件示例
V123PAN_CLIENT_ID=your_client_id
V123PAN_CLIENT_SECRET=your_client_secret
V123PAN_ACCESS_TOKEN=your_access_token
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
联系方式
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
v123pan-1.1.0.tar.gz
(44.8 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
v123pan-1.1.0-py3-none-any.whl
(45.1 kB
view details)
File details
Details for the file v123pan-1.1.0.tar.gz.
File metadata
- Download URL: v123pan-1.1.0.tar.gz
- Upload date:
- Size: 44.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eea3b62cb1268ae308a27acbf64546b3e57729a82bafb66241d8122b27a77dd
|
|
| MD5 |
47982e5b56501f636ac61dacc6505f6b
|
|
| BLAKE2b-256 |
fb546218e6397c848ef122053aa8c0bc2bcea2c67512dc5cdf9ea7ac4c16598b
|
File details
Details for the file v123pan-1.1.0-py3-none-any.whl.
File metadata
- Download URL: v123pan-1.1.0-py3-none-any.whl
- Upload date:
- Size: 45.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf591ce790d6ebfd47624c6adc43bcc78c9da86a52f020eabe4c5c1ef0c6804c
|
|
| MD5 |
510bc1a7c5ed23002d164473d518b0b5
|
|
| BLAKE2b-256 |
d6bd44027e82cc42ee7bca9c2b1ae70a039c2c390ada8ec4d5f03a9edb5edd35
|