All Projects → tomgross → pycloud

tomgross / pycloud

Licence: MIT license
A Python implementation of the pCloud API

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pycloud

pcloud-console-client
A simple console client for pCloud cloud storage.
Stars: ✭ 22 (-59.26%)
Mutual labels:  pcloud, pcloud-api, pcloud-client
pcloud-sdk-js
pCloud's Javascript SDK
Stars: ✭ 62 (+14.81%)
Mutual labels:  api-client, pcloud
sypht-golang-client
A Golang client for the Sypht API
Stars: ✭ 33 (-38.89%)
Mutual labels:  api-client
deepl-api-connector
Connector library for deepl.com rest translation api
Stars: ✭ 12 (-77.78%)
Mutual labels:  api-client
chess.com
Python wrapper for Chess.com Published-Data API
Stars: ✭ 34 (-37.04%)
Mutual labels:  api-client
adyen-python-api-library
Adyen API Library for Python
Stars: ✭ 41 (-24.07%)
Mutual labels:  api-client
notion-sdk-py
Official Notion SDK rewritten in Python (sync + async)
Stars: ✭ 753 (+1294.44%)
Mutual labels:  api-client
fs-pochta-api
Библиотека для работы с API Почты России
Stars: ✭ 15 (-72.22%)
Mutual labels:  api-client
transip-api
Python implementation for the TransIP API
Stars: ✭ 23 (-57.41%)
Mutual labels:  api-client
sbankenclient-ios
A small but enjoyable iOS framework to connect to the Sbanken API
Stars: ✭ 21 (-61.11%)
Mutual labels:  api-client
ccViewer
CryptCloudViewer source codes
Stars: ✭ 66 (+22.22%)
Mutual labels:  pcloud
upcloud-php-api
PHP client for UpCloud's API
Stars: ✭ 23 (-57.41%)
Mutual labels:  api-client
AutoMeter-API
AutoMeter-API是一款针对分布式服务,微服务API功能和性能一体的自动化测试平台,一站式解决应用,服务,API,环境管理,用例,条件,测试场景,计划,测试报告,功能/性能测试兼容支持的一体化工作平台
Stars: ✭ 105 (+94.44%)
Mutual labels:  api-client
sevenbridges-python
SevenBridges Python Api bindings
Stars: ✭ 41 (-24.07%)
Mutual labels:  api-client
lpconnector
Python client for syncing LastPass Enterprise with a remote directory over LDAP
Stars: ✭ 14 (-74.07%)
Mutual labels:  api-client
jusibe
📲 JavaScript client for Jusibe.com SMS API service. http://jusibe.com
Stars: ✭ 24 (-55.56%)
Mutual labels:  api-client
AlphaVantage.Net
.Net client library for Alpha Vantage API
Stars: ✭ 65 (+20.37%)
Mutual labels:  api-client
servicenow
A golang client for ServiceNow
Stars: ✭ 16 (-70.37%)
Mutual labels:  api-client
airtabler
R interface to the Airtable API
Stars: ✭ 84 (+55.56%)
Mutual labels:  api-client
ninja automator
Acquire data with honour and wisdom — using the way of the ninja.
Stars: ✭ 21 (-61.11%)
Mutual labels:  api-client

pcloud - A Python API client for pCloud

https://travis-ci.org/tomgross/pycloud.svg?branch=master

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 protected]', '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 protected]', '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 protected]', '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. 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 mode

OAuth 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 the pycloud_oauth2-fixture in test_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 files

  1. from filenames:
>>> pc.uploadfile(files=['/full/path/to/image1.jpg', '/Users/tom/another/image.png'],
...     path='/path-to-pcloud-dir')
  1. 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

License

The project is licensed under MIT (see LICENSE).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].