Metadata-Version: 2.4
Name: modify-csv
Version: 2026.10.8
Summary: Apply a user-supplied Python function to a CSV row, column, or cell.
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# modify-csv

Apply a user-provided Python function to every cell in one CSV data row, every
cell in one column, or one cell. The CSV's first record is treated as its header
and is never modified. Row and column indexes are zero-based; columns can also
be addressed by their exact header text.

## Install

Install a published release from PyPI:

```sh
python -m pip install modify-csv
```

## Script contract

The supplied script must define exactly this callable shape:

```python
from typing import Any


def eval(content: Any, row: int, col: int) -> Any:
    return content
```

`Any` is provided by Python's standard-library `typing` module. The function
name, parameter names, and three-argument shape are enforced.

`content` is the current CSV field (initially a string), while `row` and `col`
are zero-based numeric indexes into the data records and columns. The returned
value is passed to Python's CSV writer. The script is ordinary trusted Python
and executes with the same permissions as the command.

## Examples

Apply a script file to a column selected by header:

```sh
modify-csv apply input.csv output.csv --script-file normalize.py --column email
```

Apply inline code to data row 2:

```sh
modify-csv apply input.csv output.csv \
  --script 'def eval(content, row, col): return content.strip()' \
  --row 2
```

Apply inline code to the cell at data row 0 and column 1:

```sh
modify-csv apply input.csv output.csv \
  --script 'def eval(content, row, col): return int(content) * 2' \
  --cell 0 1
```

Exactly one of `--script` or `--script-file`, and exactly one of `--row`,
`--column`, or `--cell`, is required. Existing output files are protected;
pass `--force` to replace one.

Generate a ready-to-edit transformation script:

```sh
modify-csv template transform.py
```

Use `--force` to replace an existing template. Run `modify-csv --help` or the
help for either subcommand to see the required function signature. The original
form without the `apply` subcommand remains supported for compatibility.
