适用于pCloud的客户端库
项目描述
此Python (仅限版本 >= 3.6) 库为pCloud存储提供了Python API。
功能
可以作为库使用
提供PyFileSystem实现
示例
API使用方法
>>> from pcloud import PyCloud >>> pc = PyCloud('email@example.com', 'SecretPassword') >>> pc.listfolder(folderid=0)
使用备用端点(API调用必须针对用户注册的正确API主机名进行 - 美国为api.pcloud.com,欧洲为eapi.pcloud.com。)
>>> from pcloud import PyCloud >>> pc = PyCloud('email@example.com', 'SecretPassword', endpoint="eapi") >>> pc.listfolder(folderid=0)
PyCloud还提供了一个API方法来检索最近的API服务器,这可以在某些API操作中获得速度提升。要使用具有此功能的PyCloud,请使用nearest端点参数创建PyCloud对象
>>> from pcloud import PyCloud >>> pc = PyCloud('email@example.com', 'SecretPassword', endpoint="nearest") >>> pc.listfolder(folderid=0)
OAuth 2.0认证
要使用OAuth 2.0认证,您需要在pCloud中创建一个应用(https://docs.pcloud.com/my_apps/)。
添加以下重定向URI https://127.0.0.1:65432/(请确保您的机器上端口65432可用。否则,您需要调整oauth2.py中的PORT)
注意!要查看pCloud设置中的重定向URI,您必须注销并重新登录。
一旦完成添加应用和设置重定向URI,您就可以在您的计算机上使用OAuth 2.0和PyCloud了。PyCloud与pCloud的通信使用内置的 webserver 模块,这意味着您需要在系统上有一个真正的浏览器。
>>> from pcloud import PyCloud >>> pc = PyCloud.oauth2_authorize(client_id="XYZ", client_secret="abc123") >>> pc.listfolder(folderid=0)
无头模式
OAuth 2.0旨在使用浏览器进行身份验证流程。尽管如此,Selenium可以用来自动化此过程。有关示例,请参阅 test_oauth2.py 中的 pycloud_oauth2-fixture。由于存在太多的依赖关系,此方法不会集成为主功能,但您可以用作您的用例示例。
上传文件
从文件名
>>> pc.uploadfile(files=['/full/path/to/image1.jpg', '/Users/tom/another/image.png'], ... path='/path-to-pcloud-dir')
从数据
>>> import io >>> from PIL import Image >>> img = Image.open('image.jpg', 'r') >>> bio = io.BytesIO() >>> img.save(bio, format='jpeg') >>> pc.uploadfile(data=bio.getvalue(), filename="image.jpg", path='/path-to-pcloud-dir')
使用opener与PyFilesystem的使用
>>> from fs import opener >>> opener.open_fs('pcloud://email%40example.com:SecretPassword@/') <pCloudFS>
使用PyFilesystem从Linux复制文件到pCloud
>>> from fs import opener, copy >>> with opener.open_fs('pcloud://email%40example.com:SecretPassword@/') as pcloud_fs: >>> with opener.open_fs('/opt/data_to_copy') as linux_fs: >>> copy.copy_file(src_fs=linux_fs, >>> src_path='database.sqlite3', >>> dst_fs=pcloud_fs, >>> dst_path='/backup/server/database.sqlite3')
使用PyFilesystem从Linux复制目录到pCloud
>>> from fs import opener, copy >>> with opener.open_fs('pcloud://email%40example.com:SecretPassword@/') as pcloud_fs: >>> with opener.open_fs('/opt/data_to_copy') as linux_fs: >>> copy.copy_dir(src_fs=linux_fs, >>> src_path='database/', >>> dst_fs=pcloud_fs, >>> dst_path='/backup/database/')
更多文档
实现了位于 https://docs.pcloud.com/ 的pCloud API
安装
$ pip install pcloud
带有PyFilesystem支持的安装
$ bin/pip install pcloud[pyfs]
在zsh(Mac)上
$ bin/pip install “pcloud[pyfs]”
开发
出于测试目的,提供了一个模拟服务器。要使用此模拟服务器,您需要在tests/data目录中添加一个与方法同名并带有 .json 后缀的文件(如 getdigest.json)。该文件包含预期的JSON结果。
贡献
许可证
本项目采用MIT许可(见LICENSE)。
贡献者
Tom Gross, itconsense@gmail.com
Massimo Vannucci (blasterspike)
Yennick Schepers (yennicks)
olokelo
qo4on
变更日志
1.3 (2024-03-01)
重新实现pyfs集成 [tomgross]
更新(测试)依赖关系,仅在Python 3.8-3.12上运行测试 [tomgross]
添加了更多的API方法 [tomgross]
1.2 (2023-06-24)
添加 CONTRIBUTING 指南并更新 CODE_OF_CONDUCT 文档 [tomgross]
添加Sonarcloud检查器并报告测试覆盖率 [tomgross]
添加listtokens端点的测试 [tomgross]
将仓库名称更改为 https://github.com/tomgross/pcloud/ 以保持一致 (https://github.com/tomgross/pcloud/issues/70) [tomgross]
实现 sharefolder-端点 [tomgross]
用 multipart 替换 cgi.FieldStorage,避免Python 3.11弃用的 cgi 模块。 [tomgross]
1.1 (2022-11-14)
修复带有int folderid的文件上传 #63 [tomgross]
添加pytest超时并更新测试依赖项 [tomgross]
实现 copyfile 和 downloadfileasync 方法 [tomgross]
实现 setlanguage、getfeedback、diff 和 getfilehistory 方法 [tomgross]
1.0 (2022-02-02)
🎉 作为1.0发布,未作更改 🎉
1.0b2(2021-12-17)
构建wheel包 [tomgross]
修复带有oauth的文件上传 [giust]
自动测试OAuth [tomgross]
记录了无头OAuth [tomgross]
1.0b1(2021-11-26)
Python 3.10兼容性和依赖关系更新
更改测试服务器的端口 5000 -> 5023
添加 getpubzip API方法 (https://github.com/tomgross/pcloud/issues/51)
通过使用requests_toolbelt的MultipartEncoder允许上传大文件 (https://github.com/tomgross/pcloud/issues/25、https://github.com/tomgross/pcloud/issues/44)
记录登录过程 [tomgross]
1.0a10(2021-07-11)
测试Python 3.9支持 [tomgross]
OAuth 2.0实现 [tomgross]
实现更通用的方法 [tomgross]
实现获取最近的API服务器 [tomgross]
1.0a9(2021-01-22)
在目录已存在的情况下,输出中缺少变量
更改makedirs引发的错误
当recreate = True时,不要引发errors.DirectoryExists错误
将示例添加到README [blasterspike]
修复下载链接方法的参数 [tomgross]
增加对认证错误的更多详细信息 [yennicks]
添加新的统计端点 [AgusRumayor]
添加归档方法 [olokelo]
添加令牌过期参数 [olekelo]
开始实现废纸箱方法 [qo4on, tomgross]
添加对替代端点的支持 [tomgross]
添加贡献者并修复README ReST语法
1.0a8 (2020-02-21)
修复从路径上传多个文件的错误 [tomgross]
记录文件上传 [tomgross]
1.0a7 (2020-02-20)
添加新的API方法 createfolderifnotexists #19 [Arkoniak, tomgross]
修复文件上传上数据传输的重复 #17 [blasterspike, tomgross]
统一使用MIT许可证 [tomgross]
1.0a6 (2019-01-18)
修复使用PyFilesystem的makedirs时出现的错误,recreate=True [blasterspike]
1.0a5 (2018-10-22)
修复使用PyFilesystem的makedirs时出现的错误 https://github.com/tomgross/pcloud/issues/10 [blasterspike]
测试并声明与Python 3.7的兼容性 [tomgross]
1.0a4 (2017-10-29)
修复重复文件参数错误 #3 [tomgross]
修复数据上传 [tomgross]
执行flake8检查 [tomgross]
1.0a3 (2017-10-07)
使用py.test测试API [tomgross]
支持PyFileSystem [tomgross]
支持文件操作 [tomgross]
1.0a2 (2017-05-21)
重命名为pcloud [tomgross]
1.0a1 (2017-05-21)
首次发布。 [tomgross]
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码发行版
构建发行版
pcloud-1.3.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 01d9409ddad5f5aaea914f468eaca6cfb54a5d60adf6bf95a7dae10de52c9350 |
|
MD5 | c0d840cd1cb49915a67c68a8ec7c2d2b |
|
BLAKE2b-256 | 5306c3fa1356701dd9b0484d35d68b40f8fcfe2d1f98b353135e6f17900492ce |