# tff.types.to_type

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

Converts the argument into an instance of [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type).

#### View aliases


**Main aliases**

[`tff.to_type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/to_type)

<br />

    tff.types.to_type(
        obj: object
    ) -> https://www.tensorflow.org/federated/api_docs/python/tff/types/Type

Examples of arguments convertible to tensor types:

    np.int32
    (np.int32, [10])
    (np.int32, [None])

Examples of arguments convertible to flat named tuple types:

    [np.int32, np.bool]
    (np.int32, np.bool)
    [('a', np.int32), ('b', np.bool)]
    ('a', np.int32)
    collections.OrderedDict([('a', np.int32), ('b', np.bool)])

Examples of arguments convertible to nested named tuple types:

    (np.int32, (np.float32, np.bool))
    (np.int32, (('x', np.float32), np.bool))
    ((np.int32, [1]), (('x', (np.float32, [2])), (np.bool, [3])))

`attr.s` class instances can also be used to describe TFF types by populating
the fields with the corresponding types:

    @attr.s(auto_attribs=True)
    class MyDataClass:
      int_scalar
      string_array

    obj = MyDataClass(...)
    type_spec = tff.types.to_type(obj)

    @tff.tensorflow.computation(type_spec)
    def work(my_data):
      assert isinstance(my_data, MyDataClass)
      ...

<br />

<br />

<br />

| ## Args ||
|---|---|
| `obj` | Either an instance of [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type), or an argument convertible to [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| An instance of [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type) corresponding to the given `obj`. ||

<br />