Doesn't seem to be under active development anymore but you could check out pynarcissus, http://code.google.com/p/pynarcissus/source/browse/trunk/jsparser.py

Seems like a binding to V8 (JavaScript interpreter in Google Chromium) is available also, http://www.advogato.org/article/985.html

Answer from basicxman on Stack Overflow
🌐
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 › esprima
esprima · PyPI
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.
      » pip install esprima
    
Published   Aug 24, 2018
Version   4.0.1
🌐
Stack Overflow
stackoverflow.com › questions › 64855107 › how-to-render-ecmascript-6-with-python
how to render ecmascript 6 with python?
I try to run ECMAScript 6 with python I already try that from quickjs import Function from py_mini_racer import py_mini_racer import execjs import js2py import requests_html js = """
🌐
StackShare
stackshare.io › stackups › es6-vs-python
ES6 vs Python | What are the differences?
Some of its major enhancements ... destructuring patterns, and proper tail calls. Python is a general purpose programming language created by Guido Van Rossum....
🌐
Ku
phylo.bio.ku.edu › content › ecmascript-python-programmers
ecmascript for python programmers | phylo.bio.ku.edu
In Python, this "next object in the cascade" is the class of the object (and if it is not found there it checks for the attribute in the class' superclass...). In ECMAScript the "next object in the cascade" is the prototype (and if the property is not there then the interpreter checks the prototype of the prototype...).
🌐
Wikipedia
en.wikipedia.org › wiki › ECMAScript
ECMAScript - Wikipedia
February 21, 2026 - ECMAScript (/ˈɛkməskrɪpt/; ES) is a standard for scripting languages including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers.
🌐
Medium
medium.com › imgcook › python-in-ecmascript-modules-48bc81fd8789
Python in ECMAScript Modules. Author: @rickyes | by Yorkie Neil | imgcook | Medium
May 22, 2020 - Use boa.import() to load the Python module, and use the built-in dir function of Python builtins to get all the attributes of the module. The hook needs to provide the export list in advance and pass it to the exports parameter to support Named exports, plus default to support Default exports.
Find elsewhere
🌐
Fusionbox
fusionbox.com › blog › detail › ecmascript-6-classes-potential-pitfalls-for-the-python-programmer › 575
Avoiding Pitfalls in EcmaScript Classes | Fusionbox
August 25, 2015 - With the advent of the EcmaScript 6 standard (officially known as EcmaScript 2015), JavaScript has received a facelift with plenty of new features that will immediately look familiar to the Python developer.
🌐
Real Python
realpython.com › python-vs-javascript
Python vs JavaScript for Pythonistas – Real Python
July 31, 2023 - Since then, there have been only a handful of releases, which looks stagnant compared to the multiple new versions of Python released each year during the same period. Notice the gap between ES3 and ES5, which lasted an entire decade! Due to political conflicts and disagreements in the technical committee, ES4 never made its way to web browsers, but it was used by Macromedia (later Adobe) as a base for ActionScript. The first major overhaul to JavaScript came in 2015 with the introduction of ES6, also known as ES2015 or ECMAScript Harmony.
🌐
GitHub
gist.github.com › revolunet › 537a3448cff850231a74
# Python VS JavaScript ES6 syntax comparison · GitHub
This is fantastic. Came here for the Python spread operator, left with that AND the Array.from :) and excitement for the JS list comprehension.
🌐
2ality
2ality.com › 2015 › 10 › es6-influences.html
Influences on ECMAScript 6
This is a list of a few ECMAScript 6 features and what their influences were: Iteration: Python (but with a modified protocol) Generators: Python · Arrow functions: CoffeeScript · const: The name comes from C++ (the latest C standard borrowed it from C++), but it behaves more like Java’s final.
🌐
GitHub
github.com › PiotrDabkowski › pyjsparser
GitHub - PiotrDabkowski/pyjsparser: Fast JavaScript parser for Python.
Fast JavaScript parser - manual translation of esprima.js to python. Takes 1 second to parse whole angular.js library so parsing speed is about 100k characters per second which makes it the fastest and most comprehensible JavaScript parser for python out there. Supports whole ECMAScript 5.1 and parts of ECMAScript 6.
Starred by 256 users
Forked by 40 users
Languages   JavaScript 82.5% | Python 17.5% | JavaScript 82.5% | Python 17.5%
🌐
PyPI
pypi.org › project › javascripthon
javascripthon · PyPI
An extensive documentation about Python’s AST objects, very handy. Have a look at ECMAScript 6 Tools by Addy Osmani.
      » pip install javascripthon
    
Published   Jul 04, 2024
Version   0.13
🌐
GitHub
github.com › topics › ecmascript
ecmascript · GitHub Topics · GitHub
ECMAScript is the standardization of the family of scripting languages that includes JavaScript. New versions of the standard are released every year. It is standardized by Ecma International.
🌐
GitHub
github.com › bbraithwaite › ECMAStrict
GitHub - bbraithwaite/ECMAStrict: JavaScript lexer, parser & interpreter written in Python (for fun).
JavaScript lexer, parser & interpreter written in Python (for fun). - bbraithwaite/ECMAStrict
Author   bbraithwaite
🌐
Trey Hunner
treyhunner.com › js-like-python
JavaScript: Slightly more like Python
A word of warning: I will be going very quickly and there are code examples on almost every slide. ECMAScript is the language specification that JavaScript is based on. In this presentation I'm going to show off features that were added in ECMAScript 6, also known as ECMAScript 2015.
🌐
Object Computing
objectcomputing.com › resources › publications › sett › december-2020-comparing-python-and-javascript
Comparing Python and JavaScript: A Guide for Developers | Object Computing, Inc.
Python supports decorators, which are annotations placed before functions and classes to alter their behavior. The TC39 committee that controls the ECMAScript standard for JavaScript has been discussing adding decorators for many years, but they have not yet been added.
🌐
Reddit
reddit.com › r/javascript › what does python do better/worse than es6 javascript, esp when it comes to readability/expressiveness?
r/javascript on Reddit: What does Python do better/worse than ES6 JavaScript, esp when it comes to readability/expressiveness?
January 3, 2018 -

I don't want to use the term concise/terse, because many people take that to be a synonym for clever/confusing.

But Python is said to be a very readable language, due to syntax, whitespace rules, lack of {} etc, and is said to be 'executable pseudocode'. ES6 was a huge advance for JS and I find it a great mix of power and expressiveness.

Python:

def square(n):
  return n*n

square2 = lambda x: x**2

def adder(x):
  return lambda y: x + y

ES6:

function square(x) { return x*x } 
const square2 = x => x**x
const adder = x => y => x + y

Maybe its because I'm used to it, but I find the JS versions easier to read/understand. Interestingly, the regular function syntax in python isn't more verbose than the lambda unlike in JS. Is there any difference between the Python version of square and square2?

I know python has things like list comprehensions and probably other things I'm not aware of that make it more powerful, and I'm curious how the 2 compare today.

Top answer
1 of 5
3
Well, to be honest I find both languages quite readable but personally ES syntax is easier to understand. I'm not experienced in Python but I've read quite a lot code written in this language to convert solution to JS so there is one thing I can say about both: Pyhon code visually will look very alike whether it's written by novice or by advanced (based on code I read) In JS there is much more freedom so you can find different coding styles across the web. It's likely that it'll be harder for you to read JS code if author uses different style than you're used to.
2 of 5
3
I like to use python for data processing, and js for async things. range, list comprehension, for ... in ... loop, etc. in python makes it easy to work with strings, and lists. There are lots of libraries for data analysis. numpy allows you to do that pretty fast. I've never heard about async things in python so I guess python is not suited for that. With async/await (or promise) in JS you can write readable and short code to do async things. JS is kinda slow for CPU bound things (because it's dynamic typed), but web assembly solves that problem. And as you know, there are insane number of libraries for doing web-related things including server-side and client-side. For example, to calculate the squared sum of numbers in an array (a list in python) that are larger than 3, in js you would do arr.filter(n => n > 3).map(n => n * n).reduce((acc, n) => acc + n) In python, sum(n ** 2 for n in lis if n > 3) I think the python version is more readable yet being shorter. Also it's more memory efficient because it doesn't generate any intermediate lists or something. Python also has other useful functions to process lists (and iterables) like any(), all(), max(), min(). So I prefer python for processing a collection of data.
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).