Metadata-Version: 2.4
Name: codec_bridge
Version: 0.2.0
Summary: Detect encoding from CSV files and return the accepted case format for analytical tools (currently supports DuckDB)
Home-page: https://github.com/jpferraz-git/codec_bridge
Author: João Pedro Ferraz Bezerra
Author-email: João Pedro Ferraz Bezerra <jpferraz554@gmail.com>
License: MIT License
        
        Copyright (c) 2025 João Pedro Ferraz Bezerra
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: license.txt
Requires-Dist: charset-normalizer>=3.4.2
Requires-Dist: duckdb>=1.3.2
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# codec_bridge

A Python utility library that bridges encoding mismatches between Python and DuckDB when reading raw CSV files.

## 🔍 Motivation

DuckDB recently introduced the `encodings` extension, supporting over a thousand character encodings. However, Python often detects encodings using a format or casing that DuckDB does not accept directly. 

For example:
- Python detects: `ISO-8859-1`
- DuckDB expects: `latin`

This mismatch can break ingestion pipelines, especially when dealing with large volumes of raw CSV files from diverse sources. The goal of this library is to act as a **bridge**, translating Python-standard encoding names into DuckDB-compatible formats.

## ⚙️ Features

- ✅ `get_duckdb_encoding`: Main method that maps Python encoding names to DuckDB-compatible formats.
- 🔍 `detect_encoding`: Detects the encoding of a file using `charset-normalizer`.
- 📌 `detect_delimiter`: Identifies the most likely delimiter used in a CSV file.
- ✍️ `write_utf8_csv`: Rewrites a file to UTF-8 encoding when necessary.
- 📦 `process_files`: Scans a directory of CSV files and returns metadata for each file.

## 📦 Installation

```bash
pip install codec_bridge
```

## 🔧 Requirements

This library depends on:

- `duckdb` (>=1.3.2)
- `charset-normalizer` (>=3.4.2)

These will be installed automatically when using `pip install codec_bridge`.
