<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_class_by_path(class_path: str, is_module: Optional[bool] = False) -> type: """ Get class by its name within a package structure. :param class_path: E.g. brandt.some.module.ClassName :param is_module: Whether last item is module rather than class name :return: Class ready to be instantiated. """


    if is_module:
        try:
            backend_module = importlib.import_module(class_path)
        except ImportError:
            logger.warning("Can't import backend with name `%s`", class_path)
            raise
        else:
            return backend_module

    module_name, class_name = class_path.rsplit('.', 1)

    try:
        backend_module = importlib.import_module(module_name)
    except ImportError:
        logger.error("Can't import backend with name `%s`", module_name)
        raise

    try:
        backend_class = getattr(backend_module, class_name)
    except AttributeError:
        logger.error("Can't get backend class `%s` from `%s`", class_name, module_name)
        raise

    return backend_class