Python - API Sample Code

This section contains examples of Pyhon code to be used with the PoolParty API.

import urllib, urllib2, base64
 
# https://docs.python.org/2.7/howto/urllib2.html
 
# formulate request parameters
data = {'concept': 'http://vocabulary.semantic-web.at/cocktails/bca7bc6d-6709-48b8-ae52-fe194c212398',
        'properties': 'skos:altLabel, skos:definition'}
url_values = urllib.urlencode(data)
# construct URL based on basic URL, project UUID and target service
url = 'http://vocabulary.semantic-web.at/PoolParty/api/thesaurus/1DCE0ED2-D7E8-0001-86A1-18652DF0D7A0/concept'
full_url = url + '?' + url_values
# fire request
request = urllib2.Request(full_url)
request.add_header('Authorization', b'Basic ' + base64.b64encode("username" + b':' + "password"))
# process response
response = urllib2.urlopen(request)
response_json = response.read()
 
print(response_json)
Output
{
  "uri" : "http://vocabulary.semantic-web.at/cocktails/bca7bc6d-6709-48b8-ae52-fe194c212398",
  "prefLabel" : "Caipirinha",
  "altLabels" : [ "Capirina", "Capirinha", "Caipi" ],
  "definitions" : [ "Caipirinha is Brazil's national cocktail, made with cachaça (sugar cane hard liquor), sugar and lime. Cachaça is Brazil's most common distilled alcoholic beverage (also known as Pinga or Caninha). Both rum and cachaça are made from sugarcane-derived products. Specifically with cachaça, the alcohol results from the fermentation of sugarcane juice that is afterwards distilled." ]
}
Process finished with exit code 0