Coder Social home page Coder Social logo

python-contextio's Introduction

Context.IO API v2.0 Python Library

This is the python client library for v2.0 of the Context.IO API!

Supports Python 2.7 (2.7.9 and up) and 3.

##Dependencies RAUTH - If you do not have that, snag it with $ pip install rauth or $ easy_install rauth , or “Use the Source, Luke”

REQUESTS - rauth is built on top of the requests module $ pip install requests or $ easy_install requests or Source

SIX - six is a python compatability library for having python2 and python3 in a common codebase $ pip install six or $ easy_install six or Source

##Installation Check out / download the module from git, change directory to the folder with setup.py and run:

python setup.py install

You'll probably want to toss a sudo before that, depending on your OS. That's it though!

You can also use pip to install the latest release:

pip install contextio

##Usage You first need to instantiate the main ContextIO object with your API credentials:

import contextio as c

CONSUMER_KEY = 'YOUR_API_KEY'
CONSUMER_SECRET = 'YOUR_API_SECRET'

context_io = c.ContextIO(
	consumer_key=CONSUMER_KEY,
	consumer_secret=CONSUMER_SECRET
)

The ContextIO class can optionally accept a debug keyword parameter that prints or logs more info about the request and response.

The module is fully docstringed out, so feel free to jump into the python interpreter and help(foo) on stuff. Explore the resource classes and methods!

Here's how you can query the API for an account:

accounts = context_io.get_accounts(email='[email protected]')
# since we return a list, let's be sure we have a result
if accounts:
    account = accounts[0]

The Account class has methods to represent all the kinds of requests you can make under that resource.

If you store account ids, message ids, file ids, or anything else like that on your server, you can instantiate these objects without touching the API, for increased speed. Here's an example of how you do that.

params = {
	'id': 'ACCOUNT_ID_HERE'
}
account = c.Account(context_io, params)

That'll just be an empty object, but you need to pass in the "id" since that's used to form the URL for API endpoints for the account resource. If you want to query the API and populate that account object, you can simply do a:

account.get()

You can use this same technique to populate sub-resource objects too.

params = {
	'message_id': 'MESSAGE_ID_HERE'
}
message = c.Message(account, params)
# populate the message object with data from the API
message.get()

Notice how the Message class needs an Account object as a parent? That's because the library uses an object's ancestors to build the URL.

If you have any questions, don't hesitate to contact [email protected]

python-contextio's People

Contributors

sushithegreat avatar michaelbernstein avatar mo-mughrabi avatar mou55 avatar rbpasker avatar cecyc avatar tonyblank avatar elmkarami avatar jathanism avatar pikeas avatar privatecaptain avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.