🌐
PyPI
pypi.org › project › esprima
esprima · PyPI
Tags esprima , ecmascript , javascript , parser , ast ... Download the file for your platform.
      » pip install esprima
    
Published   Aug 24, 2018
Version   4.0.1
🌐
GitHub
github.com › Kronuz › esprima-python
GitHub - Kronuz/esprima-python: ECMAScript parsing infrastructure for multipurpose analysis · GitHub
Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser officially written in ECMAScript (also popularly known as JavaScript) and ported to Python.
Starred by 266 users
Forked by 47 users
Languages   Python
🌐
PyPI
pypi.org › project › pyesprima
pyesprima · PyPI
July 1, 2013 - Pretty much the same as Esprima’s / SpiderMonkey’s API: >>> import pyesprima >>> print pyesprima.tokenize("1 + 1") [{'type': 'Numeric', 'value': '1'}, {'type': 'Punctuator', 'value': '+'}, {'type': 'Numeric', 'value': '1'}] >>> pyesprima.parse("1 + 1", loc=True) {'body': [{'type': 'ExpressionStatement', 'expression': {'operator': '+', 'loc': {'start': {'column': 0, 'line': 1}, 'end': ... ... Download the file for your platform.
      » pip install pyesprima
    
Published   Jul 02, 2013
Version   1.0.0
🌐
Anaconda.org
anaconda.org › conda-forge › esprima-python
esprima-python - Conda
Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser officially written in ECMAScript (also popularly known as JavaScript) and ported to Python.
🌐
Arch Linux
aur.archlinux.org › packages › python-esprima
AUR (en) - python-esprima - Arch Linux
Download snapshot · Search wiki · python · python-setuptools (make) psychopy · https://github.com/Kronuz/esprima-python/archive/v4.0.1.tar.gz · aurweb v6.2.18 · Report issues here. Copyright © 2004-2025 aurweb Development Team. AUR packages are user produced content.
🌐
GitHub
github.com › int3 › pyesprima
GitHub - int3/pyesprima: Python port of Esprima, the Javascript parser.
Python port of Esprima, the Javascript parser. Contribute to int3/pyesprima development by creating an account on GitHub.
Starred by 11 users
Forked by 4 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › Kronuz › esprima-python › blob › master › esprima › esprima.py
esprima-python/esprima/esprima.py at master · Kronuz/esprima-python
ECMAScript parsing infrastructure for multipurpose analysis - esprima-python/esprima/esprima.py at master · Kronuz/esprima-python
Author   Kronuz
🌐
Esprima
esprima.org › doc
Esprima Documentation
The documentation is available in the following formats: · Warning: since this version is still being actively development, the documentation is subject to change without notice
🌐
Stack Overflow
stackoverflow.com › questions › tagged › esprima-python
Newest 'esprima-python' Questions - Stack Overflow
Let’s say the code snippet is: var answer = 6 * 7; Example AST: https://esprima.org/demo/parse.html For this code snippet, I ... ... I'm new with Python and I've been trying to use BeautifulSoup to extract one particular data line from a variable defined in a script element.
🌐
GitHub
github.com › austinbyers › esprima-ast-visitor
GitHub - austinbyers/esprima-ast-visitor: Python code to efficiently traverse the AST format saved by the Esprima JavaScript parser
$ npm install esprima $ node > var esprima = require('esprima'); > var fs = require('fs'); > ast_string = JSON.stringify(esprima.parse("var map = {'abc': 123}"), null, 2); > fs.writeFile('test.json', ast_string, null);
Starred by 32 users
Forked by 9 users
Languages   Python 100.0% | Python 100.0%
Find elsewhere
🌐
GitHub
github.com › Kronuz › esprima-python › blob › master › examples › visitor.py
esprima-python/examples/visitor.py at master · Kronuz/esprima-python
ECMAScript parsing infrastructure for multipurpose analysis - esprima-python/examples/visitor.py at master · Kronuz/esprima-python
Author   Kronuz
🌐
Pythonfix
pythonfix.com › pkg › e › esprima
esprima 4.0.1 - ECMAScript parsing infrastructure for multipurpose analysis in Python - PythonFix.com
October 13, 2024 - The Kronuz/esprima-python repo was created 7 years ago and the last code push was 1 years ago.
🌐
PyPI
pypi.org › project › esprima-fork
esprima-fork · PyPI
Download URL: esprima_fork-4.0.4-py3-none-any.whl · Upload date: Oct 25, 2022 · Size: 64.3 kB · Tags: Python 3 · Uploaded using Trusted Publishing? No · Uploaded via: twine/4.0.1 CPython/3.7.7 · See more details on using hashes here. Supported by ·
      » pip install esprima-fork
    
Published   Oct 25, 2022
Version   4.0.4
🌐
GitHub
github.com › Kronuz › esprima-python › blob › master › esprima › parser.py
esprima-python/esprima/parser.py at master · Kronuz/esprima-python
ECMAScript parsing infrastructure for multipurpose analysis - esprima-python/esprima/parser.py at master · Kronuz/esprima-python
Author   Kronuz
Top answer
1 of 5
52

Nowadays, there is at least one better tool, called slimit:

SlimIt is a JavaScript minifier written in Python. It compiles JavaScript into more compact code so that it downloads and runs faster.

SlimIt also provides a library that includes a JavaScript parser, lexer, pretty printer and a tree visitor.

Demo:

Imagine we have the following javascript code:

$.ajax({
    type: "POST",
    url: 'http://www.example.com',
    data: {
        email: '[email protected]',
        phone: '9999999999',
        name: 'XYZ'
    }
});

And now we need to get email, phone and name values from the data object.

The idea here would be to instantiate a slimit parser, visit all nodes, filter all assignments and put them into the dictionary:

from slimit import ast
from slimit.parser import Parser
from slimit.visitors import nodevisitor


data = """
$.ajax({
    type: "POST",
    url: 'http://www.example.com',
    data: {
        email: '[email protected]',
        phone: '9999999999',
        name: 'XYZ'
    }
});
"""

parser = Parser()
tree = parser.parse(data)
fields = {getattr(node.left, 'value', ''): getattr(node.right, 'value', '')
          for node in nodevisitor.visit(tree)
          if isinstance(node, ast.Assign)}

print fields

It prints:

{'name': "'XYZ'", 
 'url': "'http://www.example.com'", 
 'type': '"POST"', 
 'phone': "'9999999999'", 
 'data': '', 
 'email': "'[email protected]'"}
2 of 5
23

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

The ANTLR site provides many grammars, including one for JavaScript.

As it happens, there is a Python API available - so you can call the lexer (recognizer) generated from the grammar directly from Python (good luck).

🌐
PyPI
pypi.org › project › esprima2
esprima2 · PyPI
July 29, 2025 - More (and original) documentation is available here: https://esprima.org ... Download the file for your platform.
      » pip install esprima2
    
Published   Aug 16, 2025
Version   5.0.1
🌐
Snyk
snyk.io › advisor › python packages › esprima
esprima - Python Package Health Analysis | Snyk
The python package esprima receives a total of 35,238 weekly downloads. As such, esprima popularity was classified as a recognized.
🌐
OpenWeaver
kandi.openweaver.com › python › Kronuz › esprima-python
esprima-python | ECMAScript parsing infrastructure for multipurpose analysis | Parser library
You can install using 'pip install esprima-python' or download it from GitHub, PyPI. You can use esprima-python like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution ...
🌐
GitHub
github.com › lucasg › esprima-python
GitHub - lucasg/esprima-python: ECMAScript parsing infrastructure for multipurpose analysis
Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser officially written in ECMAScript (also popularly known as JavaScript) and ported to Python.
Author   lucasg