Metadata-Version: 2.4
Name: athena2duckdb
Version: 0.1.1
Summary: Load OMOP Athena vocabulary exports into DuckDB
Project-URL: Homepage, https://github.com/sidataplus/athena2duckdb
Project-URL: Repository, https://github.com/sidataplus/athena2duckdb
Project-URL: Issues, https://github.com/sidataplus/athena2duckdb/issues
Author-email: Max Natthawut Adulyanukosol <natthawut.adu@mahidol.ac.th>
License: MIT License
        
        Copyright (c) 2025 Siriraj Informatics and Data Innovation Center (SiData+)
        
        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.
License-File: LICENSE
Keywords: athena,duckdb,ohdsi,omop,vocabulary
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.9
Requires-Dist: duckdb>=1.4.1
Description-Content-Type: text/markdown

## OMOP Athena → DuckDB

`athena2duckdb` converts an extracted OMOP vocabulary download from
[OHDSI Athena](https://athena.ohdsi.org/) into a ready-to-query DuckDB file with
typed CDM tables, primary keys, and automatic row-count validation. The loader
ingests the standard OMOP vocab files (`CONCEPT.csv`, `VOCABULARY.csv`, etc.)
and skips auxiliary exports like `CONCEPT_CPT4.csv` or `README.txt` by default.

### Features
- Discovers standard OMOP vocabulary files such as `CONCEPT.csv`,
  `VOCABULARY.csv`, `CONCEPT_RELATIONSHIP.csv`, and more.
- Streams each file into DuckDB using `read_csv` with quoting/escaping disabled,
  preventing parse failures caused by embedded quotes or backslashes, while the
  CLI shows a live progress bar per table.
- Loads recognised vocab files into typed tables (INTEGER, DATE, VARCHAR) that
  match the CDM DDL with primary keys already enforced (secondary indexes can be
  added later if needed).
- Always performs row-count verification to ensure the database matches source
  files.

### Installation

From PyPI:

```bash
pip install athena2duckdb
```

For local development:

```bash
uv sync
```

or build/install directly from the project root:

```bash
uv build
pip install dist/athena2duckdb-*.whl
```

### CLI Usage

```bash
uv run athena2duckdb /path/to/athena-export --verbose
```

Arguments:

| Flag | Description |
|------|-------------|
| `input_dir` | Directory that contains the Athena CSV/TSV files. |
| `-o, --out` | Output DuckDB database file (default `omop_vocab.duckdb`). |
| `--sep` | Field delimiter (default tab). |
| `--encoding` | Source file encoding (default `UTF-8`). |
| `--threads` | Number of DuckDB threads to use. |
| `--schema` | DuckDB schema name for created tables (default `main`). |
| `--overwrite` | Replace an existing DuckDB file if present. |
| `--verbose` | Emit INFO-level logs during the load. |

### Example

```bash
uv run athena2duckdb data/
```

Sample output:

```
Loaded 10 tables into omop_vocab.duckdb.
Tables: concept, concept_ancestor, concept_class, concept_relationship, concept_synonym,
domain, drug_strength, source_to_concept_map, relationship, vocabulary
OK        table=concept                  csv_rows=93,547 table_rows=93,547
...
```

### Programmatic API

```python
from pathlib import Path
from athena2duckdb import CSVOptions, load_vocab_dir, verify_row_counts

summary = load_vocab_dir(Path("data"), Path("omop_vocab.duckdb"), schema="cdm")
results = verify_row_counts(summary.db_path, summary.vocab_files, schema=summary.schema)
```

### Testing

```bash
uv run pytest
```

### Releasing

See [RELEASING.md](RELEASING.md).

### License

This project is licensed under the MIT License. See [LICENSE](LICENSE).
