Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log IPython history to text file?

After some searching and trawling through the IPython documentation and some code, I can't seem to figure out whether it's possible to store the command history (not the output log) to a text file rather than an SQLite database. ipython --help-all seems to indicate that this option doesn't exist.

This would be very nice for version controlling frequently used commands like in .bash_history.

Edit: Working solution based on @minrk's answer.

like image 576
l0b0 Avatar asked May 31 '13 13:05

l0b0


People also ask

How do I find my IPython history?

In particular, running the command 'history -f FILENAME' from the IPython Notebook interface will replace FILENAME even if it already exists without confirmation. treat the arg as a glob pattern to search for in (full) history. This includes the saved history (almost all commands ever written).

How do I save my IPython session?

In XWindows, run iPython from the Xfce terminal app. click Terminal in the top menu bar and look for save contents in the dropdown.

How do I delete IPython history?

History is store on $(ipython locate)/profile_default/history. sqlite by default. You can remove the file, and or do any operation you want on it (secure erase, etc..). It's an sqlite file so you can load it with any sqlite program and do query on it.

How do I run IPython commands?

If you want some code to be run at the beginning of every IPython session, the easiest way is to add Python (. py) or IPython (. ipy) scripts to your profile_default/startup/ directory. Files here will be executed as soon as the IPython shell is constructed, before any other code or scripts you have specified.


1 Answers

You can export all of your history in IPython to a text file with the %history magic like this:

%history -g -f filename 

One way of getting what you want might be to do that export in a git hook. I usually put these "sync an external resource" actions in the post-checkout git hook.

like image 175
Christian Long Avatar answered Sep 29 '22 04:09

Christian Long