def with_init(attrs, defaults=None):
    """
    A class decorator that wraps the __init__ method of a class and sets
    *attrs* first using keyword arguments.

    :param attrs: Attributes to work with.
    :type attrs: Iterable of native strings.

    :param defaults: Default values if attributes are omitted on instantiation.
    :type defaults: `dict` or `None`
    """
    if defaults is None:
        defaults = {}

    def init(self, *args, **kw):
        for a in attrs:
            try:
                v = kw.pop(a)
            except KeyError:
                try:
                    v = defaults[a]
                except KeyError:
                    raise ValueError("Missing value for '{0}'.".format(a))
            setattr(self, a, v)
        self.__original_init__(*args, **kw)

    def wrap(cl):
        cl.__original_init__ = cl.__init__
        cl.__init__ = init
        return cl

    return wrap