OpenAustralia API Python module docs

class openaustralia.api.OpenAustralia(api_key, api_url='http://www.openaustralia.org/api')

Client for OpenAustralia API.

Provides an implementation for the REST api given at:
http://www.openaustralia.org.au/api
Parameters:
  • api_key (string) – API Access key (http://www.openaustralia.org.au/api/key)
  • api_url (string) – API url endpoint. Defaults to API_BASE_URL, but can be switched out (eg. point at your own instance for testing).
get_comments(date=None, search=None, user_id=None, pid=None, page=None, num=None)

Fetch comments left on OpenAustralia.

With no arguments, returns most recent comments in reverse date order.

Arguments:

Parameters:
  • date – (optional) Fetch the comments for this date.
  • search – (optional) Fetch the comments that contain this term.
  • user_id – (optional) Fetch the comments by a particular user ID.
  • pid – (optional) Fetch the comments made on a particular person ID (Representative/Senator).
  • page – (optional) Page of results to return.
  • num – (optional) Number of results to return.
get_debates(debate_type, date=None, search=None, person_id=None, gid=None, year=None, order=None, page=None, num=None)

Fetch Debates.

This includes Oral Questions.

Arguments:

Parameters:debate_type – (required) One of “representatives” or “senate”.

Note you can only supply one of the following search terms at present.

Parameters:
  • date – Fetch the debates for this date.
  • search – Fetch the debates that contain this term.
  • person_id – Fetch the debates by a particular person ID.
  • gid – Fetch the speech or debate that matches this GID.
  • year – (Undocumented. Seems to return dates of debates, for matching year.)

Result filtering:

Parameters:
  • order – (optional, when using search or person) d for date ordering, r for relevance ordering.
  • page – (optional, when using search or person) Page of results to return.
  • num – (optional, when using search or person) Number of results to return.
get_divisions(postcode=None, date=None, search=None)

Fetch a list of electoral divisions.

Arguments:

Parameters:
  • postcode – (optional) Fetch the list of electoral divisions that are within the given postcode (there can be more than one)
  • date – (optional) Fetch the list of electoral divisions as it was on this date.
  • search – (optional) Fetch the list of electoral divisions that match this search string
get_hansard(search=None, person_id=None, order=None, page=None, num=None)

Fetch all Hansard.

Arguments:

Note you can only supply one of the following at present.

Parameters:
  • search – Fetch the data that contain this term.
  • person_id – Fetch the data by a particular person ID.

Result filtering:

Parameters:
  • order – (optional, when using search or person, defaults to date) d for date ordering, r for relevance ordering, p for use by person.
  • page – (optional, when using search or person) Page of results to return.
  • num – (optional, when using search or person) Number of results to return.
get_representative(person_id=None, division=None, always_return=None)

Fetch a particular member of the House of Representatives.

Arguments:

Parameters:
  • person_id – (optional) If you know the person ID for the member you want (returned from getRepresentatives or elsewhere), this will return data for that person.
  • division – (optional) The name of an electoral division; we will try and work it out from whatever you give us. :)
  • always_return – (optional) For the division option, sets whether to always try and return a Representative, even if the seat is currently vacant.
get_representatives(postcode=None, data=None, party=None, search=None)

Fetch a list of members of the House of Representatives.

Arguments:

Parameters:
  • postcode – (optional) Fetch the list of Representatives whose electoral division lies within the postcode (there may be more than one)
  • date – (optional) Fetch the list of members of the House of Representatives as it was on this date.
  • party – (optional) Fetch the list of Representatives from the given party.
  • search – (optional) Fetch the list of Representatives that match this search string in their name.
get_senator(person_id)

Fetch a particular Senator.

Arguments:

Parameters:person_id – (required) If you know the person ID for the Senator you want, this will return data for that person.
get_senators(date=None, party=None, state=None, search=None)

Fetch a list of Senators.

Arguments:

Parameters:
  • date – (optional) Fetch the list of Senators as it was on this date.__version__
  • party – (optional) Fetch the list of Senators from the given party.
  • state – (optional) Fetch the list of Senators from the given state. (NSW, Tasmania, WA, Queensland, Victoria, SA, NT, ACT)
  • search – (optional) Fetch the list of Senators that match this search string in their name.
class openaustralia.api_types.ApiCall(api_url, api_key, function, output='js', immediate=True, **kwargs)

Represents on API request & its associated response.

Constructor:

Parameters:
  • api_url (string) – API url endpoint.
  • api_key (string) – API Access Key
  • function (string) – API function name to call.
  • output (string) – Expected response format. Can be one of: * js (ie. json) default, * xml, * php (serialised php array), * rabx
  • immediate (boolean) – If True, will execute request at time of construction. Otherwise, send_request will need to be called as needed.

Remaining kwargs will be passed along as request query parameters.

send_request()

Executes this API request.

If the HTTP response is 200 OK, the response contents will be stored in this instance’s result property.

JSON responses will be automatically decoded.

If the HTTP response was not ok, an exception will be raised.