Skip to main content

Python - API Sample Code

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

import requests

server = "https://vocabulary.semantic-web.at"
projectID = "cocktails"
user = "api_test_user"
password = "*************"

api_url = f"{server}/PoolParty/api/thesaurus/{projectID}/concept"

# Parameters for PP api GET requests will be encoded in the URL
get_parameters = {
    'concept': 'http://vocabulary.semantic-web.at/cocktails/bca7bc6d-6709-48b8-ae52-fe194c212398',
    'properties': 'skos:altLabel, skos:definition'
}

response = requests.get(api_url, params=get_parameters, auth=(user, password))
if response.status_code == 200:
    print(response.json())
else:
    print(f"Request failed with status code {response.status_code} and content:\n", response.text)
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