Skip to main content

123云盘 API Python SDK,支持 OAuth2 和密钥认证

Project description

v123pan - 123云盘 Python SDK

123云盘 API 的 Python SDK,支持 OAuth2 和密钥认证两种方式。

特性

  • 🎯 简洁易用的 API 设计
  • 🔐 支持 OAuth2 认证(refresh_token 自动刷新)
  • 🔑 支持密钥认证
  • 📁 完整的文件操作接口
  • ⬆️ 文件上传下载支持
  • 🔄 离线下载支持
  • 📱 异步支持(基于 httpx)

安装

pip install v123pan

快速开始

OAuth2 认证(推荐)

import asyncio
from v123pan import V123Pan
from v123pan.const import FILMLY_CLIENT_ID, FILMLY_CLIENT_SECRET

async def main():
    # 创建客户端
    client = V123Pan(
        client_id=FILMLY_CLIENT_ID,
        client_secret=FILMLY_CLIENT_SECRET,
        oauth_file="token.json"
    )
    
    # 交互式授权(首次使用)
    result = await client.auth.authorize_interactive(
        FILMLY_CLIENT_ID,
        FILMLY_CLIENT_SECRET,
        oauth_file="token.json"
    )
    
    # 后续使用会自动加载 token
    user_info = await client.user.info()
    print(f"用户名: {user_info['data']['nickname']}")

asyncio.run(main())

密钥认证

import asyncio
from v123pan import V123Pan

async def main():
    client = V123Pan(
        client_id="your_client_id",
        client_secret="your_client_secret"
    )
    
    user_info = await client.user.info()
    print(f"用户名: {user_info['data']['nickname']}")

asyncio.run(main())

使用示例

获取文件列表

# 获取根目录文件
files = await client.file.list_files(parent_id=0, limit=50)
for f in files['data']['fileList']:
    print(f"{'📁' if f['type'] == 1 else '📄'} {f['filename']}")

上传文件

# 上传文件
result = await client.upload.upload_file(
    parent_file_id=0,
    file_path="example.txt"
)

下载文件

# 获取下载链接
download_url = await client.download.get_download_url(file_id=12345)
print(f"下载地址: {download_url['data']['url']}")

认证说明

OAuth2 认证

使用 Filmly 官方 OAuth2 配置:

  • client_id: uch86homnvtpukbenxv06whun7oayymz
  • client_secret: qxlth6oludklrutxxz8h4dh6jgicpe28
  • redirect_uri: https://api.filmly.netease.com/a/v1/123pan/callback
  • scope: user:base,file:all:read,file:all:write

授权后 token 会自动保存到文件,后续使用无需重新授权。

密钥认证

需要购买 123云盘开发者权益包获取 client_idclient_secret

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

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

v123pan-1.0.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

v123pan-1.0.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file v123pan-1.0.0.tar.gz.

File metadata

  • Download URL: v123pan-1.0.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for v123pan-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4a4af0dbda08a11fc867cac60d53fdf4e0bf6a87d289d3571f6aff88bf98d501
MD5 6cf0144e6cba25e72f8116c1554773ae
BLAKE2b-256 f2769a651280833ea9aea89f269d86db6bacd859ffe3a603d35d8b089b16a14b

See more details on using hashes here.

File details

Details for the file v123pan-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: v123pan-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for v123pan-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce3dad588182ac1312f2ec6243b82bfd2ed5de7d3bf6e826d3cf2260bb975f35
MD5 815edf0b425ec2ab4995e84608eba97a
BLAKE2b-256 ab32b8e4334540ffe66cbfeaa41773d6aed7fd0faabe90a9d3942f0e13bfcc2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page