Practical guides

Prepare reliable data imports and exports

A file that opens is not necessarily usable. Reliable exchange preserves field meanings, distinguishes unknown values from zero and matches records without treating a display label as a fragile identifier.

Go to the method

Exchange without losing meaning

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.

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.

Acceptance matrix to adapt to your project

These proposed checks use synthetic cases. Decide the required behaviour with the team, record the result and assign unresolved gaps before release.

Test cases, expected outcomes and useful evidence
CaseExpected outcomeEvidence to retain
Accents, separators and multiline textValues keep their meaning after export and reimport.Field-by-field comparison using a small representative reference file with known values.
Zero, empty, null and absentThe four states follow distinct rules where required by the contract.Data dictionary and values actually received by the destination.
Repeated identifierThe chosen rule distinguishes duplication, updates and legitimate variants.Accepted and refused row log, with a reason for each decision.
Failure halfway throughThe team knows which changes were applied and how to resume.Final state, affected rows and a recovery procedure exercised with synthetic data.

Frequently asked questions

Why keep some codes as text?

They identify an entity rather than a quantity. Automatic conversion can lose leading zeros or change presentation. Define the type in the contract and test a boundary example.

Does an unchanged row count prove a correct import?

No. Counts may match despite lost fields, broken relations or incorrect replacements. Compare identifiers, values, units and errors using a representative batch.