def get_message(msg):
    'Get metric instance from dictionary or string'
    if (not isinstance(msg, dict)):
        try:
            msg = json.loads(msg, encoding='utf-8')
        except json.JSONDecodeError:
            return None
    typ = msg.pop('__type')
    if (typ == 'metric'):
        return Metric(**msg)
    return None
Get metric instance from dictionary or string
def get_message(msg):
    
    if (not isinstance(msg, dict)):
        try:
            msg = json.loads(msg, encoding='utf-8')
        except json.JSONDecodeError:
            return None
    typ = msg.pop('__type')
    if (typ == 'metric'):
        return Metric(**msg)
    return None