A simple Baidu Netdisk client for upload, download, and file listing.
Project description
baidu-disk-client
A simple Python client for Baidu Netdisk.
This package provides basic Baidu Netdisk operations, including:
- Upload files
- List remote files
- Download files
- Manage access token and refresh token locally
This is an unofficial Baidu Netdisk client.
Installation
For local development:
pip install -e .
After publishing to PyPI:
pip install baidu-disk-client
Requirements
- Python 3.9+
- requests
Authorization
Authorization
Before using this client, you need to create an application on Baidu Open Platform and get:
- app name
- app id
- app key
- secret key
- sign key
- authorization code
The authorization code is only used for the first token exchange. After the first successful authorization, token information will be saved locally in bd_trans.json. Do not commit bd_trans.json, .env, access tokens, refresh tokens, app keys, or secret keys to Git.
Usage
upload file
import os
from baidu_disk_client import BaiduDiskClient
client = BaiduDiskClient(
app_name=os.environ["BAIDU_APP_NAME"],
app_id=os.environ["BAIDU_APP_ID"],
app_key=os.environ["BAIDU_APP_KEY"],
secret_key=os.environ["BAIDU_SECRET_KEY"],
sign_key=os.environ["BAIDU_SIGN_KEY"],
grant_code=os.environ.get("BAIDU_GRANT_CODE"),
)
result = client.upload(
file_path="demo.txt",
remote_dir_path="/my_uploads",
)
print(result)
list files
import os
from baidu_disk_client import BaiduDiskClient
client = BaiduDiskClient(
app_name=os.environ["BAIDU_APP_NAME"],
app_id=os.environ["BAIDU_APP_ID"],
app_key=os.environ["BAIDU_APP_KEY"],
secret_key=os.environ["BAIDU_SECRET_KEY"],
sign_key=os.environ["BAIDU_SIGN_KEY"],
grant_code=os.environ.get("BAIDU_GRANT_CODE"),
)
files = client.list_files("/my_uploads")
for item in files:
print(item["server_filename"], item["path"])
Download file
import os
from baidu_disk_client import BaiduDiskClient
client = BaiduDiskClient(
app_name=os.environ["BAIDU_APP_NAME"],
app_id=os.environ["BAIDU_APP_ID"],
app_key=os.environ["BAIDU_APP_KEY"],
secret_key=os.environ["BAIDU_SECRET_KEY"],
sign_key=os.environ["BAIDU_SIGN_KEY"],
grant_code=os.environ.get("BAIDU_GRANT_CODE"),
)
client.download_one_file(
remote_file_path="/my_uploads/demo.txt",
save_path="downloads/demo.txt",
)
Notes
- remote_dir_path should be a Baidu Netdisk remote directory path.
- If remote_dir_path is not provided when uploading, the file will be uploaded to the app directory by default.
- Token configuration is saved in bd_trans.json.
- Keep your credentials private.
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
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
File details
Details for the file baidu_disk_client-0.1.0.tar.gz.
File metadata
- Download URL: baidu_disk_client-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8544732d3f0fc29a29612d5f8b8f5ba513c2250da8e25612264544f09331b73
|
|
| MD5 |
40a900a751ac15e502de26f86e1ca5cd
|
|
| BLAKE2b-256 |
94bbdc8e5d32d99fd4df8443f98963703f047d6a4b7dd22b27d2e16f4fc7e9bf
|
File details
Details for the file baidu_disk_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: baidu_disk_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1b46f8b3dfd609e6b82f8037baeb5310d4fbd450e934ca8d4ae3183f0567917
|
|
| MD5 |
bc4b23ca4d72c48146ca369b2d41b55b
|
|
| BLAKE2b-256 |
13f9de6d0b978d276dfeb5013a44bd75e4cddf1a0efb4f7f54935cad994a6639
|