Skip to main content

Python SDK for Cloudreve V3 and V4

Project description

Cloudreve SDK

本项目为第三方制作Cloudreve V3 和 V4 社区版的 Python SDK。

安装

pip3 install cloudreve

适配情况

功能 V3 适配情况 V4 适配情况
登录
列目录
获取文件ID 不需要
删除文件
获取文件属性
获取下载URL
下载文件
创建目录
复制文件
重命名文件
移动文件
获取文件直链
获取分享链接
上传文件(本地存储)
上传文件(OneDrive)
上传文件(OSS) 待测试 待测试
上传文件(从机模式) ✅(未经测试)

说明:

  • V4 版本使用 URI 来标识文件和目录,不再需要文件ID。
  • “待测试”表示该功能已实现,但由于缺乏测试环境,暂未进行测试,也没有公开使用。如果你使用该存储方案搭建 Cloudreve V4,并且愿意协助测试该功能,请您联系我。

示例(V3)

  • 每个方法都写了详细注释,可以直接阅读源码了解
  • 除少数特殊说明的接口外,几乎所有对文件的操作都需要使用由字母和数字组成的文件ID作为参数
from cloudreve import Cloudreve

# 初始化
conn = Cloudreve('http://127.0.0.1:5212')

# 登录
conn.login('admin@cloudreve.org', '123456')

# 列目录
conn.list("/")

# 获取文件ID
file_id = conn.get_id('/hello.py')

# 删除文件
conn.delete(file_id, is_dir=False)

# 获取文件属性
data = conn.get_property(file_id)
print(data)

# 获取临时下载URL
url = conn.get_download_url(file_id)

# 下载文件到本地
conn.download(file_id, 'hello_world.py')

# 创建目录
conn.create_dir('/python')

# 复制文件
conn.copy('/hello.py', '/python')

# 重命名文件
conn.rename(file_id, 'world.py')

# 移动文件
conn.move('/world.py', '/python')

# 上传文件
conn.upload('/my_file_backup.py', 'D:/my_file.py')

# 获取文件直链(永久有效)
# 直接返回直链
source_link_str = conn.get_source_url(file_id)
# 返回直链和文件名组成的字典
source_link_dict = conn.get_source_url(file_id, url_only=False)
# 同时获取多个文件,由于Cloudreve API实现问题,此时url_only参数必须为False,返回无序列表
list_of_source_link_dicts = conn.get_source_url([file_id], url_only=False)

# 获取分享链接
# 普通分享文件
share_link_str1 = conn.get_share_url(file_id)
# 禁止预览,下载次数限制为10次,过期时间为一天,密码为123456
share_link_str2 = conn.get_share_url(file_id, preview=False, downloads=10, expire=86400, password='123456')
# 分享文件夹
share_link_str3 = conn.get_share_url('IdOfDir', is_dir=True)

示例(V4)

  • 原则上,Cloudreve V4 使用以 cloudreve:// 开头的 URI 来标识文件和目录,但你可以在使用本 SDK 时,直接使用以 / 开头的路径,程序会自动转换为 URI。
  • Cloudreve V4 的 List 接口有分页选项,具体请参考 List files - Cloudreve API Docs
from cloudreve import CloudreveV4

# 初始化
conn = CloudreveV4('http://127.0.0.1:5212')

# 登录
conn.login('admin@cloudreve.org', '123456')

# 列目录
conn.list("/")

uri = '/hello.txt'

# 获取文件属性
data = conn.get_info(uri)
print(data)

# 删除文件
conn.delete(uri)

# 下载文件到本地
conn.download(url, './hello_world.txt')

# 创建目录
conn.create_folder('/python')

# 复制文件
conn.copy('/hello.txt', '/python')

# 重命名文件
conn.rename(uri, 'world.txt')

# 移动文件
conn.move('/world.py', '/python')

# 上传文件
conn.upload('D:/my_file.py', '/my_file_backup.py')

# 创建文件
conn.create_file('/new_file.txt')

# 更新文件
conn.update_file_content('/new_file.txt', 'This is the content of the new file.')

# 获取文件直链(永久有效)
# 简单获取(返回字符串)
source_link_str = conn.get_source_url(uri)
# 获取多个文件(返回由字典组成的列表)
list_of_source_link_dict = conn.get_source_url([uri1, uri2])

# 获取分享链接
# 普通分享文件
share_link_str1 = conn.get_share_url(uri)
# 下载次数限制为10次,过期时间为一天,密码为123456
share_link_str2 = conn.get_share_url(uri, downloads=10, expire=86400, password='123456')

联系我们

感谢

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

cloudreve-2.0.2.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

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

cloudreve-2.0.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file cloudreve-2.0.2.tar.gz.

File metadata

  • Download URL: cloudreve-2.0.2.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for cloudreve-2.0.2.tar.gz
Algorithm Hash digest
SHA256 4e2ffdbe13b2f2510a2d2712589817a1226f24212c9f6fb7fc9c6187ccdcb995
MD5 192b6793ac8fdfa5cd8ef7f86d87499f
BLAKE2b-256 ac10dc4b3779f574014fe509c806473d480e68cc2acbb9ba0cf72b7655d837cb

See more details on using hashes here.

File details

Details for the file cloudreve-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: cloudreve-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for cloudreve-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54d50f6f139113304740d2fba44a4520c751f13f3b68f182ed74c0b36ef649e2
MD5 f14e664ea891414f7562a148ca11bfa9
BLAKE2b-256 8f41849e51c667e3369db201e21babdf91017025c297d1b81dfff87a460f9d65

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