import ctypes class X(ctypes.Structure): _swappedbytes_ = 1 _pack_ = 1 _fields_ = [ ('a', ctypes.c_ubyte, 4), ('b', ctypes.c_ubyte, 4), ('c', ctypes.c_ushort, 8), ('d', ctypes.c_ushort, 8), ] buf = '\x12\x34\x56\x78' x = X.from_buffer_copy(buf) print X.a print X.b print X.c print X.d print x.a == 1 print x.b == 2 print x.c == 3 print x.d == 4