A client library for pCloud
Project description
This Python (Version >= 3.6 only!) library provides a Python API to the pCloud storage.
Features
Can be used as a library
Comes with a command line script
Provides a PyFileSystem implementation
Examples
Usage of API
>>> from pcloud import PyCloud >>> pc = PyCloud('email@example.com', 'SecretPassword') >>> pc.listfolder(folderid=0)
Use alternate endpoints (API calls have to be made to the correct API host name depending were the user has been registered – api.pcloud.com for United States and eapi.pcloud.com for Europe.)
>>> from pcloud import PyCloud >>> pc = PyCloud('email@example.com', 'SecretPassword', endpoint="eapi") >>> pc.listfolder(folderid=0)
PyCloud also provides an API method to retrieve the nearest API server, which gives you a speed gain for some API operations. To use PyCloud with this feature create the PyCloud-object with the nearest endpoint parameter:
>>> from pcloud import PyCloud >>> pc = PyCloud('email@example.com', 'SecretPassword', endpoint="nearest") >>> pc.listfolder(folderid=0)
OAuth 2.0 authentication
To use OAuth 2.0 authentication you need to create an App in pCloud (https://docs.pcloud.com/my_apps/).
Add the following redirect URI http://localhost:65432/ (Make sure port 65432 is available on your machine. Otherwise you need to adjust the PORT in oauth2.py)
Note! To see the redirect URI in the settings of pCloud you have to log out and log in again.
Once you finished adding the app and setting the redirect URI you are ready to use OAuth 2.0 with PyCloud on your machine. For the communication with pCloud PyCloud uses the builtin webserver-module.
>>> from pcloud import PyCloud >>> pc = api.PyCloud.oauth2_authorize(client_id="XYZ", client_secret="abc123") >>> pc.listfolder(folderid=0)
Uploading files
from filenames:
>>> pc.uploadfile(files=['/full/path/to/image1.jpg', '/Users/tom/another/image.png'], ... path='/path-to-pcloud-dir')
from data:
>>> 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')
Usage of PyFilesystem with opener
>>> from fs import opener >>> opener.open_fs('pcloud://email%40example.com:SecretPassword@/') <pCloudFS>
Copying files from Linux to pCloud using PyFilesystem
>>> 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')
Copy directory from Linux to pCloud using PyFilesystem
>>> 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/')
Further Documentation
Implements the pCloud API found at https://docs.pcloud.com/
Installation
$ pip install pcloud
Installation with PyFilesystem support
$ bin/pip install pcloud[pyfs]
on zsh (Mac):
$ bin/pip install “pcloud[pyfs]”
Development
For testing purposes a mock server is provided. To use this mock server you need to add a file with the same name as the method + the .json suffix in the tests/data directory (like getdigest.json). The file contains the expected JSON result.
Contribute
Issue Tracker: https://github.com/tomgross/pycloud/issues
Source Code: https://github.com/tomgross/pycloud
License
The project is licensed under MIT (see LICENSE).
Contributors
Tom Gross, itconsense@gmail.com
Massimo Vannucci (blasterspike)
Yennick Schepers (yennicks)
olokelo
qo4on
Changelog
1.0a10 (2021-07-11)
State and test Python 3.9 support [tomgross]
OAuth 2.0 implementation [tomgross]
Implement more general methods [tomgross]
Implement get nearest api server [tomgross]
1.0a9 (2021-01-22)
Missing variable in output in case a directory already exists
Changed errors raised for makedirs
Do not raise an errors.DirectoryExists when recreate = True
Added examples to README [blasterspike]
Fix parameter of downloadlink method [tomgross]
Add more details on authentication error [yennicks]
Add new stats endpoint [AgusRumayor]
Add methods for archiving [olokelo]
Add token expire parameter [olekelo]
Start implementing trash methods [qo4on, tomgross]
Add support for alternate endpoints [tomgross]
Add Contributors and fix README ReST Syntax
1.0a8 (2020-02-21)
Fix upload of multiple files from paths [tomgross]
Document uploading of files [tomgross]
1.0a7 (2020-02-20)
Add new API method createfolderifnotexists #19 [Arkoniak, tomgross]
Fix duplication of data transfer on file upload #17 [blasterspike, tomgross]
Consistently use MIT licences [tomgross]
1.0a6 (2019-01-18)
Fix error while using makedirs from PyFilesystem with recreate=True [blasterspike]
1.0a5 (2018-10-22)
Fix error while using makedirs from PyFilesystem https://github.com/tomgross/pycloud/issues/10 [blasterspike]
Test and claim Python 3.7 compatibility [tomgross]
1.0a4 (2017-10-29)
Fix error with duplicate files parameter #3 [tomgross]
Fix upload of data [tomgross]
Do flake8 checks [tomgross]
1.0a3 (2017-10-07)
Test API with py.test [tomgross]
Support for PyFileSystem [tomgross]
Support for file operations [tomgross]
1.0a2 (2017-05-21)
Rename to pcloud [tomgross]
1.0a1 (2017-05-21)
Initial release. [tomgross]
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
File details
Details for the file pcloud-1.0a10.tar.gz
.
File metadata
- Download URL: pcloud-1.0a10.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71755077e0f350f6d31576fe5382db0660f39f76d79b1e4c7d670d530b62b4ce |
|
MD5 | 7d12d264ecaf7316c96bd47bb48ed6fd |
|
BLAKE2b-256 | 685e140f920072085c9a627f645a4274890e5fb6668352d8a4a146291f1df20c |