Skip to content

Commit d3b2c1b

Browse files
committed
b2view is now installed by default in blosc2 package
1 parent d59e45d commit d3b2c1b

5 files changed

Lines changed: 98 additions & 5 deletions

File tree

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ Conda users can install from conda-forge:
4848
4949
conda install -c conda-forge python-blosc2
5050
51+
Command line tools
52+
==================
53+
54+
Two CLI tools are installed along with the package:
55+
56+
- ``b2view``: an interactive terminal browser (TUI) for TreeStore bundles
57+
(``.b2d`` directories or ``.b2z`` files), with paged views of NDArray and
58+
CTable data of any size
59+
(`walkthrough <https://www.blosc.org/python-blosc2/getting_started/b2view.html>`_).
60+
- ``parquet-to-blosc2``: converts Parquet files to Blosc2 columnar table
61+
stores, and back
62+
(`walkthrough <https://www.blosc.org/python-blosc2/getting_started/parquet_to_blosc2.html>`_;
63+
requires ``pip install "blosc2[parquet]"``).
64+
5165
Documentation
5266
=============
5367

doc/getting_started/b2view.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
b2view: Browse TreeStore Bundles in the Terminal
2+
================================================
3+
4+
The ``b2view`` CLI opens an interactive terminal browser (TUI) for Blosc2
5+
TreeStore bundles, either sparse directories (``.b2d``) or compact
6+
zip-backed files (``.b2z``). It shows the tree of groups and nodes, the
7+
metadata and vlmeta of the selected node, and a paged view of the data
8+
itself — NDArrays of any dimensionality as well as CTables.
9+
10+
``b2view`` is installed with python-blosc2; no extra dependencies are
11+
needed.
12+
13+
Step 1 — Create a sample store
14+
------------------------------
15+
16+
Run the snippet below once to produce ``sample.b2z`` with a couple of
17+
arrays and some metadata:
18+
19+
.. code-block:: python
20+
21+
import blosc2
22+
23+
with blosc2.TreeStore("sample.b2z", mode="w") as tstore:
24+
tstore.vlmeta["author"] = "me"
25+
a = blosc2.linspace(0, 1, num=1_000_000, shape=(1000, 1000))
26+
a.vlmeta["description"] = "a 2-D linspace"
27+
tstore["/dense/a"] = a
28+
tstore["/dense/b"] = blosc2.arange(10_000, shape=(10, 100, 10))
29+
30+
Any existing TreeStore bundle works too — for instance the output of the
31+
``parquet-to-blosc2`` converter (see :doc:`parquet_to_blosc2`).
32+
33+
Step 2 — Open it
34+
----------------
35+
36+
.. code-block:: console
37+
38+
b2view sample.b2z
39+
40+
The screen is split into four panels: the **tree** of the bundle on the
41+
left, and **meta**, **vlmeta** and **data** panels for the node selected
42+
in the tree. Move between panels with ``tab`` / ``shift+tab``, maximize
43+
the focused one with ``m`` (``r`` restores it), and quit with ``q``.
44+
45+
You can also jump straight to a node and panel:
46+
47+
.. code-block:: console
48+
49+
b2view sample.b2z /dense/a --panel data
50+
51+
Step 3 — Navigate the data panel
52+
--------------------------------
53+
54+
The data panel pages through objects far larger than the screen. Press
55+
``?`` at any time for the full key reference; the essentials are:
56+
57+
================================ =============================================
58+
Key Action
59+
================================ =============================================
60+
``up`` / ``down`` move the cursor; pages at the edges
61+
``pageup`` / ``pagedown`` previous / next page of rows
62+
``t`` / ``b`` first / last row
63+
``g`` go to a row number
64+
``left`` / ``right`` move across columns; pages at the edges
65+
``s`` / ``e`` (``home``/``end``) first / last column window
66+
``c`` go to a column index or name
67+
================================ =============================================
68+
69+
For N-D arrays, press ``d`` to enter *dim mode*: ``left`` / ``right``
70+
select the active dimension, ``up`` / ``down`` change its fixed index (or
71+
scroll the viewport), ``enter`` toggles a dimension between fixed and
72+
navigable, and ``escape`` leaves dim mode.
73+
74+
CLI options
75+
-----------
76+
77+
``--preview-rows N`` and ``--preview-cols N`` bound the size of each data
78+
page (20 rows by 10 columns by default), and ``--panel`` chooses the panel
79+
focused on startup (``tree``, ``meta``, ``vlmeta`` or ``data``).

doc/getting_started/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Getting Started
99
tutorials
1010
dsl_syntax
1111
parquet_to_blosc2
12+
b2view

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ dependencies = [
3838
"numexpr>=2.14.1; platform_machine != 'wasm32'",
3939
"pydantic",
4040
"requests",
41+
"rich",
42+
"textual",
4143
"threadpoolctl; platform_machine != 'wasm32'",
4244
]
4345
version = "4.4.4.dev0"
@@ -50,7 +52,6 @@ documentation = "https://www.blosc.org/python-blosc2/python-blosc2.html"
5052

5153
[project.optional-dependencies]
5254
parquet = ["pyarrow"]
53-
tui = ["textual", "rich"]
5455

5556
[project.scripts]
5657
parquet-to-blosc2 = "blosc2.cli.parquet_to_blosc2:main"
@@ -74,7 +75,7 @@ dev = [
7475
]
7576
test = [
7677
"pytest",
77-
# for the b2view Pilot tests (which also need the 'tui' extra)
78+
# for the b2view Pilot tests
7879
"pytest-asyncio",
7980
"psutil; platform_machine != 'wasm32'",
8081
# torch is optional because it is quite large (but will still be used if found)

src/blosc2/b2view/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def main(argv: list[str] | None = None) -> int:
2727
from blosc2.b2view.app import B2ViewApp
2828
except ImportError as exc:
2929
print(
30-
"b2view requires the optional TUI dependencies. Install them with:\n"
31-
"\n"
32-
' pip install "blosc2[tui]"\n',
30+
"b2view could not import its TUI dependencies. Install them with:\n\n pip install textual\n",
3331
file=sys.stderr,
3432
)
3533
print(f"Original import error: {exc}", file=sys.stderr)

0 commit comments

Comments
 (0)