def add_fields(iterable, **kw_fields):
    """
    Add fields to each item in ``iterable``. Each key=value pair provided is
    merged into the ``@fields`` object, which will be created if required.

    >>> data_in = [{'@message': 'one message'}, {'@message': 'another message'}]
    >>> data_out = add_fields(data_in, foo='bar', baz='qux')
    >>> [x for x in data_out]
    [{'@fields': {'foo': 'bar', 'baz': 'qux'}, '@message': 'one message'},
     {'@fields': {'foo': 'bar', 'baz': 'qux'}, '@message': 'another message'}]
    """
    k = '@fields'
    for item in iterable:
        if k not in item:
            item[k] = {}
        item[k].update(kw_fields)
        yield item
