Pyfx
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.9
- pip
Installation
Pip
pip install python-fx
Build from Source
Clone the this repo, change directory into the project and run
pip install -U autopep8 tox build
make install
Local Development
- Download and install the latest ANTLR v4
- It is required that ANTLR version installed matches the version of the Python ANTLR runtime version.
- Clone the this repo, change directory into the project and run
pip install -U pipenv
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 = [1]
# data is the JSON data to be rendered in the TUI
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
data = [1]
# 1. create JSONListBox from data
listbox = JSONListBox(JSONListWalker(data))
# 2. 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.
The predefined folders are searched in following order, with the first exist one has high priority.~/.config/pyfx/config.ymlsrc/pyfx/config/yaml/config.ymldefault config
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 | ||
| autocomplete_popup | autocomplete popup | black |
| autocomplete_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 |
Known Limitation
When open with very large JSON files, Pyfx will freeze on JSONPath query.
The following statistics is tested at a MacBook Air (1.1GHz Quad-Core Intel Core i5 and 8GB RAM).
| File Size | Functionality | Usability |
|---|---|---|
| 57MB | Display JSON | Fairly good |
| ^^ | Query Autocomplete | Latency <= 200ms |
| ^^ | Query JSONPath | Roughly 1~2s latency |
| 570MB | Display JSON | Slow loading |
| ^^ | Query Autocomplete | Latency <= 200ms. Give up with large data |
| ^^ | Query JSONPath | UI may freeze depend on the search space |
License
The code is under The MIT License.
Changelog
See the changelog for a history of notable changes to Pyfx.
Contributors
Avery (@nullableVoidPtr)
Zephyr Lykos (@mochaaP)
@jcaesar
How to Contribute
If you run into any issues, please let me know by creating a GitHub issue.
Metadata
Release files for python-fx 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_fx-0.4.0.tar.gz | 1.3 MB | Without provenance | Details for python_fx-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_fx-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for python_fx-0.4.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / python_fx-0.4.0.tar.gz
| Download URL | python_fx-0.4.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5d8e7c405f71475b652528a21fce8b82472802bd8e3a642b05be5518f3e2c8e
|
|
BLAKE2b-256 checksum How to use checksums |
a053abb55cef4f1355a38e6460f3f1c68b30815defb3ee78915b1e27cb093bce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / python_fx-0.4.0-py3-none-any.whl
| Download URL | python_fx-0.4.0-py3-none-any.whl |
|---|---|
| Size | 76.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31d8c22ea12ba5a15435be046089fcd3ed0ef994a0fb2b8f970fe466a4b6883f
|
|
BLAKE2b-256 checksum How to use checksums |
5869719df19e8e6ffe9fa379560ab28a827f62765c1a56ce49704030cf95b76f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Security for python-fx 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.