Note
This documentation is for a development version of IPython. There may be significant differences from the latest stable release (1.2.1).
History related magics and functionality
Bases: object
Dummy DB that will act as a black hole for history.
Only used in the absence of sqlite
Bases: sqlite3.Error
Bases: IPython.config.configurable.Configurable
Access the history database without adding to it.
This is intended for use by standalone history tools. IPython shells use HistoryManager, below, which is a subclass of this.
Create a new history accessor.
Parameters: | profile : str
hist_file : str
config :
|
---|
Get the last session ID currently in the database.
Within IPython, this should be the same as the value stored in HistoryManager.session_number.
Retrieve input by session.
Parameters: | session : int
start : int
stop : int
raw : bool
output : bool
|
---|---|
Returns: | An iterator over the desired lines. Each line is a 3-tuple, either (session, line, input) if output is False, or (session, line, (input, output)) if output is True. |
Get lines of history from a string of ranges, as used by magic commands %hist, %save, %macro, etc.
Parameters: | rangestr : str
raw, output : bool
|
---|---|
Returns: | Tuples as get_range() |
get info about a session
Parameters: | session : int
|
---|---|
Returns: | session_id : int
|
Get the last n lines from the history database.
Parameters: | n : int
raw, output : bool
include_latest : bool
|
---|---|
Returns: | Tuples as get_range() |
Connect to the database, and create tables if necessary.
Search the database using unix glob-style matching (wildcards * and ?).
Parameters: | pattern : str
search_raw : bool
raw, output : bool
n : None or int
unique : bool
|
---|---|
Returns: | Tuples as get_range() |
Overridden by HistoryManager to dump the cache before certain database lookups.
Bases: IPython.core.history.HistoryAccessor
A class to organize all history-related functionality in one place.
Create a new history manager associated with a shell instance.
Close the database session, filling in the end time and line count.
Retrieve input by session.
Parameters: | session : int
start : int
stop : int
raw : bool
output : bool
|
---|---|
Returns: | An iterator over the desired lines. Each line is a 3-tuple, either (session, line, input) if output is False, or (session, line, (input, output)) if output is True. |
get info about a session
Parameters: | session : int
|
---|---|
Returns: | session_id : int
|
Give the current session a name in the history database.
Get a new session number.
Clear the session history, releasing all object references, and optionally open a new session.
Store source and raw input in history and create input cache variables _i*.
Parameters: | line_num : int
source : str
source_raw : str, optional
|
---|
If database output logging is enabled, this saves all the outputs from the indicated prompt number to the database. It’s called by run_cell after code has been executed.
Parameters: | line_num : int
|
---|
Write any entries in the cache to the database.
Bases: threading.Thread
This thread takes care of writing history to the database, so that the UI isn’t held up while that happens.
It waits for the HistoryManager’s save_flag to be set, then writes out the history cache. The main thread is responsible for setting the flag when the cache size reaches a defined threshold.
This can be called from the main thread to safely stop this thread.
Note that it does not attempt to write out remaining history before exiting. That should be done by calling the HistoryManager’s end_session method.
return an empty list in the absence of sqlite
A decorator which wraps HistoryAccessor method calls to catch errors from a corrupt SQLite database, move the old database out of the way, and create a new one.
Turn a string of history ranges into 3-tuples of (session, start, stop).
Examples
list(extract_input_ranges(“~8/5-~7/4 2”)) [(-8, 5, None), (-7, 1, 4), (0, 2, 3)]