SmartFile API Client (Python).

Overview

SmartFile

A SmartFile Open Source project. Read more about how SmartFile uses and contributes to Open Source software.

Travis CI Status Code Coverage Latest PyPI version

Summary

This library includes two API clients. Each one represents one of the supported authentication methods. BasicClient is used for HTTP Basic authentication, using an API key and password. OAuthClient is used for OAuth (version 1) authentication, using tokens, which will require user interaction to complete authentication with the API.

Both clients provide a thin wrapper around an HTTP library, taking care of some of the mundane details for you. The intended use of this library is to refer to the API documentation to discover the API endpoint you wish to call, then use the client library to invoke this call.

SmartFile API information is available at the SmartFile developer site.

Installation

You can install via pip.

$ pip install smartfile

Or via source code / GitHub.

$ git clone https://github.com/smartfile/client-python.git smartfile
$ cd smartfile
$ python setup.py install

More information is available at GitHub and PyPI.

Usage

Choose between Basic and OAuth authentication methods, then continue to use the SmartFile API.

Some of the details this library takes care of are:

  • Encoding and decoding of parameters and return values. You deal with Python types only.
  • URLs, using the API version, endpoint, and object ID, the URL is created for you.
  • Authentication. Provide your API credentials to this library, it will take care of the details.

Basic Authentication

Three methods are supported for providing API credentials using basic authentication.

  1. Parameters when instantiating the client.

    >>> from smartfile import BasicClient
    >>> api = BasicClient('**********', '**********')
    >>> api.get('/ping')
  2. Environment variables.

    Export your credentials via your environment.

    $ export SMARTFILE_API_KEY=**********
    $ export SMARTFILE_API_PASSWORD=**********
    

    And then you can use the client without providing any credentials in your code.

    >>> from smartfile import BasicClient
    >>> # Credentials are read automatically from environment
    >>> api = BasicClient()
    >>> api.get('/ping')
  3. netrc file (not supported with OAuth).

    You can place the following into ~/.netrc:

    machine app.smartfile.com
      login **********
      password **********
    

    And then you can use the client without providing any credentials in your code.

    >>> from smartfile import BasicClient
    >>> # Credentials are read automatically from netrc
    >>> api = BasicClient()
    >>> api.get('/ping')

    You can override the default netrc file location, using the optional netrcfile kwarg.

    >>> from smartfile import BasicClient
    >>> # Credentials are read automatically from netrc
    >>> api = BasicClient(netrcfile='/etc/smartfile.keys')
    >>> api.get('/ping')

OAuth Authentication

Authentication using OAuth authentication is bit more complicated, as it involves tokens and secrets.

>>> from smartfile import OAuthClient
>>> api = OAuthClient('**********', '**********')
>>> # Be sure to only call each method once for each OAuth login
>>>
>>> # This is the first step with the client, which should be left alone
>>> api.get_request_token()
>>> # Redirect users to the following URL:
>>> print "In your browser, go to: " + api.get_authorization_url()
>>> # This example uses raw_input to get the verification from the console:
>>> client_verification = raw_input("What was the verification? :")
>>> api.get_access_token(None, client_verification)
>>> api.get('/ping')

Calling endpoints

Once you instantiate a client, you can use the get/put/post/delete methods to make the corresponding HTTP requests to the API. There is also a shortcut for using the GET method, which is to simply invoke the client.

>>> from smartfile import BasicClient
>>> api = BasicClient('**********', '**********')
>>> api.get('/ping')
>>> # The following is equivalent...
>>> api('/ping')

Some endpoints accept an ID, this might be a numeric value, a path, or name, depending on the object type. For example, a user's id is their unique username. For a file path, the id is it's full path.

>>> import pprint
>>> from smartfile import BasicClient
>>> api = BasicClient('**********', '**********')
>>> # For this endpoint, the id is '/'
>>> pprint.pprint(api.get('/path/info', '/'))
{u'acl': {u'list': True, u'read': True, u'remove': True, u'write': True},
 u'attributes': {},
 u'extension': u'',
 u'id': 7,
 u'isdir': True,
 u'isfile': False,
 u'items': 348,
 u'mime': u'application/x-directory',
 u'name': u'',
 u'owner': None,
 u'path': u'/',
 u'size': 220429838,
 u'tags': [],
 u'time': u'2013-02-23T22:49:30',
 u'url': u'http://localhost:8000/api/2/path/info/'}

File transfers

Uploading and downloading files is supported.

To upload a file:

>>> from smartfile import BasicClient
>>> api = BasicClient()
>>> file = open('test.txt', 'rb')
>>> api.upload('test.txt', file)

Downloading is automatic, if the 'Content-Type' header indicates content other than the expected JSON return value, then a file-like object is returned.

>>> from smartfile import BasicClient
>>> api = BasicClient()
>>> api.download('foobar.png')

Tasks

Operations are long-running jobs that are not executed within the time frame of an API call. For such operations, a task is created, and the API can be used to poll the status of the task.

Move files

>>> import logging
>>> from smartfile import BasicClient
>>>
>>> api = BasicClient()
>>>
>>> LOGGER = logging.getLogger(__name__)
>>> LOGGER.setLevel(logging.INFO)
>>>
>>> api.move('file.txt', '/newFolder')
>>>
>>> while True:
>>>     try:
>>>         s = api.get('/task', api['uuid'])
>>>         # Sleep to assure the user does not get rate limited
>>>         time.sleep(1)
>>>         if s['result']['status'] == 'SUCCESS':
>>>             break
>>>         elif s['result']['status'] == 'FAILURE':
>>>             LOGGER.info("Task failure: " + s['uuid'])
>>>     except Exception as e:
>>>         print e
>>>         break

Delete files

>>> from smartfile import BasicClient
>>> api = BasicClient()
>>> api.remove('foobar.png')

Running Tests

To run tests for the test.py file:

nosetests -v tests.py

To run tests for the test_smartfile.py file:

API_KEY='****' API_PASSWORD='****' nosetests test
Cdk-python-crud-app - CDK Python CRUD App

Welcome to your CDK Python project! You should explore the contents of this proj

Shapon Sheikh 1 Jan 12, 2022
YARSAW is an Async Python API Wrapper for the Random Stuff API.

Yet Another Random Stuff API Wrapper - YARSAW YARSAW is an Async Python API Wrapper for the Random Stuff API. This module makes it simpler for you to

Bruce 6 Mar 27, 2022
A modern Python client for controlling Wyze devices.

Python Wyze SDK A modern Python client for controlling Wyze devices. Whether you're building a custom app, or integrating into a third-party service l

Shaun Tarves 205 Jan 02, 2023
Send SMS text messages via email with as many accounts as you want :)

SMS-Spammer Send SMS text messages via email with as many accounts as you want :) Example Set Up Guide! To start log into the gmail account you would

Riceblades11 10 Oct 25, 2022
A stable and Fast telegram video convertor bot which can compress, convert(video into audio and other video formats), rename with permanent thumbnail and trim.

ᴠɪᴅᴇᴏ ᴄᴏɴᴠᴇʀᴛᴏʀ A stable and Fast telegram video convertor bot which can compress, convert(video into audio and other video formats), rename and trim.

Mahesh Chauhan 183 Jan 04, 2023
A Python API to retrieve and read MLB GameDay data

mlbgame mlbgame is a Python API to retrieve and read MLB GameDay data. mlbgame works with real time data, getting information as games are being playe

Zach Panzarino 493 Dec 13, 2022
Python wrapper for the Sportradar APIs ⚽️🏈

Sportradar APIs This is a Python wrapper for the sports APIs provided by Sportradar. You'll need to sign up for an API key to use the service. Sportra

John W. Miller 39 Jan 01, 2023
Gathers data and displays metrics related to climate change and resource depletion on a PowerBI report.

Apocalypse Status Dashboard Purpose Climate change and resource depletion are grave long-term dangers. The code in this repository will pull data from

Summer Is Here 1 Nov 12, 2021
Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and other financial information. This repository provides an SDK for developing applications to access the NCDS.

Nasdaq Cloud Data Service (NCDS) Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and ot

Nasdaq 8 Dec 01, 2022
Provide fine-grained push access to GitHub from a JupyterHub

github-app-user-auth Provide fine-grained push access to GitHub from a JupyterHub. Goals Allow users on a JupyterHub to grant push access to only spec

Yuvi Panda 20 Sep 13, 2022
A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create cust

Aran 1 Oct 13, 2021
PYAW allows you to call assembly from python

PYAW allows you to call assembly from python

2 Dec 13, 2021
The gPodder podcast client.

___ _ _ ____ __ _| _ \___ __| |__| |___ _ _ |__ / / _` | _/ _ \/ _` / _` / -_) '_| |_ \ \__, |_| \___/\__,_\__,_\___|_| |_

gPodder and related projects 1.1k Jan 04, 2023
A Bot that Forwards Tweets to Telegram using Airtable as a database.

Twitter Telegram Forward A Bot that Forwards Tweets to Telegram using Airtable as a Database. Features: Handles multiple twitter and telegram channels

George Bakev 3 Dec 21, 2022
A program used to create accounts in bulk, still a work in progress as of now.

Discord Account Creator This project is still a work in progress. It will be published upon its full completion. About This project is still under dev

patched 8 Sep 15, 2022
Python API Client for Twitter API v2

🐍 Python Client For Twitter API v2 🚀 Why Twitter Stream ? Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, Samp

Twitivity 31 Nov 19, 2022
Discord bot that plays cricket with the user

CricBot Table of content Commands Installation Game rules License Commands S.No Command Use 1. cric Open the home window. This command is not necessa

Raveesh Yadav 1 Nov 19, 2021
Binance Futures Client

Binance Futures Client

4 Aug 02, 2022
Python client and module for BGP Ranking

Python client and module for BGP Ranking THis project will make querying BGP Ranking easier. Installation pip install pybgpranking Usage Command line

D4 project 3 Dec 16, 2021
ServiceX DID Finder Girder

ServiceX_DID_Finder_Girder Access datasets for ServiceX from yt Hub Finding datasets This DID finder is designed to take a collection id (https://gird

1 Dec 07, 2021