I have a simple SDK in Python for internal use. It's basically 150~200 lines of code of simple API calls wrapped around nicely that is comfortable for us to use.
It holds a few clients with methods (and each method wraps some API calls).
So a proper usage would be:
from datatube.datatube import Datatube
client = Datatube()
client.do_stuff(...)
Currently it expects 3 environment variables - two for authentication purposes (these are the secret ones) and one for the environment (dev/stg/prod). I want to change the environment variable to be passed on as an argument (seems better). So:
from datatube.datatube import Datatube
client = Datatube('stg')
client.do_stuff(...)
Inside Datatube
I'll take the correct config based on the environment.
Currently I have:
class BaseConfig:
pass
class DevelopmentConfig(BaseConfig):
DATATUBE_URL = 'https://..'
class StagingConfig(BaseConfig):
DATATUBE_URL = 'https://..'
class ProductionConfig(BaseConfig):
DATATUBE_URL = 'https://..'
def get_config(env: str):
env = env.lower()
if env == 'dev':
return DevelopmentConfig()
if env == 'stg':
return StagingConfig()
elif env == 'prod':
return ProductionConfig()
else:
raise KeyError(f"unsupported env: {env}. supported environments: dev/stg/prod")
If I'll use type annotation on get_config
like:
def get_config(env: str) -> BaseConfig
Then the IDE won't like it (I guess because BaseConfig
is empty, but I don't know how to do it nicely - isn't an abstract class kind of an overkill?)
Any recommendations would be helpful.
Using Python 3.9