ibm-cloudalchemyapi

Where do I specify the AlchemyAPI key in Bluemix?


I've added the AlchemyAPI service to my Python app on Bluemix. I can see the API key in the service credentials of the AlchemyAPI service. Where, in the app code or files should I specify this key so that I can call the service? The code runs fine and does everything except the part where I call AlchemyAPI.

I followed the Getting started tutorial here, but it just stops with "Get the key" and doesn't tell me what to do with it.

Some things that I tried but which did not work:

services:
- the_alchemy-service_name
applications:
- path: .
  env:
     ALCHEMY_KEY: the_actual_key
VCAP_SERVICES = os.getenv('VCAP_SERVICES')
key = (VCAP_SERVICES['alchemy_api'][0]['credentials']['apikey'])
from alchemyapi import AlchemyAPI    
alchemyapi = AlchemyAPI()

Solution

  • Thanks to the resources shared by both @Frederic and @German, I was able to find the answer with a bit more research. I did not use the suggested SDKs as-is because the SDKs contain everything and I am trying to create a simple demo app.

    Short answer

    Do not call the AlchemyAPI module. Call the Watson Developer Cloud module instead.

    Long answer

    For a Python app on Bluemix, the dependencies must be listed in a requirements.txt file. Bluemix will automatically pip install these modules, without you having to do anything.

    Because I was using the AlchemyAPI service (and went by their Getting Started guide), I listed AlchemyAPI as a dependency in requirements.txt. I assumed Bluemix would pip install it. In my Python code, I called that module by from alchemyapi import AlchemyAPI.

    Wrong assumption. alchemyapi cannot be pip installed via Bluemix. The module to call is watson-developer-cloud.

    Once that's called, you can specify the api key so:

    from watson_developer_cloud import AlchemyLanguageV1
    alchemy_language = AlchemyLanguageV1(api_key='THE_API_KEY')

    So, here is the answer to the question: you use the api_key variable to hold the value of the key, and you call the watson-developer-cloud module, NOT the alchemyapi module. You can extract the API key programmatically from the service credentials when you bind the Alchemy service to the app.