第三方百度网盘 CLI / API 封装,底层依赖官方 bdpan CLI。
A third-party Baidu Netdisk CLI / API wrapper built on the official bdpan CLI.
本项目不是百度官方 SDK,也不伪装成官方产品。它的目标很明确:把已经验证稳定的官方命令链整理成一个易于集成、易于部署、易于自动化调用的开源项目。
This project is not an official Baidu SDK and does not pretend to be one. Its goal is narrow and practical: package the stable part of the official command chain into an open source project that is easy to integrate, deploy, and automate.
当前主工作范围明确限制在 /apps/bdpan。
The current supported workspace is intentionally limited to /apps/bdpan.
- 第三方开源封装,不属于百度官方项目
- 底层依赖官方
bdpanCLI - 一账号一配置目录
- 不暴露 token / cookie
- 不要求接入方自行抓包、逆向网页或维护 cookie
- 账号绑定
- 登录状态检查
- 目录浏览
- 创建目录
- 上传文件
- 上传后生成分享链接
- 转存公开分享链接
- 主工作范围为
/apps/bdpan search不进入主链承诺- 上传后校验建议依赖
ls和share,不要依赖search
git clone https://github.com/atuizz/baidupan-cli.git
cd baidupan-cli
pip install -e .[dev]baidupan-cli --help
bdpan-cli --help
bdpan-wrapper --help本项目强依赖官方 bdpan CLI。
如果 bdpan 不在 PATH 中,可以显式指定:
Linux/macOS:
export BDPAN_BIN=/absolute/path/to/bdpanWindows PowerShell:
$env:BDPAN_BIN="C:\path\to\bdpan.exe"- 初始化配置文件
bdpan-cli config init- 创建绑定会话
bdpan-cli bind start --name primary返回结果中会包含:
account_idconfig_pathauth_url
- 拿到授权码后完成绑定
bdpan-cli bind complete --account-id <account_id> --code <auth_code>- 检查登录状态
bdpan-cli account user --account-id <account_id>- 列目录
bdpan-cli list /apps/bdpan --account-id <account_id>- 创建目录
bdpan-cli mkdir /apps/bdpan/releases --account-id <account_id>- 上传并分享
bdpan-cli upload ./demo.pdf /apps/bdpan/releases/demo.pdf --account-id <account_id>- 转存分享链接
bdpan-cli transfer "https://pan.baidu.com/s/xxxx" /apps/bdpan/inbox/demo --pwd 1234 --account-id <account_id>默认文件名为 config.json:
{
"BaiduPan": {
"runtime_home": "~/.bdpan-wrapper",
"bdpan_bin": "bdpan",
"default_account_id": ""
}
}字段说明:
runtime_home: 运行时根目录bdpan_bin: 官方bdpan可执行文件路径default_account_id: 默认账号 ID,省略--account-id时会优先使用
环境变量优先级高于配置文件:
BDPAN_WRAPPER_HOMEBDPAN_BIN
当前提供三层协议:
- 旧接口:
/api/* - 主接口:
/api/v1/* - 兼容接口:
/compat/baidu/*
建议新接入优先使用 /api/v1/*。
统一响应结构示例:
{
"success": true,
"code": 0,
"message": "ok",
"request_id": "xxxx",
"data": {}
}核心接口:
GET /api/v1/system/statusGET /api/v1/accountsGET /api/v1/tasksPOST /api/v1/accounts/bind/startPOST /api/v1/accounts/bind/completePOST /api/v1/accounts/{account_id}/checkPOST /api/v1/files/listPOST /api/v1/files/mkdirPOST /api/v1/files/upload-sharePOST /api/v1/files/browser-upload-sharePOST /api/v1/shares/transfer
兼容接口:
GET /compat/baidu/listPOST /compat/baidu/mkdirGET /compat/baidu/transferPOST /compat/baidu/transferPOST /compat/baidu/upload-share
启动 API 服务后可直接打开:
//portal/docs/redoc
.github/
workflows/
ci.yml
cmd/
bdpan-cli.py
deploy/
gcp/
docs/
ARCHITECTURE.md
sdk/
python/
README.md
src/
bdpan_wrapper/
accounts/
api/
bdpan/
runtime/
cli.py
tests/
test_api.py
test_bdpan_adapter.py
test_cli.py
test_runtime.py
test_services.py
模块职责:
accounts/: 账号元数据与持久化bdpan/: 官方bdpanCLI 适配层与输出解析services.py: 绑定、mkdir、ls、upload-share、transfer-share 主链服务runtime/: 运行时装配和目录初始化api/: FastAPI、OpenAPI 和浏览器测试台tests/: 以假适配器和假运行时覆盖主链逻辑
当前仓库已覆盖这些验证:
- CLI 帮助可正常输出
- 配置文件初始化可正常生成
- 绑定服务主链已由 service 测试覆盖
- mkdir / ls / upload-share / transfer-share 已由 service / api / adapter 测试覆盖
- API 门户页和主要接口由测试覆盖
已知边界:
- 真实百度侧联调依赖本机或服务器已安装可用的官方
bdpan - 当前测试以 fake adapter / fake runtime 为主,用于保证开源仓库结构和主链逻辑稳定
本项目是第三方开源封装,仅用于学习、自动化和合法合规的业务集成。
你需要自行确认:
- 账号使用符合百度网盘服务条款
- 部署、分享、分发行为符合当地法律法规
- 生产环境已做好权限控制、隔离和审计
- third-party open source wrapper, not an official Baidu project
- built on the official
bdpanCLI - one account maps to one config directory
- does not expose token or cookie handling
- does not require packet capture, web reverse engineering, or manual cookie maintenance
- account bind
- login state check
- directory listing
- directory creation
- file upload
- upload then create share link
- transfer a public share link
- primary working scope is
/apps/bdpan searchis excluded from the main support contract- upload verification should rely on
lsandshare, notsearch
git clone https://github.com/atuizz/baidupan-cli.git
cd baidupan-cli
pip install -e .[dev]baidupan-cli --help
bdpan-cli --help
bdpan-wrapper --helpThis project strongly depends on the official bdpan CLI.
If bdpan is not in PATH, set it explicitly:
Linux/macOS:
export BDPAN_BIN=/absolute/path/to/bdpanWindows PowerShell:
$env:BDPAN_BIN="C:\path\to\bdpan.exe"- Create a config file
bdpan-cli config init- Start an account bind session
bdpan-cli bind start --name primaryThe result includes:
account_idconfig_pathauth_url
- Complete bind with the auth code
bdpan-cli bind complete --account-id <account_id> --code <auth_code>- Check account login state
bdpan-cli account user --account-id <account_id>- List a directory
bdpan-cli list /apps/bdpan --account-id <account_id>- Create a directory
bdpan-cli mkdir /apps/bdpan/releases --account-id <account_id>- Upload and share
bdpan-cli upload ./demo.pdf /apps/bdpan/releases/demo.pdf --account-id <account_id>- Transfer a public share
bdpan-cli transfer "https://pan.baidu.com/s/xxxx" /apps/bdpan/inbox/demo --pwd 1234 --account-id <account_id>Default file name: config.json
{
"BaiduPan": {
"runtime_home": "~/.bdpan-wrapper",
"bdpan_bin": "bdpan",
"default_account_id": ""
}
}Fields:
runtime_home: runtime root directorybdpan_bin: path to the officialbdpanexecutabledefault_account_id: default account ID used when--account-idis omitted
Environment variables override config values:
BDPAN_WRAPPER_HOMEBDPAN_BIN
Three protocol layers are available:
- legacy endpoints:
/api/* - primary endpoints:
/api/v1/* - compatibility endpoints:
/compat/baidu/*
Recommended for new integrations: /api/v1/*
Unified response envelope example:
{
"success": true,
"code": 0,
"message": "ok",
"request_id": "xxxx",
"data": {}
}Core endpoints:
GET /api/v1/system/statusGET /api/v1/accountsGET /api/v1/tasksPOST /api/v1/accounts/bind/startPOST /api/v1/accounts/bind/completePOST /api/v1/accounts/{account_id}/checkPOST /api/v1/files/listPOST /api/v1/files/mkdirPOST /api/v1/files/upload-sharePOST /api/v1/files/browser-upload-sharePOST /api/v1/shares/transfer
Compatibility endpoints:
GET /compat/baidu/listPOST /compat/baidu/mkdirGET /compat/baidu/transferPOST /compat/baidu/transferPOST /compat/baidu/upload-share
After starting the API server, open:
//portal/docs/redoc
See docs/ARCHITECTURE.md for a bilingual breakdown of module boundaries, runtime wiring, and request flow.
The repository currently verifies:
- CLI help output
- config initialization
- bind flow at the service layer
- mkdir / ls / upload-share / transfer-share at service, adapter, and API layers
- portal page and primary API routes
Known boundary:
- real Baidu-side verification still depends on an environment with a working official
bdpan - most tests use fake adapters and fake runtimes to guarantee repository structure and main-chain behavior
This is a third-party open source wrapper for learning, automation, and legitimate service integration.
You are responsible for ensuring:
- your account usage complies with Baidu Netdisk terms
- your deployment and sharing flows comply with local law and policy
- your production environment has proper isolation, audit, and access control
MIT