Skip to main content

A AST pretty printer for python.

Project description

pprintast

PyPi release

An AST (abstract syntax tree) pretty printer for Python 🐍.

Installation

$ pip install pprintast

Usage

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(s) passed in as file

optional 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.

$ pprintast "./path/to/script.py"

Pretty print AST from a string using the pprintast CLI.

$ pprintast -c "lambda a: a**2"

Module

Pretty print AST from a string using the pprintast module.

# 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

License

MIT © Travis Clarke

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

pprintast-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pprintast-1.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pprintast-1.0.0.tar.gz.

File metadata

  • Download URL: pprintast-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pprintast-1.0.0.tar.gz
Algorithm Hash digest
SHA256 16df79b27b158a5b474192ddd9f0cd967ff1c2501b3f39dd5e848e0fe5ac0c4f
MD5 5d373c8cd5ee5871e6fb61b9deebab33
BLAKE2b-256 201abc3f1a7a762a1ad9e8bf88b8098555a43bc502941d6aa5ad7f0de6296da8

See more details on using hashes here.

File details

Details for the file pprintast-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pprintast-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pprintast-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8e81fcd98d315c855603c255b57026abf30064a12d3b07e04c2699ab800e013
MD5 88984689ef7d9600b27cb2fa0db275bd
BLAKE2b-256 6a7eeb98cee10a08b59df82c089905a27ae7302ede8f9e1d17f750f32d3a8163

See more details on using hashes here.

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