Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Python implementation of Tezel's NodeJS unio.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 pyunio
Octocat-spinner-32 specs
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Changelog.md
Octocat-spinner-32 LICENSE
Octocat-spinner-32 MANIFEST
Octocat-spinner-32 README.md
Octocat-spinner-32 requirements.txt
Octocat-spinner-32 setup.py
Octocat-spinner-32 tests.py
README.md

PyUnio, API Consumption in a Snap

Build Status

PyUnio is currently in alpha and should not be considered stable.

Introducion

PyUnio is an implementation of Tolga Tezel's Node.js project unio.

It allows developers to consume REST API's in as little as three lines of code by predefining aspects of an API in a JSON file. These API definitions are called Specifications and should be placed in a directory titled specs.

Any specs should be downloaded from here or you can write your own.

Warning

PyUnio's development may not always run parallel to that of unio.

PyUnio may implement features not available in unio, or it may not implement features available in unio.

For this reason, you should read this entire page for any important changes in future versions.

Install

Either

$ git clone git://github.com/citruspi/PyUnio.git
$ cd PyUnio && python setup.py
$ pip install -r requirements.txt

or

$ pip install pyunio

Directory Structure

project/
    script.py
    specs/
        service1.json
        service2.json
        service3.json           
        etc

Usage

from pyunio import pyunio

params = {
            'oauth' : {
                        'consumer_secret'    : 'ITS A SECRET',
                        'consumer_key'       : 'ITS A SECRET',
                        'access_token'       : 'ITS A SECRET',
                        'access_token_secret': 'ITS A SECRET'                               
                      },
            'header': {
                        'api_key': 'ITS A SECRET'
                      },
            'body':   {
                        'username': 'iluv',
                        'password': 'pie'
                      }
         }

Example: Twitter - Get User Settings

The following code is an implementation of Twitter's API with PyUnio:

from pyunio import pyunio

params = {
            'oauth':  {
                        'consumer_secret'    : 'ITS A SECRET',
                        'consumer_key'       : 'ITS A SECRET',
                        'access_token'       : 'ITS A SECRET',
                        'access_token_secret': 'ITS A SECRET'
                      },
            'header': {},
            'body'  : {}
         }

pyunio.use('twitter')

try:

    result = pyunio.get('account/settings', params)

    print result.text

except Exception as e:

    raise Exception(e)

The output of result.text (with my Twitter account) is:

{
    "protected":false,
    "geo_enabled":false,
    "screen_name":"citrus",
    "language":"en",
    "time_zone":{
        "tzinfo_name":"America\/Halifax",
        "name":"Atlantic Time (Canada)",
        "utc_offset":-14400
    },
    "discoverable_by_email":false,
    "sleep_time":{
        "enabled":false,
        "start_time":null,
        "end_time":null
    },
    "use_cookie_personalization":false,
    "always_use_https":true
}

This can then be loaded and parsed via Python's JSON module:

parsed = json.loads(result.text)

API

Coming Soon.

License

Copyright © 2013 Mihir Singh <me@mihirsingh.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of 
this software and associated documentation files (the “Software”), to deal in 
the Software without restriction, including without limitation the rights to 
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
the Software, and to permit persons to whom the Software is furnished to do 
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
IN THE SOFTWARE.

Contributing

Just fork and submit a pull request ;)

Something went wrong with that request. Please try again.