# tff.framework.serialize_value

<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) |

Serializes a value into `executor_pb2.Value`.

    tff.framework.serialize_value(
        value: object,
        type_spec: Optional[https://www.tensorflow.org/federated/api_docs/python/tff/types/Type] = None
    ) -> _SerializeReturnType

We use a switch/function pattern in the body here (and in `deserialize_value`
below in order to persist more information in traces and profiling.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `value` | A value to be serialized. |
| `type_spec` | An optional [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A 2-tuple of serialized value and [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type) that represents the TFF type of the serialized value. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If the arguments are of the wrong types. |
| `ValueError` | If the value is malformed. |

<br />