Package: pcloud
This Python(Version >= 3.6 only!)library provides a Python API to the pCloud storage.FeaturesCan be used as a libraryComes with a command line scriptProvides a PyFileSystem implementationExamplesUsage 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 thenearestendpoint parameter:>>> from pcloud import PyCloud
>>> pc = PyCloud('email@example.com', 'SecretPassword', endpoint="nearest")
>>> pc.listfolder(folderid=0)OAuth 2.0 authenticationTo use OAuth 2.0 authentication you need to create an App in pCloud (https://docs.pcloud.com/my_apps/).Add the following redirect URIhttp://localhost:65432/(Make sure port 65432 is available on your machine. Otherwise you need to adjust thePORTin 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
builtinwebserver-module. This means you need a real browser on your system available.>>> from pcloud import PyCloud
>>> pc = PyCloud.oauth2_authorize(client_id="XYZ", client_secret="abc123")
>>> pc.listfolder(folderid=0)Headless modeOAuth 2.0 is designed to use a browser for the authentication flow. Nevertheless Selenium
can be used to automate this process. For an example see thepycloud_oauth2-fixture intest_oauth2.py.
This method will not integrated as main functionality, since there are too many dependencies.
You can use it as example for your usecase.Uploading filesfrom 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 DocumentationImplements the pCloud API found athttps://docs.pcloud.com/Installation$ pip install pcloudInstallation with PyFilesystem support$ bin/pip install pcloud[pyfs]on zsh (Mac):$ bin/pip install “pcloud[pyfs]”DevelopmentFor 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.jsonsuffix
in the tests/data directory (likegetdigest.json).
The file contains the expected JSON result.ContributeIssue Tracker:https://github.com/tomgross/pcloud/issuesSource Code:https://github.com/tomgross/pcloudLicenseThe project is licensed under MIT (see LICENSE).ContributorsTom Gross,itconsense@gmail.comMassimo Vannucci (blasterspike)Yennick Schepers (yennicks)olokeloqo4onChangelog1.2 (2023-06-24)AddCONTRIBUTINGguideline and updateCODE_OF_CONDUCTdocument [tomgross]Add Sonarcloud checker and report test coverage [tomgross]Add test for listtokens endpoint [tomgross]Changed repo name tohttps://github.com/tomgross/pcloud/to be consistent (https://github.com/tomgross/pcloud/issues/70) [tomgross]Implementsharefolder-endpoint [tomgross]Replacecgi.FieldStoragebymultipartavoiding
thecgimodule deprecated by Python 3.11. [tomgross]1.1 (2022-11-14)Fix upload with int folderid #63 [tomgross]Add pytest timeout and update testing dependencies [tomgross]Implementcopyfileanddownloadfileasyncmethods [tomgross]Implementsetlanguage,getfeedback,diff&getfilehistorymethods [tomgross]1.0 (2022-02-02)🎉 Release unchanged as 1.0 🎉1.0b2 (2021-12-17)Build wheel package [tomgross]Fix file upload with oauth [giust]Automated test for OAuth [tomgross]Documented headless OAuth [tomgross]1.0b1 (2021-11-26)Python 3.10 compatibility and dependency updatesChange port of test server 5000 -> 5023AddgetpubzipAPI method (https://github.com/tomgross/pcloud/issues/51)Allow uploading BIG files by using MultipartEncoder of requests_toolbelt
(https://github.com/tomgross/pcloud/issues/25,https://github.com/tomgross/pcloud/issues/44)Log login process
[tomgross]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 existsChanged errors raised for makedirsDo not raise an errors.DirectoryExists when recreate = TrueAdded 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 Syntax1.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 methodcreatefolderifnotexists#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 PyFilesystemhttps://github.com/tomgross/pcloud/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]