Species IDs can be read by hovering over a species in the species menu.Species, leader, empire and pop IDs however are defined when the game is created and have to be found with the debugtooltip command.
Most IDs are predefined and can be found on the ID page.