Add a convenient way to visualize an sqlite3.Cursor
in a terminal (and maybe also Jupyter)
#128905
Labels
sqlite3.Cursor
in a terminal (and maybe also Jupyter)
#128905
Feature or enhancement
Proposal:
I think that the
sqlite3
module is a hidden gem in the Python standard library: the functionality it provides is like a mini-Pandas, similar to thearray
module, which is a mini-NumPy. The only problem is that it's more programmatic than interactive, in that it's hard to look at the results of a query without either writing a loop to iterate oversqlite3.Cursor
results or passing the query to Pandas (which instantiates all of the results in memory).This came up in a problem I was working on and I didn't find any standard solutions for visualizing an SQLite query, so I wrote one on StackOverflow. Just it's just complex enough that variants of code like this shouldn't be floating around the web; a single version should be built into the
sqlite3.Cursor
object.I'd like a method that you can use like this:
that prints a table like this:
Here's my sample implementation:
And/or maybe a
head
method that only shows the beginning, rather than both the beginning and end (to avoid iterating over millions of rows). Maybe also a_repr_html_
method for IPython/Jupyter, but that's probably more specific than the standard model should be (only useful in a third-party library, albeit a major one).What do you think? Is this going against the direction you want
sqlite3
to go? (E.g. are you trying to reduce its presence, rather than increase it?) Is the idea sound, but the method names (print
,head
) are bad? Is it a problem that it "eats" the Cursor, and should instead be a method onsqlite3.Connection
that takes aquery: str
?I'm willing to write the PR; I just want to start by checking to see if such a PR would be welcome.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: