Skip to main content

Python port of Esprima, the Javascript parser.

Project description

A Python port of [Esprima][1], the JavaScript parser.

Why shouldn’t I use it?

It’s pretty slow – about two orders of magnitude slower to parse a 116k JS file. The code was semi-automatically translated from JavaScript, and it does a lot of string appending, which is fast in JS but slow in Python.

Why should I use it?

Shelling out to a NodeJS process is likely to be a better way to use Esprima from Python. However, writing the interprocess data-marshaling code is a bit annoying, so if you want to do a quick hack on small amounts of data, PyEsprima is a good way to get down to business. The API is exactly the same, so you can easily swap in an interface to the external Node process later on.

Also, since the code is semi-automatically translated using [js2py][2], it’s pretty easy to keep up-to-date. You could even do it yourself. Don’t fear the bit rot!

API

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': ...

Installing

pip install pyesprima

[1]: http://esprima.org/ [2]: https://github.com/int3/js2py

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

pyesprima-1.0.0.tar.gz (21.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pyesprima-1.0.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyesprima-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cd6d9090cb3f8ba8d0b8462c116fc470f2a4f63927395b1a4baf3691bcd2be7f
MD5 af6be6ca4bb22ecf80cd9f99475d14fa
BLAKE2b-256 9e97ba3d2f2397e22dd3344e81b4fa9a368e4733834dddaab3d0e16ff71ddee3

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