Skip to content

Use CloudFS to quickly integrate cloud storage into your Python application

License

Notifications You must be signed in to change notification settings

gordillo/CloudFS-Python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CloudFS-Python SDK 1.0

Python SDK for CloudFS. This SDK provides access to the CloudFS API through native python objects.

Limitations

This release fully supports CloudFS with the following exceptions:

  • The file-like functions on the CloudFS File object are incomplete.
  • Some of the folder list options (such as filter) are not implemented.

We think these limitations are relatively minor. If they restrict your planned use cases, please contact us over email or open a pull request.

Future Plans

We would like to make the SDK more pythonic, but we also want consistent behavior around request usage and keeping data fresh, so those features will come in subsequent updates.

Installation

pip install cloudfs_sdk

Hello World

Here's the CloudFS equivalent of Hello World: CLIENT_ID, CLIENT_SECRET, and BASE_URL should use the values given in your CloudFS account. TEST_USERNAME & TEST_USER_PASSWORD should be set to the info for a test user of your CloudFS application.

from cloudfs import Session, InvalidRequest, ExistValues

CLIENT_ID = ''
CLIENT_SECRET = ''
BASE_URL = ''

TEST_USERNAME = ''
TEST_USER_PASSWORD = ''

# Create a session
s = Session(BASE_URL,
    CLIENT_ID,
    CLIENT_SECRET
    )

# Authenticate session with test user
try:
    s.authenticate(TEST_USERNAME, TEST_USER_PASSWORD)
except InvalidRequest:
    print "Check CLIENT_ID, CLIENT_SECRET and BASE_URL. If they are correct, check username and password."
    exit(1)

# Get filesystem object
fs = s.filesystem()

# Print the contents of an empty root
print "FS Root is empty: {}".format(fs.root().list())

# Create a folder in the root of the filesystem
cloud_folder = fs.root().create_folder("My First Folder", exists=ExistValues.overwrite)

# Print the contents of root
print "FS Root contains a new folder: {}".format(fs.root().list())
print "Our new folder is empty: {}".format(cloud_folder.list())

# Create a file inside our new folder using inline data
cloud_file = cloud_folder.upload(None, name='Hello.txt', exists=ExistValues.overwrite, file_content="Hello World!")

# List our folder again
print "Our new folder now has a file: {}".format(cloud_folder.list())
print "Our file contents: {}".format(cloud_file.read())

# Permanently delete the folder we created and the file in it.
cloud_folder.delete(commit=True, force=True)

Extra Notes

All calls have an optional debug parameter that will print the request & response associated with that request. The CloudFSRESTAdapter also has a method to get this as a string to help debug any difficulties. Including the failed requests in pull requests / other contact will help us debug what's going on.

Example:

s = Session(base_url,
            cloudfs_id,
            cloudfs_secret)
s.authenticate(username, password, debug=True)
Request:
POST: https://xxxxxxxx.cloudfs.io/v2/oauth2/token
Date : Sat, 25 Oct 2014 03:10:15 GMT
Content-Length : 60
Content-Type : application/x-www-form-urlencoded; charset="utf-8"
Authorization : BCS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Body:
	username=<username>
	password=<password>
	grant_type=password

Response:
HTTP Code: 200
content-length : 308
set-cookie : tkey_auth_api_stage_sessionid=US2.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY; Domain=.cloudfs.io; Max-Age=2592000; Path=/; expires=Mon, 24-Nov-2014 03:10:13 GMT, tkey_auth_api_stage_csrf=7fb02c4c212d4c2b8139b1328d313963; Domain=.cloudfs.io; Max-Age=2592000; Path=/; expires=Mon, 24-Nov-2014 03:10:13 GMT
server : Apache
date : Sat, 25 Oct 2014 03:10:13 GMT
x-bcp : s:api06-v2-us2, be:api, fe:https
content-type : application/json; charset=UTF-8
Body:
{u'access_token': u'US2.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY',
 u'token_type': u'bearer',
 u'transmission_key': u'<160 character transmission key>'}

Tests

The tests that exist are functional tests designed to be used with a CloudFS test user and are the tests used to develop the API. They will use API requests on your free CloudFS account, but if you run out of requests just create a new account.

These tests also act as a guide for intended functionality. Some test lines are commented out to reflect the current state of the SDK or REST interface.

Setup

The test_settings.py file in the test directory contains all the constants needed for the API.

  • CLOUDFS_ID = Application Client ID.
  • CLOUDFS_SECRET = Application Secret.
  • CLOUDFS_BASE = Application API Server.
  • TEST_USER_EMAIL = email for a test user.
  • TEST_USER_PASSWORD = password for a test user.
  • SECOND_TEST_USER_EMAIL = email for a second user - used to receieve shares.
  • SECOND_TEST_USER_PASSWORD = password for the second user.

A (non-test) user account created through the API should work just as well.

Feedback

We would love to hear what features or functionality you're interested in, or general comments on the SDK (good and bad - especially bad).

About

Use CloudFS to quickly integrate cloud storage into your Python application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%