Previous topic

PyTango API

Next topic

Client API

This Page

Data typesΒΆ

This chapter describes the mapping of data types between Python and Tango.

Tango has more data types than Python which is more dynamic. The input and output values of the commands are translated according to the array below. Note that if PyTango is compiled with numpy support the numpy type will be the used for the input arguments. Also, it is recomended to use numpy arrays of the appropiate type for output arguments as well, as they tend to be much more efficient.

For scalar types (SCALAR)

Tango data type Python 2.x type Python 3.x type (New in PyTango 8.0)
DEV_VOID No data No data
DEV_BOOLEAN bool bool
DEV_SHORT int int
DEV_LONG int int
DEV_LONG64
  • long (on a 32 bits computer)
  • int (on a 64 bits computer)
int
DEV_FLOAT float float
DEV_DOUBLE float float
DEV_USHORT int int
DEV_ULONG int int
DEV_ULONG64
  • long (on a 32 bits computer)
  • int (on a 64 bits computer)
int
DEV_STRING str str (decoded with latin-1, aka ISO-8859-1)
DEV_ENCODED (New in PyTango 8.0)

sequence of two elements:

  1. str
  2. bytes (for any value of extract_as)

sequence of two elements:

  1. str (decoded with latin-1, aka ISO-8859-1)
  2. bytes (for any value of extract_as, except String. In this case it is str (decoded with default python encoding utf-8))

For array types (SPECTRUM/IMAGE)

Tango data type ExtractAs Data type (Python 2.x) Data type (Python 3.x) (New in PyTango 8.0)
DEVVAR_CHARARRAY Numpy numpy.ndarray (dtype= numpy.uint8) numpy.ndarray (dtype= numpy.uint8)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int> list <int>
Tuple tuple <int> tuple <int>
DEVVAR_SHORTARRAY or (DEV_SHORT + SPECTRUM) or (DEV_SHORT + IMAGE) Numpy numpy.ndarray (dtype= numpy.uint16) numpy.ndarray (dtype= numpy.uint16)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int> list <int>
Tuple tuple <int> tuple <int>
DEVVAR_LONGARRAY or (DEV_LONG + SPECTRUM) or (DEV_LONG + IMAGE) Numpy numpy.ndarray (dtype= numpy.uint32) numpy.ndarray (dtype= numpy.uint32)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int> list <int>
Tuple tuple <int> tuple <int>
DEVVAR_LONG64ARRAY or (DEV_LONG64 + SPECTRUM) or (DEV_LONG64 + IMAGE) Numpy numpy.ndarray (dtype= numpy.uint64) numpy.ndarray (dtype= numpy.uint64)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int (64 bits) / long (32 bits)> list <int>
Tuple tuple <int (64 bits) / long (32 bits)> tuple <int>
DEVVAR_FLOATARRAY or (DEV_FLOAT + SPECTRUM) or (DEV_FLOAT + IMAGE) Numpy numpy.ndarray (dtype= numpy.float32) numpy.ndarray (dtype= numpy.float32)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <float> list <float>
Tuple tuple <float> tuple <float>
DEVVAR_DOUBLEARRAY or (DEV_DOUBLE + SPECTRUM) or (DEV_DOUBLE + IMAGE) Numpy numpy.ndarray (dtype= numpy.float64) numpy.ndarray (dtype= numpy.float64)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <float> list <float>
Tuple tuple <float> tuple <float>
DEVVAR_USHORTARRAY or (DEV_USHORT + SPECTRUM) or (DEV_USHORT + IMAGE) Numpy numpy.ndarray (dtype= numpy.uint16) numpy.ndarray (dtype= numpy.uint16)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int> list <int>
Tuple tuple <int> tuple <int>
DEVVAR_ULONGARRAY or (DEV_ULONG + SPECTRUM) or (DEV_ULONG + IMAGE) Numpy numpy.ndarray (dtype= numpy.uint32) numpy.ndarray (dtype= numpy.uint32)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int> list <int>
Tuple tuple <int> tuple <int>
DEVVAR_ULONG64ARRAY or (DEV_ULONG64 + SPECTRUM) or (DEV_ULONG64 + IMAGE) Numpy numpy.ndarray (dtype= numpy.uint64) numpy.ndarray (dtype= numpy.uint64)
Bytes bytes (which is in fact equal to str) bytes
ByteArray bytearray bytearray
String str String str (decoded with default python encoding utf-8!!!)
List list <int (64 bits) / long (32 bits)> list <int>
Tuple tuple <int (64 bits) / long (32 bits)> tuple <int>
DEVVAR_STRINGARRAY or (DEV_STRING + SPECTRUM) or (DEV_STRING + IMAGE)   sequence<str> sequence<str> (decoded with latin-1, aka ISO-8859-1)
DEV_LONGSTRINGARRAY  

sequence of two elements:

  1. numpy.ndarray (dtype= numpy.int32) or sequence<int>
  2. sequence<str>

sequence of two elements:

  1. numpy.ndarray (dtype= numpy.int32) or sequence<int>
  2. sequence<str> (decoded with latin-1, aka ISO-8859-1)
DEV_DOUBLESTRINGARRAY  

sequence of two elements:

  1. numpy.ndarray (dtype= numpy.float64) or sequence<int>
  2. sequence<str>

sequence of two elements:

  1. numpy.ndarray (dtype= numpy.float64) or sequence<int>
  2. sequence<str> (decoded with latin-1, aka ISO-8859-1)

For SPECTRUM and IMAGES the actual sequence object used depends on the context where the tango data is used, and the availability of numpy.

  1. for properties the sequence is always a list. Example:

    >>> import PyTango
    >>> db = PyTango.Database()
    >>> s = db.get_property(["TangoSynchrotrons"])
    >>> print type(s)
    <type 'list'>
    
  2. for attribute/command values