def select_nearest_point(target, points, threshold):
    """Select data point nearest to a given point in time.

    :param datetime.datetime target: the target timestamp for the point.
    :param points: an iterator of :class:`Point`s to search.
    :param float threshold: the maximum number of seconds the selected
        point can be away from the target timestamp.

    :raises ValueError: if the selected data point exceeds the threshold.

    :returns: the :class:`Point` nearest to ``target``.
    """
    sorted_points = sorted(points, key=lambda p: abs(target - p.timestamp))
    if not sorted_points:
        raise ValueError('No points given')
    if abs(target - sorted_points[0].timestamp).total_seconds() > threshold:
        raise ValueError('No metric point within {} seconds'.format(threshold))
    return sorted_points[0]
