code: def csv_from_items(items, stream=None):
          
          items = iter(items)
          first = next(items)
          cls = first.__class__
          if stream is None:
              stream = sys.stdout
          fields = [f.name for f in attr.fields(cls)]
          writer = csv.DictWriter(stream, fieldnames=fields)
          writer.writeheader()
          writer.writerow(attr.asdict(first))
          writer.writerows((attr.asdict(x) for x in items))
docs: Write a list of items to stream in CSV format.
  
          The items need to be attrs-decorated.