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
GUI Pancakeswap2 and Uniswap3 trading client (and bot)

GUI Pancakeswap2 and Uniswap3 trading client (and bot) (MOST ADVANCE TRADING BOT SUPPORT WINDOWS LINUX MAC) (AUTO BUY TOKEN ON LUNCH AFTER ADD LIQUIDI

16 Dec 23, 2021
An Open Source ALL-In-One Telegram RoBot, that can do lot of things.

URL Uploader Bot An Open Source ALL-In-One Telegram RoBot, that can do lot of things. My Features Installation The Easy Way You can also tap the Deplo

NT BOTS 1 Oct 23, 2021
Auxiliator is telegram bot for basic web-application analysis

Auxiliator Auxiliator is telegram bot for basic web-application analysis What for? Sometimes there is no access to your main PC, where you can scan we

Revoltage 13 Dec 26, 2021
Home Assistant for Opendata CWB. Get the weather forecast of the city in Taiwan.

Home assistant support for Opendata CWB. The readme in Traditional Chinese. This integration is based on OpenWeatherMap (@csparpa, pyowm) to develop.

11 Sep 30, 2022
BSDotPy, A module to get a bombsquad player's account data.

BSDotPy BSDotPy, A module to get a bombsquad player's account data from bombsquad's servers. Badges Provided By: shields.io Acknowledgements Issues Pu

Rudransh Joshi 3 Feb 17, 2022
I-Spy is a discord and twitter bot πŸ€– that keeps a check on usage foul language, hate-speech and NSFW contents

I-Spy is a discord and twitter bot πŸ€– that keeps a check on usage foul language, hate-speech and NSFW contents. It is the one stop solution to monitor your discord servers and twitter handles against

Tia Saxena 5 Nov 16, 2022
Modern, privacy-friendly, and detailed web analytics that works without cookies or JS.

Modern, privacy-friendly, and cookie-free web analytics. Getting started Β» Screenshots β€’ Features β€’ Office Hours Motivation There are a lot of web ana

R. Miles McCain 2.1k Jan 03, 2023
Dodo - A graphical, hackable email client based on notmuch

Dodo Dodo is a graphical email client written in Python/PyQt5, based on the comm

Aleks Kissinger 44 Nov 12, 2022
It's a simple python script to take backup of directories (compressing) then the same to move your mentioned S3 bucket with the help of AWS IAM User.

Directory Backup Moved to S3 (Pyscript) Description Here it's a python script that needs to use this script simply create a directory backup and moved

Yousaf K Hamza 3 Mar 04, 2022
A Telegram bot that searches for the original source of anime, manga, and art

A Telegram bot that searches for the original source of anime, manga, and art How to use the bot Just send a screenshot of the anime, manga or art or

Kira Kormak 9 Dec 28, 2022
Bot that embeds a random hysterical meme from Reddit into your text channel as an embedded message, using an API call.

Discord_Meme_Bot 🀣 Bot that embeds a random hysterical meme from Reddit into your text channel as an embedded message, using an API call. Add the bot

2 Jan 16, 2022
Framework to make using Bottle less time-consuming and easier

A class for the Bottle API to reduce clutter and difficulty while creating a website.

Tygzy 0 Dec 26, 2022
Tsar-Bot - Crypto auto trade bot that use sentiment analysis from twitter

Tsar Bot - Crypto Sentiment Bot Tsar Bot is a Twitter Crypto Sentiment Bot that

Hilmi Azizi 26 Dec 15, 2022
A Python script to update Spotify Playlist data every 5 minutes.

Spotify Playlist Updater A Python script to update Spotify Playlist data every 5 minutes. Description An automatic playlist updater using Spotify API

6 Nov 24, 2022
Cytotron - A unique discord bot like never before. Add it to your server to keep it active, motiviated, and amazing!!

Cytotron - Take your server to the next level Most of the details are in the website. Go to https://cytotron-bot.gq for more information. If that link

LeviathanProgramming 6 Jun 13, 2021
Apple iTunes In-app purchase verification tool

itunes-iap v2 Python 2 & 3 compatible! Even with :mod:`asyncio` support! Source code: https://github.com/youknowone/itunes-iap Documentation: http://i

Jeong YunWon 129 Dec 10, 2022
A python package for fetching informations from GitHub API

Py-GitHub A python package for fetching informations from GitHub API Made with Python3 (C) @FayasNoushad Copyright permission under MIT License Licens

Fayas Noushad 6 Nov 28, 2021
A Discord bot to combat phishing links for Steam trades and Discord gifts.

delink-bot A Discord bot to combat phishing links for Steam trades and Discord gifts. Requirement python3 -m pip install -U discord.py python3 -m pip

hugonun 15 Dec 09, 2022
A fast and expressive Craigslist API wrapper

pycraigslist A fast and expressive Craigslist API wrapper. ⚠ As of September 2021, it is believed that Craigslist added a rate-limiter. It is advised

Ira Horecka 24 Dec 28, 2022
β€œHey there πŸ‘‹ I'm szrosebot .A Powerful, Smart And Simple Group Manager with some extra features..

A Powerful, Smart And Simple Group Manager szrose bot This is the clone of DewmiBotit is a Powerful, Smart And Simple Group Manager bot made by hiruna

slgeekshow 36 Oct 30, 2022