Metadata-Version: 2.4
Name: databridge-cli
Version: 0.1.1
Summary: Portable local CSV and JSON table operations
Author: Ahmed Saeed
License-Expression: MIT
Project-URL: Repository, https://github.com/ahmedsaeed1-eng/databridge-cli
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: hypothesis<7,>=6; extra == "test"
Requires-Dist: ruff==0.17.6; extra == "test"
Requires-Dist: black==26.10.1; extra == "test"
Dynamic: license-file

![DataBridge CLI terminal interface — CSV to JSON, local computation](assets/logo.svg)

# DataBridge CLI

`python >= 3.10` · **0 runtime dependencies** · [MIT](LICENSE) · v0.1.1

[![GitHub stars](https://img.shields.io/github/stars/ahmedsaeed1-eng/databridge-cli?style=flat-square&color=23865c)](https://github.com/ahmedsaeed1-eng/databridge-cli/stargazers) [![CI](https://github.com/ahmedsaeed1-eng/databridge-cli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ahmedsaeed1-eng/databridge-cli/actions/workflows/ci.yml) [![MIT](https://img.shields.io/badge/license-MIT-087f8c?style=flat-square)](LICENSE) ![Runtime offline](https://img.shields.io/badge/runtime-offline-648577?style=flat-square)

A local CSV/JSON toolkit built around explicit terminal commands. Validate the shape of a table, inspect columns, convert formats and export Markdown without a spreadsheet application.

---

## A terminal-first workflow

```console
$ python -m databridge validate examples/inventory.csv
{
  "valid": true,
  "rows": 3,
  "columns": [
    "item",
    "quantity",
    "location"
  ]
}
```

**Input → Inspect → Transform → Export**

The output of a successful validation is JSON. CSV data stays text, preserving values such as leading zeros. Conversion and export work offline with the Python standard library. DataBridge is deliberately not a general-purpose application control framework.

## Quick start

Clone the repository and run from the checkout with Python 3.10 or later:

```sh
python -m databridge --help
python -m databridge validate examples/inventory.csv
python -m databridge summary examples/inventory.csv
python -m databridge convert examples/inventory.csv --to json
python -m databridge select examples/inventory.csv --column location --column item --to csv
python -m databridge markdown examples/inventory.csv
```

Optional installation with available setuptools/build dependencies: `python -m pip install .` then use `databridge` instead of `python -m databridge`. Running from checkout needs no package installation or network.

## Command reference

| Command | Function | Output |
|---|---|---|
| `validate` | Check UTF-8, table shape and supported scalar cells | JSON shape report |
| `summary` | Count rows, columns, missing values and field types | JSON summary |
| `convert --to csv/json` | Convert a complete table | CSV or JSON |
| `select --column NAME ... --to csv/json` | Select/reorder explicit columns | CSV or JSON |
| `markdown` | Escape values into a Markdown table | Markdown |

Conversion, selection and Markdown accept `--output PATH` (new file only) and `--dry-run`. Dry runs compute the output size without writing; validation reports data shape rather than schema or business-rule validity. Input format is inferred by extension or set by `--input-format csv/json`; `--delimiter` changes CSV parsing and CSV output delimiter (must be one non-newline character, not the quote character).

Example dry run:

```sh
python -m databridge convert examples/inventory.csv --to json --output inventory.json --dry-run
```

Example output:

```json
{
  "valid": true,
  "dry_run": true,
  "rows": 3,
  "columns": ["item", "quantity", "location"],
  "output_bytes": 249,
  "writes": 0
}
```

The byte count varies with data; run the command for the exact count.

## Behavior and limitations

- Only UTF-8 regular input files and explicitly named output paths; no network, external commands or plugins.
- Maximum input 16 MiB, 100,000 rows, 256 columns; processing is in memory.
- CSV requires unique nonblank headers and uniform row width; all CSV data is text to preserve leading zeros and avoid accidental type coercion.
- JSON requires a nonempty array of records with matching keys and primitive scalar values; nested data, duplicate keys and nonfinite numbers are rejected.
- Conversion to CSV represents null as empty text and numbers/booleans as strings. A header-only CSV produces an empty JSON array that cannot be reimported with header metadata.
- Missing means null or empty string. Markdown line breaks become spaces; escaped text is not a rendered HTML guarantee. Treat data from untrusted sources as untrusted if opening in other applications, including spreadsheet programs.
- A supplied output path is created exclusively and cannot overwrite existing files. Input and output paths are explicit. There is no automatic discovery of personal files.
- Reports and errors are JSON; invalid data/I/O errors are sent to stderr with exit code 1. CLI argument errors use argparse and exit code 2.

## Development

```sh
python -m pip install ".[test]"
ruff check databridge tests
black --check databridge tests
python -m unittest discover -s tests -v
```

The tests exercise the parsers, Unicode, malformed records, selection, Markdown escaping, the real CLI, and non-overwriting dry runs. A property test exercises quoted Unicode CSV round trips across delimiters (75 generated inputs); 13 local tests, Ruff and Black passed on Linux/Python 3.12. CI runs the same checks across configured Python/OS combinations; consult actual remote results.

## Acknowledgement

The idea of predictable command-oriented interfaces was inspired by [HKUDS/CLI-Anything](https://github.com/HKUDS/CLI-Anything). This independently written project uses no source code or assets from that repository and has a narrower local data scope. Original code and original logo are under the [MIT License](LICENSE).

### Distribution

A release workflow is prepared for future PyPI Trusted Publishing and requires explicit dispatch with publishing enabled plus configured publisher authorization. The package is not yet published; use the source installation above.
