Skip to main content

A python-native fx-alike terminal JSON viewer.

Project description

Pyfx

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

A python-native JSON Viewer TUI, inspired by fx.
Pyfx supports:

  • Read JSON files in terminal from several sources (file, pipe or clipboard).
  • Query JSON files using JSONPath query.

Table of Content

Prerequisites

  • OS: MacOS / Linux
  • python: >= 3.8
  • pip

Installation

Pip

pip install python-fx

Build from Source

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

python setup.py install

Local Development

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

pipenv install --dev

Quick Start

You can use Pyfx in two ways:

  • A standalone CLI tool
  • A python module which can be integrated in any python CLI application

For details, please check the hosted documentation.

CLI

Check Key Bindings section for default key bindings.
Pyfx comes with a CLI, use it

  • To open a JSON file
     pyfx JSON_FILE
    
  • To read JSON data from pipe
     cat JSON_FILE | pyfx
    
  • To read JSON data from clipboard
     pyfx -x / --from-clipboard
    

Python Module

Check Key Bindings section for default key bindings.

Directly Attach Pyfx Simple TUI

Directly integrate Pyfx's TUI into your own project.

from pyfx import PyfxApp

# data is the JSON data to be rendered in the TUI
# only supports dict, list and primitive variable
PyfxApp(data=data).run()

Integrate with Your Own Urwid-based TUI

Integrate Pyfx native JSON widgets into your own urwid-based TUI.

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

# 1. create NodeFactory
node_factory = NodeFactory(DEFAULT_NODE_IMPLS)

# 2. add any custom display implementation
node_factory.register({
    clazz: json_node_impl
})

# 3. create top node from the data (only supports dict, list and primitive variable)
top_node = node_factory.create_root_node(data)

# 4. create JSONListBox from top node
listbox = JSONListBox(JSONListWalker(top_node))

# 5. use listbox in your own TUI

Configuration

Pyfx is configured using YAML. There are two ways to provide a configuration file:

  • Pass directly through CLI option (-c | --config).
  • Create a config file in predefined folders and Pyfx will load it with best effort and use the default config if none is find.
    The predefined folders are searched in following order, with the first exist one has high priority.
    1. ~/.config/pyfx/config.yml

For available configuration, see configuration.

Default Configuration

Theme

Alternative key bindings, see Theme Configuration.

Name Description Foreground Color
body Pyfx body (JSON Browser) terminal default
foot Pyfx footer (Query Bar and Help Bar) gray
focused focused display gray
Auto Complete PopUp
popup autocomplete popup black
popup_focused focused display for autocomplete popup white
JSON Browser
json_key object key blue
json_string string type value green
json_integer integer type value cyan
json_numeric numeric type value cyan
json_bool boolean type value yellow
json_null null type value red
json_focused focused display for JSON gray

Key Bindings

Alternative key bindings, see Key Bindings Configuration.

Key Function
q exit pyfx (except in Query Bar)
? open help page (except in Query Bar)
JSON Browser
up move cursor up one line
down move cursor down one line
e expand all
c collapse all
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
Autocomplete PopUp
up move cursor up one line
down move cursor down one line
enter select option and complete the query
esc close pop up
Help PopUp
up move cursor up one line
down move cursor down one line
esc close the help popup

License

The code is under The MIT License.

Changelog

See the changelog for a history of notable changes to Pyfx.

How to Contribute

If you run into any issues, please let me know by creating a GitHub issue.

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.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_fx-0.1.0-py3-none-any.whl (64.1 kB view details)

Uploaded Python 3

File details

Details for the file python-fx-0.1.0.tar.gz.

File metadata

  • Download URL: python-fx-0.1.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for python-fx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 861118cd69eaca8803d01352fc3e861f17073f57961aa682ac2875321de34f07
MD5 2444716ed5e75ebaac6766c110c0a4ef
BLAKE2b-256 4403ab20e4d079830270b460a6219c07912fe5a723ac0d55516bc318eb0a3283

See more details on using hashes here.

File details

Details for the file python_fx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_fx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 64.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for python_fx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71dfb04921abbb1656f79cbab64f403cf382da8874e8a1ef1248f08905ed29bd
MD5 a26e5d835631e9a41933a188a2d2653e
BLAKE2b-256 bd44290c23d51749ab36f63a4b10470aaa23ea52c5d7b3ae8f76ef33e7ea36da

See more details on using hashes here.

Supported by

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