Giter Site home page Giter Site logo

dux-python / pyexecjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doloopwhile/pyexecjs

0.0 0.0 0.0 154 KB

Run JavaScript code from Python (EOL: https://gist.github.com/doloopwhile/8c6ec7dd4703e8a44e559411cb2ea221)

License: MIT License

Shell 0.68% Python 99.32%

pyexecjs's Introduction

PyExecJS (EOL)

Build Status

End of life

This library is no longer maintananced (Reason). Bugs are not be fixed (even if they are trivial or essential).

We suggest to use other library or to make a fork.


Run JavaScript code from Python.

PyExecJS is a porting of ExecJS from Ruby. PyExecJS automatically picks the best runtime available to evaluate your JavaScript program.

A short example:

>>> import execjs
>>> execjs.eval("'red yellow blue'.split(' ')")
['red', 'yellow', 'blue']
>>> ctx = execjs.compile("""
...     function add(x, y) {
...         return x + y;
...     }
... """)
>>> ctx.call("add", 1, 2)
3

Supported runtimes

First-class support (runtime class is provided and tested)

Second-class support (runtime class is privided but not tested)

Installation

$ pip install PyExecJS

or

$ easy_install PyExecJS

Details

If EXECJS_RUNTIME environment variable is specified, PyExecJS pick the JavaScript runtime as a default:

>>> execjs.get().name # this value is depends on your environment.
>>> os.environ["EXECJS_RUNTIME"] = "Node"
>>> execjs.get().name
'Node.js (V8)'

You can choose JavaScript runtime by execjs.get():

>>> default = execjs.get() # the automatically picked runtime
>>> default.eval("1 + 2")
3
>>> import execjs.runtime_names
>>> jscript = execjs.get(execjs.runtime_names.JScript)
>>> jscript.eval("1 + 2")
3
>>> import execjs.runtime_names
>>> node = execjs.get(execjs.runtime_names.Node)
>>> node.eval("1 + 2")
3

The pros of PyExecJS is that you do not need take care of JavaScript environment. Especially, it works in Windows environment without installing extra libraries.

One of cons of PyExecJS is performance. PyExecJS communicate JavaScript runtime by text and it is slow. The other cons is that it does not fully support runtime specific features.

PyV8 might be better choice for some use case.

License

Copyright (c) 2016 Omoto Kenji. Copyright (c) 2011 Sam Stephenson and Josh Peek. (As a author of ExecJS)

Released under the MIT license. See LICENSE for details.

Changelog

1.5.0

  • Eased version requirement for six.

1.4.1

  • Fixed arguments of module-level functions.
  • Fixed bug of execution with pipe.
  • Fixed wrong excption is raised.

1.4.0

  • Fixed required libraries.
  • Fixed order of output of --print-available-runtimes.
  • Execute some JavaScript runtime with pipe/stdin (without temporary file).

1.3.1

  • Fixed --print-available-runtimes fails in Python 2.7.

1.3.0

  • Added cwd argument.

1.2.0

  • Supported Python 3.5
  • Supported Nashorn(Java 8 JavaScript engine) as runtime
  • Dropped support for Python 2.6 and 3.2

1.1.0

  • Supported Python 3.4
  • Supported SlimerJS as runtime
  • Supported PhantomJS as runtime
  • Fixed JScript runtime on Windows 8

1.0.5

  • Supported Python 3.3
  • Fixed file handle leaking
  • Fixed issue with passenger-nginx-4.0

1.0.4

  • Removed "import execjs" (it prevent execution of setup.py by Python 2.6)

1.0.3

  • Javascript sources were embeded in init.py. 'which' command were reimplemented by pure python.

1.0.2

  • Python 2.6.x was supported.

1.0.1

  • Forgotten shell=True was added to Popen.

1.0.0

  • First release.

pyexecjs's People

Contributors

doloopwhile avatar true-pasky avatar bootandy avatar grivescorbett avatar jamesbroadhead avatar jgibson avatar bkad avatar themylogin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.