# tff.program.CSVFileReleaseManager

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

A [`tff.program.ReleaseManager`](https://www.tensorflow.org/federated/api_docs/python/tff/program/ReleaseManager) that releases values to a CSV file.

Inherits From: [`ReleaseManager`](https://www.tensorflow.org/federated/api_docs/python/tff/program/ReleaseManager)

    tff.program.CSVFileReleaseManager(
        file_path: Union[bytes, str, os.PathLike[Union[bytes, str]]],
        save_mode: https://www.tensorflow.org/federated/api_docs/python/tff/program/CSVSaveMode = https://www.tensorflow.org/federated/api_docs/python/tff/program/CSVSaveMode#APPEND,
        key_fieldname: str = 'key'
    )

A [`tff.program.CSVFileReleaseManager`](https://www.tensorflow.org/federated/api_docs/python/tff/program/CSVFileReleaseManager) is a utility for releasing values
from a federated program to a CSV file and is used to release values from
platform storage to customer storage in a federated program.

Values are released to the file system as a CSV file and are quoted as
strings. When the value is released, each
[`tff.program.MaterializableValueReference`](https://www.tensorflow.org/federated/api_docs/python/tff/program/MaterializableValueReference) is materialized. The value is then
flattened, converted to a `numpy.ndarray`, and then converted to a nested list
of Python scalars, and released as a CSV file. For example, `1` will be
written as `'1'` and `tf.constant([[1, 1], [1, 1]])` will be written as
`'[[1, 1], [1, 1]]'`.

This manager can be configured to release values using a `save_mode` of either
[`CSVSaveMode.APPEND`](https://www.tensorflow.org/federated/api_docs/python/tff/program/CSVSaveMode#APPEND) or [`CSVSaveMode.WRITE`](https://www.tensorflow.org/federated/api_docs/python/tff/program/CSVSaveMode#WRITE).

- In append mode, when a value is released, this manager will try and append
  the value to the CSV file instead of overwriting the existing file. While
  potentially more efficient, append mode is incompatible with compressed
  files (e.g. `.bz2` formats) and encoded directories. This mode is equivalent
  to write mode when releasing a value with a different structure than the
  currently released values, so it may not be useful when values with
  different structures are being released frequently.

- In write mode (or in append mode when releasing new structures), when a
  value is realeased, this manager reads the entire CSV file and overwrites
  the existing file with the additional values. This can be slower than append
  mode, but is compatible with compressed files (e.g. `.bz2` formats) and
  encoded directories.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `file_path` | A path on the file system to save releases values. If this file does not exist it will be created. |
| `save_mode` | A [`tff.program.CSVSaveMode`](https://www.tensorflow.org/federated/api_docs/python/tff/program/CSVSaveMode) specifying how to save released values. |
| `key_fieldname` | A `str` specifying the fieldname used for the key when saving released value. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `file_path` or `key_fieldname` is an empty string. |
| `CSVKeyFieldnameNotFoundError` | If the file exists but does not contain a fieldname of `key_fieldname`. |

<br />

## Methods

### `release`

[View source](https://github.com/tensorflow/federated/blob/v0.87.0
Version 2.0, January 2004
Licensed under the Apache License, Version 2.0 (the)

    release(
        value: https://www.tensorflow.org/federated/api_docs/python/tff/program#ReleasableStructure,
        key
    ) -> value_reference.MaterializedValue

Releases `value` from a federated program.

This method will atomically update the managed CSV file by removing all
values previously released with a key greater than or equal to `key` before
writing `value`.

<br />

<br />

<br />

| Args ||
|---|---|
| `value` | A [`tff.program.ReleasableStructure`](https://www.tensorflow.org/federated/api_docs/python/tff/program#ReleasableStructure) to release. |
| `key` | An integer used to reference the released `value`; `key` represents a step in a federated program. |

<br />