# Module: tf.compat

<br />

Compatibility functions.

The [`tf.compat`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat) module contains two sets of compatibility functions.

## Tensorflow 1.x and 2.x APIs

The [`compat.v1`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1) and `compat.v2` submodules provide a complete copy of both the
[`v1`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1) and `v2` APIs for backwards and forwards compatibility across TensorFlow
versions 1.x and 2.x. See the
[migration guide](https://www.tensorflow.org/guide/migrate) for details.

## Utilities for writing compatible code

Aside from the [`compat.v1`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1) and `compat.v2` submodules, [`tf.compat`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat) also contains
a set of helper functions for writing code that works in both:

- TensorFlow 1.x and 2.x
- Python 2 and 3

## Type collections

The compatibility module also provides the following aliases for common
sets of python types:

- `bytes_or_text_types`
- `complex_types`
- `integral_types`
- `real_types`

## Modules

[`v1`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1) module: Bring in all of the public TensorFlow interface into this module.

## Functions

[`as_bytes(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/as_bytes): Converts `bytearray`, `bytes`, or unicode python input types to `bytes`.

[`as_str(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/as_str)

[`as_str_any(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/as_str_any): Converts input to `str` type.

[`as_text(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/as_text): Converts any string-like python input types to unicode.

[`dimension_at_index(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/dimension_at_index): Compatibility utility required to allow for both V1 and V2 behavior in TF.

[`dimension_value(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/dimension_value): Compatibility utility required to allow for both V1 and V2 behavior in TF.

[`forward_compatibility_horizon(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/forward_compatibility_horizon): Context manager for testing forward compatibility of generated graphs.

[`forward_compatible(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/forward_compatible): Return true if the forward compatibility window has expired.

[`path_to_str(...)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/path_to_str): Converts input which is a `PathLike` object to `str` type.

<br />

<br />

<br />

| ## Other Members ||
|---|---|
| bytes_or_text_types | `(<class 'bytes'>, <class 'str'>)` |
| complex_types | `(<class 'numbers.Complex'>, <class 'numpy.number'>)` |
| integral_types | `(<class 'numbers.Integral'>, <class 'numpy.integer'>)` |
| real_types | `(<class 'numbers.Real'>, <class 'numpy.integer'>, <class 'numpy.floating'>)` |

<br />