diff --git a/sanic/config.py b/sanic/config.py index 0a53a607..d3b03f4f 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -1,6 +1,8 @@ import os import types +import import_string + from sanic.exceptions import PyFileError @@ -111,6 +113,8 @@ class Config(dict): :param obj: an object holding the configuration """ + if isinstance(obj, str): + obj = import_string(obj) for key in dir(obj): if key.isupper(): self[key] = getattr(obj, key) diff --git a/setup.py b/setup.py index 37164336..87de21fb 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ Sanic import codecs import os import re -from distutils.errors import DistutilsPlatformError + from distutils.util import strtobool from setuptools import setup @@ -63,6 +63,7 @@ requirements = [ 'aiofiles>=0.3.0', 'websockets>=6.0,<7.0', 'multidict>=4.0,<5.0', + 'import-string>=0.1.0' ] if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): print("Installing without uJSON")