Skip to main content

This module dismantles python code to parse tree, token, symbols and reproduces it to dictionary and string.

Project description

Dismantler

PyPI version Apache 2.0 License PyPI - Python Version Say Thanks

██████╗ ██╗███████╗███╗   ███╗ █████╗ ███╗   ██╗████████╗██╗     ███████╗██████╗ 
██╔══██╗██║██╔════╝████╗ ████║██╔══██╗████╗  ██║╚══██╔══╝██║     ██╔════╝██╔══██╗
██║  ██║██║███████╗██╔████╔██║███████║██╔██╗ ██║   ██║   ██║     █████╗  ██████╔╝
██║  ██║██║╚════██║██║╚██╔╝██║██╔══██║██║╚██╗██║   ██║   ██║     ██╔══╝  ██╔══██╗
██████╔╝██║███████║██║ ╚═╝ ██║██║  ██║██║ ╚████║   ██║   ███████╗███████╗██║  ██║
╚═════╝ ╚═╝╚══════╝╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝   ╚══════╝╚══════╝╚═╝  ╚═╝

This module dismantles python code to parse tree, token, symbols and reproduces it to dictionary and string.

What is this?

Dismantler takes a Python code as input and creates a parse tree in a short time. It also export the parse tree to a dictionary or json. You can get list of tokens or symbols separately if you want. This project can be used for research purpose, such as teaching the source code to deep learning model as tokenized sequential data or interpreting the Python code on token level and using it for educational programs (like tutoring).

Basic Usage

import dismantler

d = dismantler.run_from_string('a + 5').dictionary()
print(d)
{
    "type": "symbol",
    "name": "stmt",
    "value": [
        // Nodes...
    ]
}

d = dismantler.run_from_file('file.py').json(indent=4)
print(d)
"{
    "type": "symbol",
    "name": "stmt",
    "value": [
        // Nodes...
    ]
}"

Installation

Via pip

pip3 install dismantler-python

Via source

git clone http://github.com/harrydrippin/dismantler-python

Contribution

This project is very small now, so contribution to this project is very welcome. Feel free to submit some issues or PRs to this project.

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

dismantler-python-0.0.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

dismantler_python-0.0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file dismantler-python-0.0.2.tar.gz.

File metadata

File hashes

Hashes for dismantler-python-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e9cdd4bf4cd69379587ad342dc84e9ab621c86cc56be2b2a1ce74604eec61790
MD5 06cbdbd136bc3cdf574329732bb10ed6
BLAKE2b-256 22fd4b10aa4abdbbf653a2182c72ab8cd94d3f6c7f052f28ef80a633fe123fd9

See more details on using hashes here.

File details

Details for the file dismantler_python-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for dismantler_python-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 182fa5f9d3d68c8d46ec61d6d50ca4b6c69b4e97a65c9f8e81c6d708f40a042a
MD5 1b1c1f20ad91ef7fea106d5d32ba9264
BLAKE2b-256 b58266195e99e0fdfb341341f153e93ccca5da65ad9ded93815271b9f3868cd3

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