Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clarketm/pprintast
An AST pretty printer for Python 🐍
https://github.com/clarketm/pprintast
ast ppast pprint pprintast python
Last synced: about 2 months ago
JSON representation
An AST pretty printer for Python 🐍
- Host: GitHub
- URL: https://github.com/clarketm/pprintast
- Owner: clarketm
- License: mit
- Created: 2018-12-02T09:02:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-11T03:28:14.000Z (almost 6 years ago)
- Last Synced: 2024-10-30T01:05:20.905Z (2 months ago)
- Topics: ast, ppast, pprint, pprintast, python
- Language: Python
- Homepage: https://pprintast.readthedocs.io/en/latest/
- Size: 83 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [pprintast](https://pprintast.readthedocs.io/en/latest/)
[![PyPi release](https://img.shields.io/pypi/v/pprintast.svg)](https://pypi.org/project/pprintast/)
[![PyPi versions](https://img.shields.io/pypi/pyversions/pprintast.svg)](https://pypi.org/project/pprintast/)
[![Downloads](https://pepy.tech/badge/pprintast)](https://pepy.tech/project/pprintast)
[![Documentation Status](https://readthedocs.org/projects/pprintast/badge/?version=latest)](https://pprintast.readthedocs.io/en/latest/?badge=latest)An AST (abstract syntax tree) pretty printer for Python 🐍.
[Check out the pprintast docs](https://pprintast.readthedocs.io/en/latest/)
## Installation
```bash
$ pip install pprintast
```## Usage
```text
usage: pprintast.py [-h] [-a] [-c cmd] [-m mode] [-t] [-v] [file]
A pretty-printing dump function for the ast module. The code was copied from the ast.dump function
and modified slightly to pretty-print.positional arguments:
file program passed in as fileoptional arguments:
-h, --help show this help message and exit
-a, --attributes include attributes such as line numbers and column offsets
-c cmd, --command cmd program passed in as string
-m mode, --mode mode compilation mode (choices: exec, eval, single) (default: exec)
-t, --terse terse output by disabling field annotations
-v, --version show program's version number and exit```
### Script
Pretty print AST from a **file** using the `pprintast` CLI.
```bash
$ pprintast "./path/to/script.py"
```Pretty print AST from a **string** using the `pprintast` CLI.
```bash
$ pprintast -c "lambda a: a**2"
```### Module
Pretty print AST from a **string** using the `pprintast` module.
```python
# 1. import the "pprintast" function.
from pprintast import pprintast as ppast # OR: from pprintast import ppast# 2. pretty print AST from a "string".
exp = "lambda a: a**2"ppast(exp)
```
![stdout](https://raw.githubusercontent.com/clarketm/pprintast/master/pprintast.png)
## License
MIT © [**Travis Clarke**](https://blog.travismclarke.com/)