ast2json


Nameast2json JSON
Version 0.3 PyPI version JSON
download
home_pagehttps://github.com/Psycojoker/ast2json
Summaryconvert a python source code into json-dumpable data (dict and lists with strings, ints, ...)
upload_time2022-04-25 02:15:22
maintainer
docs_urlNone
authorLaurent Peuch
requires_python
licenseBSD
keywords ast
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Introduction
============

ast2json is a small module that will convert any python AST node into its ast
representation formated in a JSON compatible python representation (list and
dicts containing string, ints and null).

Installation
============

::

    pip install ast2json
    # or to have lastest version
    pip install git+git://github.com/Psycojoker/ast2json.git

Usage
=====

::

    >>> import json
    >>> from ast import parse
    >>> from ast2json import ast2json

    >>> ast = ast2json(parse(open('some_python_source_file.py').read()))
    >>> print json.dumps(ast, indent=4)

If you are lazy, "str2json" will apply the "parse" method of ast on a string for you, so you'll be able to write:

::

    >>> str2json(open('some_python_source_file.py').read())

Example
=======

This is the result of converting 'print "Hello World!"' (and applying json.dumps on the result).

::

    {
        "body": [
            {
                "_type": "Print", 
                "nl": true, 
                "col_offset": 0, 
                "dest": null, 
                "values": [
                    {
                        "s": "Hello World!", 
                        "_type": "Str", 
                        "lineno": 1, 
                        "col_offset": 6
                    }
                ], 
                "lineno": 1
            }
        ], 
        "_type": "Module"
    }


Changelog
=========

0.3 (2022-04-25)
----------------

* add support for elipsis

0.2.1 (2016-11-13)
------------------

* fix broken pip installation by @abolger

0.2 (2016-09-03)
----------------

* python 3 support and some unit testing by Juncheol Cho @zironycho

Licence
=======

BSD



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Psycojoker/ast2json",
    "name": "ast2json",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ast",
    "author": "Laurent Peuch",
    "author_email": "cortex@worlddomination.be",
    "download_url": "https://files.pythonhosted.org/packages/55/ee/af6be7bd7553cd6f9ca4bb7cef95986805ab8e5529e1692bae27bbe97457/ast2json-0.3.tar.gz",
    "platform": null,
    "description": "Introduction\n============\n\nast2json is a small module that will convert any python AST node into its ast\nrepresentation formated in a JSON compatible python representation (list and\ndicts containing string, ints and null).\n\nInstallation\n============\n\n::\n\n    pip install ast2json\n    # or to have lastest version\n    pip install git+git://github.com/Psycojoker/ast2json.git\n\nUsage\n=====\n\n::\n\n    >>> import json\n    >>> from ast import parse\n    >>> from ast2json import ast2json\n\n    >>> ast = ast2json(parse(open('some_python_source_file.py').read()))\n    >>> print json.dumps(ast, indent=4)\n\nIf you are lazy, \"str2json\" will apply the \"parse\" method of ast on a string for you, so you'll be able to write:\n\n::\n\n    >>> str2json(open('some_python_source_file.py').read())\n\nExample\n=======\n\nThis is the result of converting 'print \"Hello World!\"' (and applying json.dumps on the result).\n\n::\n\n    {\n        \"body\": [\n            {\n                \"_type\": \"Print\", \n                \"nl\": true, \n                \"col_offset\": 0, \n                \"dest\": null, \n                \"values\": [\n                    {\n                        \"s\": \"Hello World!\", \n                        \"_type\": \"Str\", \n                        \"lineno\": 1, \n                        \"col_offset\": 6\n                    }\n                ], \n                \"lineno\": 1\n            }\n        ], \n        \"_type\": \"Module\"\n    }\n\n\nChangelog\n=========\n\n0.3 (2022-04-25)\n----------------\n\n* add support for elipsis\n\n0.2.1 (2016-11-13)\n------------------\n\n* fix broken pip installation by @abolger\n\n0.2 (2016-09-03)\n----------------\n\n* python 3 support and some unit testing by Juncheol Cho @zironycho\n\nLicence\n=======\n\nBSD\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "convert a python source code into json-dumpable data (dict and lists with strings, ints, ...)",
    "version": "0.3",
    "split_keywords": [
        "ast"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "acf5f8d37afe696d73bfb407de28e998592c4b72fe76f59ec71719d531e46a60",
                "md5": "4f4b7cb374ef587325ba6e33d862a5a0",
                "sha256": "7f0f0cbb59abce2086c81c8949ac0e2b9a4ed09bf291e417cd21d86535118847"
            },
            "downloads": -1,
            "filename": "ast2json-0.3-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f4b7cb374ef587325ba6e33d862a5a0",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4988,
            "upload_time": "2022-04-25T02:15:20",
            "upload_time_iso_8601": "2022-04-25T02:15:20.849750Z",
            "url": "https://files.pythonhosted.org/packages/ac/f5/f8d37afe696d73bfb407de28e998592c4b72fe76f59ec71719d531e46a60/ast2json-0.3-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55eeaf6be7bd7553cd6f9ca4bb7cef95986805ab8e5529e1692bae27bbe97457",
                "md5": "5302721193faafe6750924383e8530cf",
                "sha256": "fd40a7d911df8de97eb5976783bf16765fcbe6ce9393fb92aa833283fb5f8ee3"
            },
            "downloads": -1,
            "filename": "ast2json-0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "5302721193faafe6750924383e8530cf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4369,
            "upload_time": "2022-04-25T02:15:22",
            "upload_time_iso_8601": "2022-04-25T02:15:22.588641Z",
            "url": "https://files.pythonhosted.org/packages/55/ee/af6be7bd7553cd6f9ca4bb7cef95986805ab8e5529e1692bae27bbe97457/ast2json-0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-04-25 02:15:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Psycojoker",
    "github_project": "ast2json",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "ast2json"
}
        
Elapsed time: 0.11335s