Generic python bindings to connect to the Poplus components APIs.
Project description
_____ _ | __ \ | | | |__) |___ _ __ | | _ _ ___ | ___// _ \ | '_ \ | || | | |/ __| | | | (_) || |_) || || |_| |\__ \ |_| \___/ | .__/ |_| \__,_||___/ _____ | | _ / ____| |_| | | | | ___ _ __ ___ _ __ ___ _ __ ___ _ __ | |_ | | / _ \ | '_ ` _ \ | '_ \ / _ \ | '_ \ / _ \| '_ \ | __| | |____| (_) || | | | | || |_) || (_) || | | || __/| | | || |_ \_____|\___/ |_| |_| |_|| .__/ \___/ |_| |_| \___||_| |_| \__| _____ _ | | _ _ |_ _| | | |_| | | (_) | | _ __ | |_ ___ __ _ _ __ __ _ | |_ _ ___ _ __ | | | '_ \ | __|/ _ \ / _` || '__|/ _` || __|| | / _ \ | '_ \ _| |_ | | | || |_| __/| (_| || | | (_| || |_ | || (_) || | | | |_____||_| |_| \__|\___| \__, ||_| \__,_| \__||_| \___/ |_| |_| __/ | |___/
Generic Python bindings to connect to the Poplus components APIs.
Actually, this is only a convenient wrapper around Tortilla generic API wrapper, with some specialized instructions to use Poplus components apis.
The main advantage of Tortilla over other wrappers is that it allows access through a full object oriented interface, both when requesting data, and when parsing the results.
Results are transformed from JSON into a Python dictionary, and then bunchified.
Installation
poplus-pci is available as a module on PyPi, to install, simply run:
pip install poplus-pci
Alternatively, you can clone this repo and install as you see fit.
Quick start
First, let’s try read-only access to the legisladores-ar instance of Popit at mySociety, and get the paged list of political organizations in the argentinian parliament:
from pci import Popit
popit = Popit(
instance='legisladores-ar',
host='popit.mysociety.org',
)
- instance Name of the instance you want to point to.
There can be more than one for one installation.
host The hostname of the PopIt server.
Once an instancehas been created, it’s easy enough to access data, using a full object oriented interface:
os = popit.organizations.get()
# there are 65 organizations
print(os.total)
# but only 30 have been grabbed
print(o.page)
for i, o in enumerate(os.result, start=1):
print("{0}: {1}".format(i, o.name))
# how to get next page?
print os.next_url
# get it
os = popit.organizations.get(params={'page': 2})
Changelog
=== 0.1 (2015-02-20) ===
initial release
Credits
tortilla: http://github.com/redodo/tortilla
popit-python http://github.com/mysociety/popit-python