Package: poplus-pci
_____               _
|  __ \             | |
| |__) |___   _ __  | | _   _  ___
|  ___// _ \ | '_ \ | || | | |/ __|
| |   | (_) || |_) || || |_| |\__ \
|_|    \___/ | .__/ |_| \__,_||___/
  _____      | |                                            _
 / ____|     |_|                                           | |
| |      ___   _ __ ___   _ __    ___   _ __    ___  _ __  | |_
| |     / _ \ | '_ ` _ \ | '_ \  / _ \ | '_ \  / _ \| '_ \ | __|
| |____| (_) || | | | | || |_) || (_) || | | ||  __/| | | || |_
 \_____|\___/ |_| |_| |_|| .__/  \___/ |_| |_| \___||_| |_| \__|
 _____         _         | |                _    _
|_   _|       | |        |_|               | |  (_)
  | |   _ __  | |_  ___   __ _  _ __  __ _ | |_  _   ___   _ __
  | |  | '_ \ | __|/ _ \ / _` || '__|/ _` || __|| | / _ \ | '_ \
 _| |_ | | | || |_|  __/| (_| || |  | (_| || |_ | || (_) || | | |
|_____||_| |_| \__|\___| \__, ||_|   \__,_| \__||_| \___/ |_| |_|
                          __/ |
                         |___/Generic Python bindings to connect to thePoplus componentsAPIs.Actually, this is only a convenient wrapper aroundTortillageneric
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.Installationpoplus-pci is available as a module on PyPi, to install, simply run:pip install poplus-pciAlternatively, you can clone this repo and install as you see fit.Quick startFirst, let’s try read-only access to thelegisladores-arinstance of Popit at mySociety,
and get the paged list of political organizations in the argentinian parliament:frompciimportPopitpopit=Popit(instance='legisladores-ar',host='popit.mysociety.org',)instanceName of the instance you want to point to.
There can be more than one for one installation.hostThe 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 organizationsprint(os.total)# but only 30 have been grabbedprint(o.page)fori,oinenumerate(os.result,start=1):print("{0}:{1}".format(i,o.name))# how to get next page?printos.next_url# get itos=popit.organizations.get(params={'page':2})Write access (Popit)Make sure you have all the information you need. Then get the object use thePopItconstructor.frompciimportPopitpopit=Popit(instance='openpolistest',host='popit.mysociety.org',api_key='-YOUR-API-KEY-',)api_keyThis is the API key you can request by clicking
‘Get API key’ in the PopIt web interface for your instance, asdescribed in the documentation.Then the basic CRUD operations will be:# createeinstein=popit.persons.post(data={'name':'Albert Einstein','links':[{'url':'http://www.wikipedia.com/AlbertEinstein','note':'Wikipedia'}]})# readpopit.persons(einstein.result.id).get()# update (note: is PUT, not PATCH)popit.persons(einstein.result.id).put(data={"name":"Albert Einstein"})# deletepopit.persons(einstein.result.id).delete()If you’re still using an older PopIt instance and have not upgraded
your account for the new, more secure authentication system, instead
ofapi_keyyou can supplyuserandpassword:popit=Popit(instance='openpolistest',host='popit.mysociety.org',user='-USERNAME-',password='-PASSWORD-')userYour username, the email address that you created the instance withpasswordThe password you were emailed when creating the instancePopit Search apiAlmost all APIs can be wrapped around the pci component, easily.Starting from a popit instance, queries through the search API can be done:popit.search.organizations.get(params={'q':'trabajo'})popit.search.organizations.get(params={'q':'trabajadores'})Mapit accessMapit has read-only access, and the API does not adhere to REST standards.The default Mapit instance is MySociety’s Global Mapit:http://global.mapit.mysociety.org/.The mapit API call/point/SRID/LON,LAT/[box], can be invoked directly,
by tortilla wrapping utilities, or by using Mapit helpers.mapit=Mapit()self.m.point.get('4326/12.5042,41.8981')self.m.areas_overpoint(lat='41.8981',lon='12.5042',srid='4326',box=True)Other helpers are available, and will be implemented as needed in the futures.
You can find them in thepci/__init__.pyfile.CachingTo limit the amount of requests to an API endpoint, a caching mechanism is available.
You can activate this with thecache_lifetimeparameter, when creating a pci instance:mapit=Mapit(cache_lifetime=60,)Single requests, though, can be performed ignoring the cache alltogether:mapit.point.get('4326/12.5042,41.8981',ignore_cache=True)RequirementsIf you don’t use pip to install the module, you’ll also need:tortilla (pip install tortilla)How to run the testsCopy the fileconfig_sample.pytoconfig_test.pyChange the entries inconfig_test.pyto refer to your test serversInstalloktest(pip install oktest)Make sure components instances are running, and you have access to them.
You cannot test this wrapper without running instances.runpython test.pyto run all tests,python test_mapit.py, orpython test_popit.pyto run the specified
component’s testsChangelog=== 0.1 (2015-02-20) ===
initial releaseCreditstortillapopit-pythonslumber