Skip to main content

A python-native fx-alike terminal JSON viewer with JSONPath Integration.

Project description

pyfx

Build Status Documentation Status PyPI version GitHub Pipenv locked Python version GitHub

Inspired by fx, a python implementation of JSON Viewer TUI.

Installation

Use pip

Before using pip, please check your Python version, pyfx requires >= 3.8.

pip install python-fx

Build From Source

Clone the this repo, change directory into the project and run

python setup.py install

Usage

CLI

pyfx comes with a CLI, which you can use to directly open a JSON file.

  • You can use it to open a JSON file
     pyfx JSON_FILE
    
  • You can also use it to open JSON data from a pipe
     cat JSON_FILE | pyfx
    

Import as Module

Import pyfx Simple TUI

You can directly integrate pyfx's TUI into your own project.
One would expect this to be the last step of your CLI application. The method Controller#run_with_data contains a infinite loop MainLoop to render image until exit (press q).

from pyfx import Controller

...
# data is the what you want to render as TUI
# only supports dict, list and primitive variable
Controller().run_with_data(data)

Import pyfx's Native JSON Library and Integrate with Your Own TUI

You can also import pyfx native JSON lib to integrate it into your own urwid TUI, e.g. json_browser.py.

from pyfx.view.json_lib import JSONListBox, JSONListWalker, NodeFactory

...
# create top node from the data (only supports dict, list and primitive variable)
top_node = NodeFactory.create_node("", data, display_key=False)
# create JSONListBox from top node, a urwid ListBox compatible widget (http://urwid.org/reference/widget.html#listbox)
listbox = JSONListBox(JSONListWalker(top_node))
# use listbox in your own TUI 
...

Configuration

pyfx can be configured using YAML, the config file is either passed directly through CLI option or automatically loaded in predefined config folderq.

If pyfx is invoked without -c / --config option, it will search config file in with the following order:

  1. ~/.config/pyfx/config.yml
  2. PYTHON_DIR/site-packages/pyfx/config/config.yml

Predefined Key Mappings

Key mapping is configured with the following configuration schema

keymap:
  mode: string, accepted_options = ["basic" (The default) | "emacs" | "vim"]

Basic Mode

Key Function
q exit pyfx (except in Query Bar)
JSON Browser
up move cursor up one line
down move cursor down one line
enter toggle expansion
. enter query window (used to input JSONPath query)
Query Bar
enter apply JSONPath query and switch to JSON Browser
esc cancel query and restore to state before query

Emacs Mode

To enable, add the following configuration in your config file:

keymap:
  mode: "emacs"
Mapped Keys
Key Function
q exit pyfx (except in Query Bar)
JSON Browser
up / ctrl p move cursor up one line
down / ctrl n move cursor down one line
enter toggle expansion
. / meta x enter query window (used to input JSONPath query)
Query Bar
enter apply JSONPath query and switch to JSON Browser
ctrl g cancel query and restore to state before query

Vim Mode

To enable, add the following configuration in your config file:

keymap:
  mode: "vim"
Mapped Keys
Key Function
q exit pyfx (except in Query Bar)
JSON Browser
up / k move cursor up one line
down / j move cursor down one line
enter toggle expansion
. / : enter query window (used to input JSONPath query)
Query Bar
enter apply JSONPath query and switch to JSON Browser
esc cancel query and restore to state before query

Full Documentation

Please visit Documentation

License

Please visit LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-fx-0.1.0b0.tar.gz (32.6 kB view hashes)

Uploaded Source

Built Distribution

python_fx-0.1.0b0-py3-none-any.whl (41.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page