Creating Virtual Layer programmatically in QGIS

For QGIS 3, instead use QgsProject:

from qgis.core import QgsVectorLayer, QgsProject
vlayer = QgsVectorLayer( "?query=SELECT * FROM road WHERE type = 'Expressway'", "vlayer", "virtual" )
QgsProject.instance().addMapLayer(vlayer)

You could use something like the following:

from qgis.core import QgsVectorLayer, QgsMapLayerRegistry

vlayer = QgsVectorLayer( "?query=SELECT * FROM road WHERE type = 'Expressway'", "vlayer", "virtual" )
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

You can find examples on how to use virtual layers through python from the author's GitHub:

https://github.com/mhugo/qgis_vlayers/blob/master/README.md