Estimated reading time : 5 min · Published
Describe the data contract
Write a field dictionary covering meaning, type, unit, required status and missing values. Define stable identifiers and relations. A postal code, product number or administrative code may require a text representation to preserve its meaning.
Specify encoding, delimiter, dates, time zones and decimal conventions. Python’s CSV documentation explains dialect configuration; a file extension alone does not impose identical conventions on every producer.
Describe the CSV dialect and test fields before counting lines. In RFC 4180’s comma-separated format, fields containing a comma, double quote or line break are enclosed in double quotes; internal quotes are doubled. The table’s [CRLF] notation represents an actual carriage-return/line-feed pair in the test file. Such a field still belongs to one logical record.
Test case: a header and two data records, with CRLF inside the second record’s quoted field, occupy four physical lines, not four records. Use a CSV parser and compare fields. Python’s default reader returns strings, so 00120 retains its leading zeros unless a later conversion removes them. Define empty-field meaning and spreadsheet use separately: CSV quoting alone does not neutralise formulas.
Scroll the table horizontally to read every column. With a keyboard, focus the table area and use the arrow keys.
| Demonstration fragment | Field count | Parsed fields, shown as text |
|---|---|---|
| "Paris, France" | 1 | ["Paris, France"] |
| "A ""B""" | 1 | ["A \"B\""] |
| "A[CRLF]B" | 1 | ["A[CRLF]B"] |
| 00120, | 2 | ["00120", ""] |
Build a batch that challenges the boundaries
Include an accented name, an optional missing value, an identifier with a leading zero, a multiline description and a missing relation. Add a duplicate and an intentionally invalid format. Keep this dataset synthetic and clearly labelled as test data.
Decide whether a problem rejects one row, rejects the file or produces an import with an issue report. Avoid reporting success while silently dropping fields. Report accepted, rejected and review-required rows.
Plan exchange permissions and safety
Define who can export, import and remove a batch. Do not place confidential exports in a public folder by default. For files opened in spreadsheets, review fields that could be interpreted as formulas using a method appropriate to the receiving software.
Separate authorised data from internal context that should not travel, such as private comments, unnecessary contact details or technical keys. Use cleaned or synthetic test copies. Document storage, retention and who removes temporary exports.
Reconcile data after processing
Compare identifiers, relations, totals and sampled values before and after processing. If round-trip support is required, export and reimport into a test environment, then compare meaning rather than file size alone.
Keep a backup and record before a destructive import. Distinguish updates, additions and deletion. A missing row in a partial export does not automatically mean that it should be deleted. Agree on these rules before processing the full database.
Primary documentation : Python : CSV File Reading and Writing.
Fictional batch: six records carry the text identifiers 00120, 00121, 00120, 00122, 00123 and 00124, in that order. Before import, 00121 exists with a value to change and 00122 exists unchanged. The chosen rule accepts the first occurrence of a key, rejects repeats within the batch and rejects 00123 because a required relationship is missing. The first run therefore yields 2 created + 1 updated + 1 unchanged + 2 rejected = 6 examined records.
After that run, the target contains four identifiers: 00120, 00121, 00122 and 00124. Replaying exactly the same batch with the same rules and no intervening changes must yield 0 created, 0 updated, 4 unchanged and 2 rejected. This recovery behaviour comes from the chosen import contract, not automatically from CSV. Preserve leading zeros and count logical records read by the parser; a quoted field can contain a line break.
Scroll the table horizontally to read every column. With a keyboard, focus the table area and use the arrow keys.
| Outcome | Count | Affected records |
|---|---|---|
| Created | 2 | 00120 and 00124 |
| Updated | 1 | 00121: value differs from target |
| Unchanged | 1 | 00122: value already identical |
| Rejected | 2 | Occurrence 3: duplicate 00120; occurrence 5: missing relationship for 00123 |
- Python : CSV File Reading and Writing
Python CSV, consulted 22 October 2026: reading and formats. The data and acceptance rules are a fictional example.
Deliver exports with readable filenames in the published languages.
Synthetic case: an export filename contains accents. Test appropriate filename and filename* parameters, content type and the actually saved file. Sanitize names originating in user input before constructing headers. This header neither protects document access nor replaces authorization checks.
- The saved filename is readable, content type is accurate and input cannot inject another header.
- MDN Content-Disposition
Reference for inline presentation or downloading, including filename parameters.
Test a data round trip

Proposed case: export and import change leading-zero codes and dates. Row count stays the same, but values were altered.
Prepare fictional data with accents, empty cells and sensitive formats. Compare fields after the round trip and keep the report; error-free import does not guarantee fidelity.
- Define types and encoding
- Include format-sensitive values
- Compare fields after import
- Distinguish product variants
Prepare a useful product catalogue before building the shop
Reference documents
- MDN Content-Disposition · Source consulted
- W3C WAI : Tables Tutorial · Source consulted
- MDN : URLSearchParams · Source consulted
- IETF : RFC 4180: CSV format · Source consulted
- Python : CSV File Reading and Writing · Source consulted
- OWASP : CSV Injection · Source consulted
Content updated on
Documented reference points for this topic
| Reference | Value or syntax | Scope |
|---|---|---|
| RFC 4180 · CSV | text/csv · "a,b" | Fields containing commas, quotes or line breaks are quoted; internal quotes are doubled. |
| RFC 8259 · JSON | application/json · UTF-8 | Standard JSON permits neither comments nor trailing commas; strings use double quotes. |
| RFC 3339 · Date-time | 2026-10-22T09:00:00+02:00 | The explicit offset relates local time to UTC; this example is not an appointment. |
Dates indicate when references were consulted. These facts are neither a site audit nor an overall compliance statement.
