Clients¶
HTTP clients for the CleanCSV API. Implementation module: cleancsv.client.
- class cleancsv.client.CleanCSVClient(base_url, *, timeout=120.0, client=None)[source]¶
Bases:
objectSynchronous HTTP client for CleanCSV
cleanandsuggestendpoints.Pass the deployment origin only (no path): paths such as
/api/v1/cleanand/api/v1/suggestare appended by each method. Usecleancsv.DEFAULT_BASE_URLfor the public app.Use as a context manager to ensure the underlying connection is closed:
with CleanCSVClient(base_url) as client: result = client.clean(path_to_csv)
- Raises:
cleancsv.errors.CleanCSVError – On HTTP error responses from the API.
cleancsv.errors.RateLimitError – On HTTP 429 when rate limits apply.
- clean(file, *, config=None, filename='upload.csv', version='v1', query=None)[source]¶
Upload a CSV via multipart POST to
/api/{version}/clean.Sends the file as form field
fileand optionalconfigas a JSON string whenconfigis set. URL query parameters such asformat,dedup_by, orstrategycan be supplied viaquery(merged with any existing query).- Parameters:
file (Path | bytes | bytearray | BinaryIO) – CSV payload: path, bytes, or binary stream.
config (CleanConfig | str | None) – Cleaning options as
CleanConfig, a JSON string, orNoneto omit the config field.filename (str) – Filename sent in the multipart part (default
upload.csv).version (Literal['v1', 'demo']) – API segment:
"v1"or"demo".query (dict[str, str] | None) – Optional query parameters merged into the request URL.
- Returns:
CleanResultwith status, headers, raw body bytes, andContent-Type.- Raises:
cleancsv.errors.CleanCSVError – On non-success HTTP status (except 429).
cleancsv.errors.RateLimitError – On HTTP 429.
TypeError – If
filecannot be read as bytes.
- Return type:
- clean_raw_body(body, *, content_type='text/csv', version='v1', query=None)[source]¶
POST raw CSV bytes to
/api/{version}/cleanwithout multipart encoding.Use when the server accepts a raw request body. Query parameters can still be passed via
query. This path does not send a multipartconfigfield; configure via URL query if the API supports it.- Parameters:
- Returns:
CleanResultwith response metadata and body.- Raises:
cleancsv.errors.CleanCSVError – On non-success HTTP status (except 429).
cleancsv.errors.RateLimitError – On HTTP 429.
- Return type:
- suggest(file, *, filename='upload.csv', version='v1')[source]¶
Upload a CSV via multipart POST to
/api/{version}/suggest.Returns parsed JSON describing suggested deduplication rules and column stats.
- Parameters:
- Returns:
SuggestResponseparsed from the JSON body.- Raises:
cleancsv.errors.CleanCSVError – On non-success HTTP status, invalid JSON, or a non-object JSON body.
cleancsv.errors.RateLimitError – On HTTP 429.
TypeError – If
filecannot be read as bytes.
- Return type:
- suggest_raw_body(body, *, content_type='text/csv', version='v1')[source]¶
POST raw CSV bytes to
/api/{version}/suggestwithout multipart encoding.- Parameters:
- Returns:
SuggestResponseparsed from the JSON body.- Raises:
cleancsv.errors.CleanCSVError – On HTTP errors or malformed JSON response.
cleancsv.errors.RateLimitError – On HTTP 429.
- Return type:
- class cleancsv.client.AsyncCleanCSVClient(base_url, *, timeout=120.0, client=None)[source]¶
Bases:
objectAsynchronous HTTP client for CleanCSV; mirrors
CleanCSVClientwith async I/O.Use
async withto close the underlying client when it was created internally:async with AsyncCleanCSVClient(base_url) as client: result = await client.clean(path_to_csv)
- Raises:
cleancsv.errors.CleanCSVError – On HTTP error responses from the API.
cleancsv.errors.RateLimitError – On HTTP 429 when rate limits apply.
- async clean(file, *, config=None, filename='upload.csv', version='v1', query=None)[source]¶
Async version of
CleanCSVClient.clean().- Parameters:
file (Path | bytes | bytearray | BinaryIO) – CSV payload: path, bytes, or binary stream.
config (CleanConfig | str | None) –
CleanConfig, JSON string, orNone.filename (str) – Multipart filename (default
upload.csv).version (Literal['v1', 'demo']) –
"v1"or"demo".query (dict[str, str] | None) – URL query parameters to merge.
- Returns:
CleanResultwith raw response body and metadata.- Raises:
cleancsv.errors.CleanCSVError – On HTTP errors (except 429).
cleancsv.errors.RateLimitError – On HTTP 429.
TypeError – If
filecannot be read as bytes.
- Return type:
- async clean_raw_body(body, *, content_type='text/csv', version='v1', query=None)[source]¶
Async version of
CleanCSVClient.clean_raw_body().- Parameters:
- Returns:
- Raises:
cleancsv.errors.CleanCSVError – On HTTP errors (except 429).
cleancsv.errors.RateLimitError – On HTTP 429.
- Return type:
- async suggest(file, *, filename='upload.csv', version='v1')[source]¶
Async version of
CleanCSVClient.suggest().- Parameters:
- Returns:
- Raises:
cleancsv.errors.CleanCSVError – On HTTP errors or invalid JSON.
cleancsv.errors.RateLimitError – On HTTP 429.
TypeError – If
filecannot be read as bytes.
- Return type:
- async suggest_raw_body(body, *, content_type='text/csv', version='v1')[source]¶
Async version of
CleanCSVClient.suggest_raw_body().- Parameters:
- Returns:
- Raises:
cleancsv.errors.CleanCSVError – On HTTP errors or malformed JSON.
cleancsv.errors.RateLimitError – On HTTP 429.
- Return type: