import inspect


def get_public_fields(obj):
    """Returns only public fields from object or class."""

    public_attributes = [attr for attr in dir(obj)
                         if not attr.startswith("_")]

    public_fields = {}

    for attribute_str in public_attributes:
        attr = getattr(obj, attribute_str)
        is_field = not (inspect.isbuiltin(attr)
                        or inspect.isfunction(attr)
                        or inspect.ismethod(attr))

        if is_field:
            public_fields[attribute_str] = attr

    return public_fields