Skip to main content

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.

Metadata

Release files for baidu-disk-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for baidu-disk-client 0.1.0
File Size Uploaded Provenance
baidu_disk_client-0.1.0.tar.gz 7.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for baidu-disk-client 0.1.0
File Interpreter ABI Platform
baidu_disk_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / baidu_disk_client-0.1.0.tar.gz

Download URL baidu_disk_client-0.1.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f8544732d3f0fc29a29612d5f8b8f5ba513c2250da8e25612264544f09331b73
BLAKE2b-256 checksum
How to use checksums
94bbdc8e5d32d99fd4df8443f98963703f047d6a4b7dd22b27d2e16f4fc7e9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release files / baidu_disk_client-0.1.0-py3-none-any.whl

Download URL baidu_disk_client-0.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1b46f8b3dfd609e6b82f8037baeb5310d4fbd450e934ca8d4ae3183f0567917
BLAKE2b-256 checksum
How to use checksums
13f9de6d0b978d276dfeb5013a44bd75e4cddf1a0efb4f7f54935cad994a6639
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Security for baidu-disk-client 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page