### This solution only changes the order of columns in the attribute table, and not in the original file. This PyQGIS solution utilizes the [`setColumns()`](https://api.qgis.org/api/classQgsAttributeTableConfig.html#a8a018be39a06e7caa2202adf868daae7) and [`setAttributeTableConfig()`](https://api.qgis.org/api/classQgsVectorLayer.html#ab91616c2e2e296fa97a3ab8bc0a36f7d) methods. Let's assume there is a layer called *'gis_osm_buildings'*, see the image below. [![input][1]][1] To get the original order of fields: <!-- language: pyqgis --> layer = iface.activeLayer() print([layer.attributeDisplayName(index) for index in layer.attributeList()]) that gives: ['osm_id', 'lastchange', 'code', 'fclass', 'geomtype', 'name', 'type', 'height', 'levels'] To set a new order of fields one can achieve with the following function: <!-- language: pyqgis --> from qgis.core import QgsProject def setting_new_columns_order(layer_name: str, new_order: list) -> None: """ Changes order of all columns in the layer Parameters: ========== :param layer_name: name of the layer :param new_order: a list with a new order of columns """ layer = QgsProject.instance().mapLayersByName(layer_name)[0] layer_attr_table_config = layer.attributeTableConfig() columns_config = layer_attr_table_config.columns() columns_new_order_dict = {column : new_order.index(column.name) for column in columns_config if column.type == 0 and column.name in new_order} columns_new_order_list = sorted(columns_new_order_dict, key=columns_new_order_dict.get, reverse=False) layer_attr_table_config.setColumns(columns_new_order_list) layer.setAttributeTableConfig(layer_attr_table_config) return setting_new_columns_order('gis_osm_buildings', ['name', 'type', 'osm_id', 'code', 'fclass', 'height', 'levels', 'lastchange', 'geomtype']) [![result][2]][2] ---------- **References:** - [PyQGIS Developer Cookbook](https://docs.qgis.org/latest/en/docs/pyqgis_developer_cookbook/index.html) [1]: https://i.sstatic.net/RCgr2.png [2]: https://i.sstatic.net/bjqhD.png