Types and configuration¶
Dataclasses and helpers matching the clean/suggest request and response payloads. Implementation module: cleancsv.types.
- class cleancsv.types.MojibakeMapping(from_, to)[source]¶
Single replacement rule for fixing mojibake in
EncodingConfig.
- class cleancsv.types.DedupConfig(columns=None, strategy='first', fuzzy=False, threshold=0.85, normalize=False, preview=False, nulls_equal=True)[source]¶
Deduplication options under
dedupinCleanConfig.- columns¶
Column names to use for duplicate detection;
Nonemeans API default.
- strategy¶
How to pick the surviving row among duplicates.
- Type:
Literal[‘first’, ‘last’, ‘most_complete’, ‘merge’]
- class cleancsv.types.EncodingConfig(encoding='auto', fallback=None, fix_mojibake=True, custom_mojibake_mappings=None, normalize_unicode=True, strip_control_chars=True, strip_invisible=True, fix_bom=True, line_endings='unix')[source]¶
Encoding and text-normalization options under
encodinginCleanConfig.- custom_mojibake_mappings¶
Optional list of
MojibakeMappingrules.- Type:
list[cleancsv.types.MojibakeMapping] | None
- normalize_unicode¶
If
Trueor a Unicode form name, apply normalization.- Type:
bool | Literal[‘NFC’, ‘NFD’, ‘NFKC’, ‘NFKD’]
- line_endings¶
Normalized line ending style:
unix,windows, orauto.- Type:
Literal[‘unix’, ‘windows’, ‘auto’]
- class cleancsv.types.NullColumnConfig(treat_empty_as_null=None, null_values=None, fill=None, cast=None)[source]¶
Per-column null handling under
null_handling.per_column.- cast¶
Target type for casting:
string,int,float,boolean,auto.- Type:
Literal[‘string’, ‘int’, ‘float’, ‘boolean’, ‘auto’] | None
- class cleancsv.types.NullHandlingConfig(null_values=None, treat_empty_as_null=True, type_inference=True, fill='leave', per_column=None)[source]¶
Global and per-column null handling under
null_handlinginCleanConfig.- per_column¶
Optional map of column name to
NullColumnConfig.- Type:
dict[str, cleancsv.types.NullColumnConfig] | None
- class cleancsv.types.CleanConfig(format='json', dedup=None, encoding=None, null_handling=None, null_representation=None, filter_invalid_emails=False, email_columns=None)[source]¶
Cleaning options sent as the multipart form field
config(JSON string).Corresponds to the CleanCSV upload/config schema: output
format, optionaldedup,encoding,null_handling, email filters, etc.- format¶
Response format for the clean endpoint:
jsonorcsv.- Type:
Literal[‘json’, ‘csv’]
- dedup¶
Optional
DedupConfig.- Type:
cleancsv.types.DedupConfig | None
- encoding¶
Optional
EncodingConfig.- Type:
- null_handling¶
Optional
NullHandlingConfig.- Type:
- to_json()[source]¶
Serialize
to_api_dict()to a compact JSON string (no extra whitespace).- Returns:
JSON text suitable for the multipart
configfield.- Return type:
- classmethod from_suggested_rule(rule, *, format='json')[source]¶
Build a minimal clean config from one
SuggestedRule(e.g. aftersuggest).- Parameters:
rule (SuggestedRule) – A suggested rule from
SuggestResponse.format (Literal['json', 'csv']) – Desired clean output format (
jsonorcsv).
- Returns:
CleanConfigwithdeduppopulated from the rule’s columns and flags.- Return type:
- class cleancsv.types.SuggestedRule(dedup_by, fuzzy, normalize, reason, threshold=None)[source]¶
One deduplication suggestion from the
/suggestAPI.
- class cleancsv.types.SuggestResponse(row_count, column_count, columns, suggested_rules, null_profiles=None, warnings=None)[source]¶
Structured JSON body from
POST .../suggest.- suggested_rules¶
List of
SuggestedRuleentries.- Type:
- class cleancsv.types.CleanResult(status_code, content_type, body, headers=<factory>)[source]¶
Raw HTTP result from
POST .../cleanbefore parsing structured JSON/CSV.- property text: str¶
Decode
bodyas UTF-8 with replacement for invalid sequences.- Returns:
Unicode text of the response body.
- parse_json()[source]¶
Parse the body as JSON into
CleanResponsewhen format is JSON.- Returns:
Structured clean response with
meta,data, and optional preview fields.- Raises:
ValueError – If
Content-Typedoes not indicate JSON or JSON is invalid.- Return type:
- class cleancsv.types.CleanResponse(meta, data, duplicate_groups=None, preview_source=None, preview_cleaned=None, preview_row_in_output=None, preview_row_removal_reason=None)[source]¶
Parsed JSON body from a successful JSON-format clean operation.
- preview_row_removal_reason¶
Optional reasons for excluded preview rows.
- cleancsv.types.config_from_mapping(m)[source]¶
Build
CleanConfigfrom a plain dict (e.g. loaded from JSON on disk).Recognizes the same keys as the API:
format,dedup,encoding,null_handling,null_representation,filter_invalid_emails,email_columns.- Parameters:
m (Mapping[str, Any]) – Configuration mapping in API snake_case shape.
- Returns:
Populated
CleanConfigwith nested dataclasses where sections exist.- Return type: