-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Add a convenient way to visualize an sqlite3.Cursor
in a terminal (and maybe also Jupyter)
#128905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did you try the |
Hi @jpivarski, This is an interesting proposal! Visualizing sqlite3.Cursor directly in the terminal would definitely improve the user experience when working with SQLite queries, especially for those who prefer not to use additional libraries like Pandas. A couple of thoughts: Usability: I believe the proposed print() method would be helpful, especially for quick debugging or exploration of data without needing to load everything into memory. A head() method could also be a nice addition to avoid iterating through large datasets unnecessarily. Alternative Approach: As you mentioned, since this “eats” the cursor, it might be worth considering whether the method could be implemented on sqlite3.Connection instead. This would allow users to keep their Cursor intact while still benefiting from the functionality, especially if they want to continue processing the query results programmatically. Jupyter Integration: The potential integration with Jupyter/IPython would be awesome. A repr_html method for rendering the results in a more interactive format would align well with the existing functionality in those environments. |
I don't think we should add such debug methods to the |
Closing this as not planned, since we won't be adding such functionality to |
Uh oh!
There was an error while loading. Please reload this page.
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: