dataframe-textual 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dataframe-textual might be problematic. Click here for more details.

@@ -0,0 +1,14 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ *bak
12
+ *.csv
13
+ *.xlsx
14
+ test.py
@@ -0,0 +1 @@
1
+ 3.14
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tiejun Cheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,548 @@
1
+ Metadata-Version: 2.4
2
+ Name: dataframe-textual
3
+ Version: 0.3.1
4
+ Summary: Interactive CSV/Excel viewer for the terminal (Textual TUI)
5
+ Project-URL: Homepage, https://github.com/need47/dataframe-textual
6
+ Project-URL: Repository, https://github.com/need47/dataframe-textual.git
7
+ Project-URL: Documentation, https://github.com/need47/dataframe-textual#readme
8
+ Project-URL: Bug Tracker, https://github.com/need47/dataframe-textual/issues
9
+ Author-email: Tiejun Cheng <need47@gmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: csv,data-analysis,excel,interactive,polars,terminal,textual,tui,viewer
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: End Users/Desktop
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Natural Language :: English
19
+ Classifier: Operating System :: MacOS
20
+ Classifier: Operating System :: POSIX
21
+ Classifier: Operating System :: Unix
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Office/Business
28
+ Classifier: Topic :: Utilities
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.11
31
+ Requires-Dist: polars>=1.34.0
32
+ Requires-Dist: textual>=1.0.0
33
+ Provides-Extra: dev
34
+ Requires-Dist: textual-dev>=1.8.0; extra == 'dev'
35
+ Provides-Extra: excel
36
+ Requires-Dist: fastexcel>=0.16.0; extra == 'excel'
37
+ Requires-Dist: xlsxwriter>=3.2.9; extra == 'excel'
38
+ Description-Content-Type: text/markdown
39
+
40
+ # DataFrame Viewer/Editor
41
+
42
+ A powerful, interactive terminal-based CSV/Excel viewer/editor built with Python, Polars, and Textual. Inspired by VisiData, this tool provides smooth keyboard navigation, data manipulation, and a clean interface for exploring tabular data directly in your terminal. Now with **multi-file support for simultaneous data comparison**!
43
+
44
+ ![Screenshot](https://raw.githubusercontent.com/need47/dataframe-textual/refs/heads/main/screenshot.png)
45
+
46
+ ## Features
47
+
48
+ ### Core Data Viewing
49
+ - 🚀 **Fast CSV Loading** - Powered by Polars for efficient data handling with lazy pagination
50
+ - 🎨 **Rich Terminal UI** - Beautiful, color-coded columns with automatic type detection
51
+ - ⌨️ **Comprehensive Keyboard Navigation** - Intuitive controls for browsing, editing, and manipulating data
52
+ - 📊 **Flexible Input** - Read from files or stdin (pipes/redirects)
53
+ - 🔄 **Smart Pagination** - Lazy load rows on demand for handling large datasets
54
+
55
+ ### Data Manipulation
56
+ - 📝 **Data Editing** - Edit cells, delete rows, and remove columns
57
+ - 🔍 **Search & Filter** - Find values, highlight matches, and filter selected rows
58
+ - ↔️ **Column/Row Reordering** - Move columns and rows with simple keyboard shortcuts
59
+ - 📈 **Sorting & Statistics** - Multi-column sorting and frequency distribution analysis
60
+ - 💾 **Save & Undo** - Save filtered data back to CSV with full undo/redo support
61
+
62
+ ### Advanced Features
63
+ - 📌 **Pin Rows/Columns** - Keep important rows and columns visible while scrolling
64
+ - 🎯 **Cursor Type Cycling** - Switch between cell, row, and column selection modes
65
+ - 📂 **Multi-File Support** - Open multiple CSV files in tabs for side-by-side comparison
66
+ - 🔄 **Tab Management** - Seamlessly switch between open files with keyboard shortcuts
67
+
68
+ ## Installation
69
+
70
+ ### Using pip
71
+
72
+ ```bash
73
+ # Install from PyPI
74
+ pip install dataframe-textual
75
+
76
+ # With Excel support (fastexcel, xlsxwriter)
77
+ pip install dataframe-textual[excel]
78
+ ```
79
+
80
+ Then run:
81
+ ```bash
82
+ dataframe-textual <csv_file>
83
+ ```
84
+
85
+ ### Using uv
86
+
87
+ ```bash
88
+ # Quick run using uvx without installation
89
+ uvx https://github.com/need47/dataframe-textual.git <csvfile>
90
+
91
+ # Clone or download the project
92
+ cd dataframe-textual
93
+
94
+ # Run directly with uv
95
+ uv run python main.py <csv_file>
96
+
97
+ #
98
+ ```
99
+
100
+ ### Development installation
101
+
102
+ ```bash
103
+ # Clone the repository
104
+ git clone https://github.com/need47/dataframe-textual.git
105
+ cd dataframe-textual
106
+
107
+ # Install from local source
108
+ pip install -e .
109
+
110
+ # Or with development dependencies
111
+ pip install -e ".[excel,dev]"
112
+ ```
113
+
114
+ ## Usage
115
+
116
+ ### Basic Usage - Single File
117
+
118
+ ```bash
119
+ # After pip install dataframe-textual
120
+ dataframe-textual pokemon.csv
121
+
122
+ # Or if running from source
123
+ python main.py pokemon.csv
124
+
125
+ # Or with uv
126
+ uv run python main.py pokemon.csv
127
+
128
+ # Read from stdin
129
+ cat data.csv | dataframe-textual
130
+ dataframe-textual < data.csv
131
+ ```
132
+
133
+ ### Multi-File Usage - Multiple Tabs
134
+
135
+ ```bash
136
+ # Open multiple files in tabs
137
+ dataframe-textual file1.csv file2.csv file3.csv
138
+
139
+ # Open multiple sheets in tabs in an Excel file
140
+ dataframe-textual file.xlsx
141
+
142
+ # Mix files and stdin (file opens first, then read from stdin)
143
+ dataframe-textual data1.csv < data2.csv
144
+ ```
145
+
146
+ When multiple files are opened:
147
+ - Each file appears as a separate tab at the top
148
+ - Switch between tabs using `>` (next) or `<` (previous)
149
+ - Open additional files with `Ctrl+O`
150
+ - Close the current tab with `Ctrl+W`
151
+ - Each file maintains its own state (sort order, selections, history, etc.)
152
+ - Edits and filters are independent per file
153
+
154
+ ## Keyboard Shortcuts
155
+
156
+ ### App-Level Controls
157
+
158
+ #### File & Tab Management
159
+
160
+ | Key | Action |
161
+ |-----|--------|
162
+ | `Ctrl+O` | Open new CSV file in a new tab |
163
+ | `Ctrl+W` | Close current tab |
164
+ | `Ctrl+Shift+S` | Save all open tabs to Excel file |
165
+ | `>` or `b` | Move to next tab |
166
+ | `<` | Move to previous tab |
167
+ | `B` | Toggle tab bar visibility |
168
+ | `q` | Quit the application |
169
+
170
+ #### View & Settings
171
+
172
+ | Key | Action |
173
+ |-----|--------|
174
+ | `?` or `h` | Toggle help panel (context-sensitive) |
175
+ | `k` | Cycle through themes |
176
+
177
+ ---
178
+
179
+ ### Table-Level Controls
180
+
181
+ #### Navigation
182
+
183
+ | Key | Action |
184
+ |-----|--------|
185
+ | `g` | Jump to first row |
186
+ | `G` | Jump to last row (loads all remaining rows) |
187
+ | `↑` / `↓` | Move up/down one row |
188
+ | `←` / `→` | Move left/right one column |
189
+ | `PageDown` / `PageUp` | Scroll down/up |
190
+ | Arrow keys | Navigate the table |
191
+
192
+ #### Viewing & Display
193
+
194
+ | Key | Action |
195
+ |-----|--------|
196
+ | `Enter` | View full details of current row in modal |
197
+ | `F` | Show frequency distribution for column |
198
+ | `C` | Cycle cursor type: cell → row → column → cell |
199
+ | `#` | Toggle row labels visibility |
200
+
201
+ #### Data Editing
202
+
203
+ | Key | Action |
204
+ |-----|--------|
205
+ | `e` | Edit current cell (respects data type) |
206
+ | `d` | Delete current row |
207
+ | `-` | Delete current column |
208
+
209
+ #### Searching & Filtering
210
+
211
+ | Key | Action |
212
+ |-----|--------|
213
+ | `\|` (pipe) | Search in current column (case-insensitive) |
214
+ | `/` (slash) | Global search across all columns |
215
+ | `\` | Search current column using cell value |
216
+ | `s` | Select/deselect current row |
217
+ | `t` | Toggle highlighting of all selected rows (invert) |
218
+ | `T` | Clear all selected rows |
219
+ | `"` (quote) | Filter to show only selected rows |
220
+ | `v` | Filter by selected rows (if any) or current cell value |
221
+ | `V` | Filter by expression (Polars expression syntax) |
222
+
223
+ #### Sorting
224
+
225
+ | Key | Action |
226
+ |-----|--------|
227
+ | `[` | Sort current column ascending |
228
+ | `]` | Sort current column descending |
229
+
230
+ #### Reordering
231
+
232
+ | Key | Action |
233
+ |-----|--------|
234
+ | `Shift+↑` | Move current row up |
235
+ | `Shift+↓` | Move current row down |
236
+ | `Shift+←` | Move current column left |
237
+ | `Shift+→` | Move current column right |
238
+
239
+ #### Data Management
240
+
241
+ | Key | Action |
242
+ |-----|--------|
243
+ | `f` | Freeze rows and columns |
244
+ | `c` | Copy current cell to clipboard |
245
+ | `Ctrl+S` | Save current tab to CSV/TSV file |
246
+ | `u` | Undo last action |
247
+ | `U` | Reset to original data |
248
+
249
+ #### Modal Interactions
250
+
251
+ **In Frequency Distribution Modal** (opened with `F`):
252
+ - `[` / `]` - Sort frequency table
253
+ - `v` - Filter main table to selected value
254
+ - `"` - Highlight rows with selected value
255
+ - `q` / `Escape` - Close modal
256
+
257
+ **In Row Detail Modal** (opened with `Enter`):
258
+ - `v` - Filter main table to selected column value
259
+ - `"` - Highlight rows with selected column value
260
+ - `q` / `Escape` - Close modal
261
+
262
+ **Tip**: Press `?` or `h` to open the context-sensitive help panel which displays all available shortcuts based on your current focus.
263
+
264
+ ## Features in Detail
265
+
266
+ ### 1. Color-Coded Data Types
267
+
268
+ Columns are automatically styled based on their data type:
269
+ - **Int64** (Integers): Cyan text, right-aligned
270
+ - **Float64** (Decimals): Magenta text, right-aligned
271
+ - **String**: Green text, left-aligned
272
+ - **Boolean**: Blue text, centered
273
+ - **Date/Datetime**: Blue text, centered
274
+
275
+ ### 2. Row Detail View
276
+
277
+ Press `Enter` on any row to open a modal showing all column values for that row. Useful for examining wide datasets where columns don't fit on screen.
278
+
279
+ **In the Row Detail Modal**:
280
+ - Press `v` to **filter** the main table to show only rows with the selected column value
281
+ - Press `"` to **highlight** all rows containing the selected column value
282
+ - Press `q` or `Escape` to close the modal
283
+
284
+ ### 3. Search & Filtering
285
+
286
+ **Column Search** (`|`):
287
+ - Search for values in the current column
288
+ - Case-insensitive substring matching
289
+ - All matching rows are highlighted in red
290
+ - Multiple searches accumulate selections
291
+
292
+ **Global Search** (`/`):
293
+ - Search for a term across all columns simultaneously
294
+ - Cell-level highlighting in red for each matching cell
295
+ - Useful for finding a value anywhere in the dataset
296
+ - Automatically loads rows if matches extend beyond visible area
297
+ - Type-aware matching: converts values to strings before comparing
298
+
299
+ **Cell-Value Search** (`\`):
300
+ - Automatically search using the current cell's value
301
+ - Quick way to find all occurrences of a value
302
+
303
+ **Row Filtering** (`"`):
304
+ - Display only the selected (highlighted) rows
305
+ - Other rows are hidden but preserved
306
+ - Use undo (`u`) to restore
307
+
308
+ ### 4. Filter by Expression
309
+
310
+ Press `f` to open a powerful filter expression dialog. This allows you to write complex filter conditions using a special syntax:
311
+
312
+ **Column References:**
313
+ - `$_` - Current column (based on cursor position)
314
+ - `$1`, `$2`, etc. - Column by 1-based index
315
+ - `$age`, `$salary` - Column by name
316
+
317
+ **Operators:**
318
+ - Comparison: `==`, `!=`, `<`, `>`, `<=`, `>=`
319
+ - Logical: `&&` (AND), `||` (OR)
320
+ - Arithmetic: `+`, `-`, `*`, `/`, `%`
321
+
322
+ **Examples:**
323
+ - `$_ > 50` - Current column greater than 50
324
+ - `$salary >= 100000` - Salary at least 100,000
325
+ - `$age < 30 && $status == 'active'` - Age less than 30 AND status is active
326
+ - `$name == 'Alice' || $name == 'Bob'` - Name is Alice or Bob
327
+ - `$salary / 1000 >= 50` - Salary divided by 1,000 is at least 50
328
+
329
+ See [FILTER_EXPRESSION_GUIDE.md](FILTER_EXPRESSION_GUIDE.md) for comprehensive syntax documentation.
330
+
331
+ ### 5. Sorting
332
+
333
+ - Press `[` to sort current column ascending
334
+ - Press `]` to sort current column descending
335
+ - Multi-column sorting supported (press multiple times on different columns)
336
+ - Press same key twice to toggle direction
337
+ - Frequency view (`F`) shows value distribution with optional sorting
338
+
339
+ ### 6. Frequency Distribution
340
+
341
+ Press `F` to see how many times each value appears in the current column. The modal shows:
342
+ - Value
343
+ - Count
344
+ - Percentage of total
345
+ - **Total row** at the bottom
346
+
347
+ **In the Frequency Table**:
348
+ - Press `[` and `]` to sort by any column (value, count, or percentage)
349
+ - Press `v` to **filter** the main table to show only rows with the selected value
350
+ - Press `"` to **highlight** all rows containing the selected value
351
+ - Press `q` or `Escape` to close the frequency table
352
+
353
+ This is useful for:
354
+ - Understanding value distributions
355
+ - Quickly filtering to specific values
356
+ - Identifying rare or common values
357
+ - Finding the most/least frequent entries
358
+
359
+ ### 7. Data Editing
360
+
361
+ **Edit Cell** (`e`):
362
+ - Opens modal for editing current cell
363
+ - Validates input based on column data type
364
+ - Shows column name and type
365
+ - Integer, number, and text inputs available
366
+
367
+ **Delete Row** (`d`):
368
+ - Delete single row at cursor
369
+ - Or delete all selected rows at once
370
+ - Deleted rows are marked internally but kept for undo
371
+
372
+ **Delete Column** (`-`):
373
+ - Removes the entire column from view and dataframe
374
+ - Cannot be undone directly (use undo feature)
375
+
376
+ ### 8. Column & Row Reordering
377
+
378
+ **Move Columns**: `Shift+←` and `Shift+→`
379
+ - Swaps adjacent columns
380
+ - Reorder is preserved when saving
381
+
382
+ **Move Rows**: `Shift+↑` and `Shift+↓`
383
+ - Swaps adjacent rows
384
+ - Visual reordering without affecting data
385
+
386
+ ### 9. Pin Rows and Columns
387
+
388
+ Press `f` to open the pin dialog:
389
+ - Enter number of fixed rows: keeps top rows visible while scrolling
390
+ - Enter two numbers: `<rows> <columns>` (space-separated)
391
+ - Example: `2 3` pins top 2 rows and left 3 columns
392
+
393
+ ### 10. Save to CSV
394
+
395
+ Press `Ctrl+S` to save:
396
+ - Save filtered, edited, or sorted data back to CSV
397
+ - Choose filename in modal dialog
398
+ - Confirm if file already exists
399
+ - Automatic .tsv or .csv detection
400
+
401
+ ### 11. Undo/Redo
402
+
403
+ Press `u` to undo:
404
+ - Reverts last action with full state restoration
405
+ - Works for edits, deletions, sorts, searches, etc.
406
+ - Shows description of reverted action
407
+
408
+ ### 12. Cursor Type Cycling
409
+
410
+ Press `C` to cycle through selection modes:
411
+ 1. **Cell mode**: Highlight individual cell (and its row/column headers)
412
+ 2. **Row mode**: Highlight entire row
413
+ 3. **Column mode**: Highlight entire column
414
+
415
+ Visual feedback shows which mode is active.
416
+
417
+ ### 13. Clipboard Operations
418
+
419
+ Press `c` to copy:
420
+ - Copies current cell value to system clipboard
421
+ - Works on macOS (`pbcopy`) and Linux (`xclip`)
422
+ - Shows confirmation notification
423
+
424
+ ## Data Type Support
425
+
426
+ - **Int64, Int32, UInt32**: Integer values
427
+ - **Float64, Float32**: Decimal numbers (shown with 4 significant figures)
428
+ - **String**: Text data
429
+ - **Boolean**: True/False values
430
+ - **Date**: ISO date format (YYYY-MM-DD)
431
+ - **Datetime**: ISO datetime format
432
+ - **Null values**: Displayed as `-`
433
+
434
+ ## Examples
435
+
436
+ ### Single File Examples
437
+
438
+ ```bash
439
+ # View Pokemon dataset
440
+ dataframe-textual pokemon.csv
441
+
442
+ # View Titanic dataset with analysis
443
+ dataframe-textual titanic.csv
444
+
445
+ # Filter and view specific columns
446
+ cut -d',' -f1,2,3 pokemon.csv | dataframe-textual
447
+
448
+ # View with grep filter (then use | search in viewer)
449
+ grep "Fire" pokemon.csv | dataframe-textual
450
+
451
+ # Chain with other commands
452
+ cat data.csv | sort -t',' -k2 | dataframe-textual
453
+ ```
454
+
455
+ ### Multi-File Examples
456
+
457
+ ```bash
458
+ # Compare two versions of a dataset
459
+ dataframe-textual pokemon_v1.csv pokemon_v2.csv
460
+
461
+ # Side-by-side analysis of related files
462
+ dataframe-textual sales_2022.csv sales_2023.csv forecast_2024.csv
463
+
464
+ # Cross-reference datasets
465
+ dataframe-textual customers.csv orders.csv products.csv
466
+
467
+ # Start with one file, open others using Ctrl+O
468
+ dataframe-textual initial_data.csv
469
+ # Then press Ctrl+O to open more files interactively
470
+ ```
471
+
472
+ ### Advanced Workflows
473
+
474
+ ```bash
475
+ # Start with a filtered file, compare with original
476
+ grep "status=active" data.csv > filtered.csv
477
+ dataframe-textual data.csv filtered.csv
478
+ # Now compare the full dataset with the filtered version in separate tabs
479
+
480
+ # Multi-step analysis
481
+ # 1. Open multiple related CSVs
482
+ # 2. Use Ctrl+O to open additional files as you discover relationships
483
+ # 3. Each tab maintains independent sort/filter/search state
484
+ # 4. Use Ctrl+W to close tabs when done analyzing
485
+ ```
486
+
487
+ ## Performance
488
+
489
+ - **Lazy loading**: Only loads visible rows + 10 rows ahead
490
+ - **Efficient sorting**: Uses Polars' optimized sort algorithms
491
+ - **Smooth scrolling**: No lag when paging through large files
492
+ - **Memory efficient**: Handles datasets larger than RAM
493
+
494
+ Tested with:
495
+ - 10,000+ row CSV files
496
+ - Wide datasets (100+ columns)
497
+ - Various data types and sizes
498
+
499
+ ## Dependencies
500
+
501
+ - **polars**: Fast DataFrame library for CSV processing
502
+ - **textual**: Terminal UI framework
503
+ - **rich**: Rich text and formatting in the terminal
504
+
505
+ ## Architecture Overview
506
+
507
+ ### Single-Table Design
508
+
509
+ The core of the application is built around the `DataFrameTable` widget:
510
+
511
+ - **Self-contained**: Each table instance maintains its own complete state (13 independent variables)
512
+ - **Fully autonomous**: All operations (editing, sorting, filtering, searching) are handled within the table
513
+ - **Event-driven**: Each table owns and handles its keyboard events
514
+ - **Backward compatible**: Works identically in single-file mode
515
+
516
+ ### Multi-Table Design
517
+
518
+ The `DataFrameApp` coordinates multiple independent `DataFrameTable` instances:
519
+
520
+ - **Tab-based interface**: Uses Textual's `TabbedContent` for tab management
521
+ - **Independent state**: Each tab has completely separate state (sort order, selections, history)
522
+ - **Seamless switching**: Switch between files without losing context or state
523
+ - **File management**: Open/close files dynamically without restarting the application
524
+
525
+ ### State Isolation
526
+
527
+ Each `DataFrameTable` instance owns:
528
+ - DataFrame (`self.df`)
529
+ - Sorted columns (`self.sorted_columns`)
530
+ - Selected rows (`self.selected_rows`)
531
+ - Edit history (`self.histories`)
532
+ - Cursor state (position, type)
533
+ - Search/filter state
534
+ - And 8 more internal state variables
535
+
536
+ This ensures perfect isolation between tabs with zero cross-contamination.
537
+
538
+ ## Requirements
539
+
540
+ - Python 3.11+
541
+ - POSIX-compatible terminal (macOS, Linux, WSL)
542
+ - Terminal supporting ANSI escape sequences and mouse events
543
+
544
+ ## Acknowledgments
545
+
546
+ - Inspired by [VisiData](https://visidata.org/)
547
+ - Built with [Textual](https://textual.textualize.io/), [Polars](https://www.pola.rs/), and [Rich](https://rich.readthedocs.io/)
548
+ - All code created through iterative development