colander_data_converter.exporters.csv

class colander_data_converter.exporters.csv.CsvExporter(feed, entity_type)[source]

Bases: BaseExporter

A class to export entities from a ColanderFeed to CSV format.

This exporter filters entities by type and exports their fields to a CSV file, excluding certain internal fields and object references.

__init__(feed, entity_type)[source]

Initialize the CSV exporter.

Parameters:
  • feed (ColanderFeed) – The feed containing entities to export

  • entity_type (type[BaseModel]) – The Pydantic model type to filter entities by

Raises:

AssertionError – If entity_type is not a subclass of pydantic.BaseModel or feed is not a ColanderFeed.

export(output, **csv_options)[source]

Export the filtered entities to a CSV file. The CSV includes a header row and one row per entity with the computed field values.

Parameters:
  • output (TextIO) – A file-like object to write the CSV to

  • csv_options

    Optional keyword arguments passed to csv.DictWriter. Common options include:

    • quoting: csv.QUOTE_ALL, csv.QUOTE_MINIMAL, etc.

    • delimiter: Field delimiter

    • quotechar: Character used for quoting

    • lineterminator: Line terminator

    • extrasaction: How to handle extra fields

Raises:

AssertionError – If output is not a file-like object

excluded_fields: List[str] = ['colander_internal_type', 'attributes']

Fields to exclude from CSV export