def import_obj(obj_path, hard=False):
    """
    import_obj imports an object by uri, example::

        >>> import_obj("module:main")
        <function main at x>

    :param obj_path: a string represents the object uri.
    ;param hard: a boolean value indicates whether to raise an exception on
                import failures.
    """
    try:
        # ``__import__`` of Python 2.x could not resolve unicode, so we need
        # to ensure the type of ``module`` and ``obj`` is native str.
        module, obj = str(obj_path).rsplit(':', 1)
        m = __import__(module, globals(), locals(), [obj], 0)
        return getattr(m, obj)
    except (ValueError, AttributeError, ImportError):
        if hard:
            raise