def bytes_str(num):
    """
    Converts bytes to a human readable format. For example: ::

        print_bytes(12345) returns '12.06 KB'
        print_bytes(123456789) returns '117.74 MB'

    Parameters
    ----------
    num : `int`
        The size in bytes.

    Raises
    ------
    ValueError
        num must be int >= 0
    """
    if not isinstance(num, int) or num < 0:
        raise ValueError('num must be int >= 0')
    for x in ['bytes', 'KB', 'MB', 'GB']:
        if num < 1024.0:
            return '{0:3.2f} {1:s}'.format(num, x)
        num /= 1024.0
    return '{0:3.2f} {1:s}'.format(num, 'TB')
