sofarocean / sofar-api-client-python

Python Client for Wavefleet
Apache License 2.0
7 stars 5 forks source link

Using multiple API keys for Spotter class #7

Closed benjwadams closed 3 years ago

benjwadams commented 4 years ago

If it is desired to use mutliple API keys with the Spotter class, only the first assigned API key from the environment variable WF_API_TOKEN get used at import time. Thus, if a user wants to use a different spotter with a different API key, they will have to do something like:

import os
import importlib
import pysofar
import pysofar.spotter
# this is a hack, requires setting an environment variable
# and reloading modules any time the API key potentially changed
os.environ["WF_API_TOKEN"] = api_key
importlib.reload(pysofar)
importlib.reload(pysofar.spotter)
spotter = pysofar.spotter.Spotter(spotter_id, "")

It would be preferable to be able to do this by having a usable argument from the Spotter constructor or similar.

mattp0 commented 4 years ago

I had the same issues, I am working on showcasing some work using jupyter notebooks and outside of a hacky approach it would be nice to set your own custom_token. I found that there is a constructor param that checks if the flag exists. After looking into this code, I believe that the issue lies within the __init__ as it does not properly handle the custom_token flag that can be passed on the API creation. The custom_token is not documented in the docs. I have opened an issue and submitted a PR for a suggested fix.

mike-sosa-sofarocean commented 3 years ago

Hey there. Sorry for the delay. We've been a bit busy with a few different projects but I'll try to get the fix for this merged in ASAP

mike-sosa-sofarocean commented 3 years ago

New version out on Pypi (0.1.9). Thanks again for the PR!