In Ruby there is a gem called interactive_editor which allows entering a vim session when entering vi in Ruby interpreter.
Literally we need to require interactive_editor.rb in ~/.irbrc file, like this:
require '~/interactive_editor.rb'
And we are done. When we do vi in interactive session; vim is launched. As soon as we quit the editor, the code inside the vim session is executed. Here is more information about running vim within irb.
So, is there any equivalent to that in Python?