Minimal, modern embedded V8 for Python.
Project description
===============================
Python Mini Racer
===============================
.. image:: https://img.shields.io/pypi/v/py_mini_racer.svg
:target: https://pypi.python.org/pypi/py_mini_racer
Minimal, modern embedded V8 for Python.
* Free software: ISC license
.. image:: https://github.com/sqreen/PyMiniRacer/raw/master/data/py_mini_racer.png
Features
--------
* Unicode support
* Thread safe
* Re-usable contexts
* Binary object is Python agnostic
MiniRacer can be easily used by Django or Flask projects to minify assets, run
babel or compile CoffeeScript.
Examples
--------
py_mini_racer is straightforward to use:
.. code-block:: python
>>> from py_mini_racer import py_mini_racer
>>> ctx = py_mini_racer.MiniRacer()
>>> ctx.eval('1+1')
2
>>> ctx.eval("var x = {company: 'Sqreen'}; x.company")
u'Sqreen'
>>> print ctx.eval(u"'\N{HEAVY BLACK HEART}'")
❤
>>> ctx.eval("var fun = () => ({ foo: 1 });")
>>> ctx.call("fun")
{u'foo': 1}
Variables are kept inside of a context:
.. code-block:: python
>>> ctx.eval("x.company")
u'Sqreen'
You can give directly a custom JSON encoder when sending non-JSON encodable
parameters:
.. code-block:: python
import json
from datetime import datetime
class CustomEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
return json.JSONEncoder.default(self, obj)
.. code-block:: python
>>> ctx.eval("var f = function(args) { return args; }")
>>> ctx.call("f", datetime.now(), encoder=CustomEncoder)
u'2017-03-31T16:51:02.474118'
PyMiniRacer is ES6 capable:
.. code-block:: python
>>> ctx.eval("[1,2,3].includes(5)")
False
V8 heap information can be retrieved:
.. code-block:: python
>>> ctx.heap_stats()
{u'total_physical_size': 1613896,
u'used_heap_size': 1512520,
u'total_heap_size': 3997696,
u'total_heap_size_executable': 3145728,
u'heap_size_limit': 1501560832}
Compatibility
-------------
PyMiniRacer is compatible with Python 2 and Python 3. Wheels are generated for python 2.7 and python 3.4 to python 3.6.
Binary builds availability
--------------------------
The PyMiniRacer binary builds have been tested on x86_64 with:
* OSX 10.10
* Ubuntu >= 12.04
* Debian >= 7
* CentOS >= 6
You need pip >= 8.1 to install the wheels - you can check and upgrade yours in
this way:
.. code-block:: bash
$ pip --version
$ pip install --upgrade pip
It should work on any Linux with a libc >= 2.12 and a wheel compatible pip (>=
8.1).
If you have a up-to-date pip and it doesn't use a wheel, you might have an environment for which no wheel is built. Please open an issue.
Installation
------------
We built Python wheels (prebuilt binaries) for OSX 64 bits and Linux 64 bits -
most recent distributions. You need pip >= 1.4 and setuptools >= 0.8.
.. code:: bash
$ pip install py-mini-racer
Build
-----
You can build v8 with the command:
.. code:: bash
$ python setup.py build_v8
You can also build the ctype extension:
.. code:: bash
$ python setup.py build_ext
Which automatically builds v8.
You can generate a wheel with the command:
.. code:: bash
$ python setup.py bdist_wheel
which builds v8, the extension, and generates a wheel.
Notes for building on macOS
'''''''''''''''''''''''''
The legacy Python binary builds (OSX 10.6) need to be downloaded from:
https://www.python.org/downloads/
They will allow to build a wheel compatible with former OSX versions.
If you're having build issues, you may either have to run the build a second time (which will be much faster than the first run) or run the following command before running the first build:
``export LDSHARED="clang++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64"``
Notes for building on Travis
'''''''''''''''''''''''''
The V8 build is cached in order to make the Travis builds faster.
Whenever V8 is updated, the caches need to be flushed `on Travis here`_.
.. _`on Travis here`: https://travis-ci.org/sqreen/PyMiniRacer/caches
Tests
-----
If you want to run the tests, you need to build V8 first, then launch:
.. code:: bash
$ python setup.py test --addopts tests
Credits
-------
Built with love by Sqreen_.
.. _Sqreen: https://www.sqreen.io
PyMiniRacer launch was described in `this blog post`_.
.. _`this blog post`: https://blog.sqreen.io/embedding-javascript-into-python/
PyMiniRacer is inspired by mini_racer_, built for the Ruby world by Sam Saffron.
.. _`mini_racer`: https://github.com/SamSaffron/mini_racer
Tools used in rendering this package:
* Cookiecutter_
* `cookiecutter-pypackage`_
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
Todo
----
Export V8 version.
Fix circular structures export.
History
-------
0.1.18 (2019-01-04)
---------------------
* Support memory and time limits
0.1.17 (2018-19-12)
---------------------
* Upgrade libv8
* Fix a memory leak
0.1.16 (2018-07-11)
---------------------
* Add wheel for Python without PyMalloc
0.1.15 (2018-06-18)
---------------------
* Add wheel for Python 3.7
0.1.14 (2018-05-25)
---------------------
* Add support for pip 10
* Update package metadata
0.1.13 (2018-03-15)
---------------------
* Add heap_stats function
* Fix issue with returned strings containing null bytes
0.1.12 (2018-17-04)
---------------------
* Remove dependency to enum
0.1.11 (2017-07-11)
---------------------
* Add compatibility for centos6
0.1.10 (2017-03-31)
---------------------
* Add the possibility to pass a custom JSON encoder in call.
0.1.9 (2017-03-24)
---------------------
* Fix the compilation for Ubuntu 12.04 and glibc < 2.17.
0.1.8 (2017-03-02)
---------------------
* Update targets build for better compatibility with old Mac OS X and linux platforms.
0.1.7 (2016-10-04)
---------------------
* Improve general performances of the JS execution.
* Add the possibility to build a different version of V8 (for example with debug symbols).
* Fix a conflict that could happens between statically linked libraries and dynamic ones.
0.1.6 (2016-08-12)
---------------------
* Add error message when py_mini_racer sdist fails to build asking to update pip in order to download the pre-compiled wheel instead of the source distribution.
0.1.5 (2016-08-04)
---------------------
* Build py_mini_racer against a static Python. When built against a shared library python, it doesn't work with a static Python.
0.1.4 (2016-08-04)
---------------------
* Ensure JSEvalException message is converted to unicode
0.1.3 (2016-08-04)
---------------------
* Fix extension loading for python3
* Add a make target for building distributions (sdist + wheels)
* Fix eval conversion for python 3
0.1.2 (2016-08-03)
---------------------
* Fix date support
* Fix Dockerfile for generating python3 wheels
0.1.1 (2016-08-02)
---------------------
* Fix sdist distribution.
0.1.0 (2016-08-01)
---------------------
* First release on PyPI.
Python Mini Racer
===============================
.. image:: https://img.shields.io/pypi/v/py_mini_racer.svg
:target: https://pypi.python.org/pypi/py_mini_racer
Minimal, modern embedded V8 for Python.
* Free software: ISC license
.. image:: https://github.com/sqreen/PyMiniRacer/raw/master/data/py_mini_racer.png
Features
--------
* Unicode support
* Thread safe
* Re-usable contexts
* Binary object is Python agnostic
MiniRacer can be easily used by Django or Flask projects to minify assets, run
babel or compile CoffeeScript.
Examples
--------
py_mini_racer is straightforward to use:
.. code-block:: python
>>> from py_mini_racer import py_mini_racer
>>> ctx = py_mini_racer.MiniRacer()
>>> ctx.eval('1+1')
2
>>> ctx.eval("var x = {company: 'Sqreen'}; x.company")
u'Sqreen'
>>> print ctx.eval(u"'\N{HEAVY BLACK HEART}'")
❤
>>> ctx.eval("var fun = () => ({ foo: 1 });")
>>> ctx.call("fun")
{u'foo': 1}
Variables are kept inside of a context:
.. code-block:: python
>>> ctx.eval("x.company")
u'Sqreen'
You can give directly a custom JSON encoder when sending non-JSON encodable
parameters:
.. code-block:: python
import json
from datetime import datetime
class CustomEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
return json.JSONEncoder.default(self, obj)
.. code-block:: python
>>> ctx.eval("var f = function(args) { return args; }")
>>> ctx.call("f", datetime.now(), encoder=CustomEncoder)
u'2017-03-31T16:51:02.474118'
PyMiniRacer is ES6 capable:
.. code-block:: python
>>> ctx.eval("[1,2,3].includes(5)")
False
V8 heap information can be retrieved:
.. code-block:: python
>>> ctx.heap_stats()
{u'total_physical_size': 1613896,
u'used_heap_size': 1512520,
u'total_heap_size': 3997696,
u'total_heap_size_executable': 3145728,
u'heap_size_limit': 1501560832}
Compatibility
-------------
PyMiniRacer is compatible with Python 2 and Python 3. Wheels are generated for python 2.7 and python 3.4 to python 3.6.
Binary builds availability
--------------------------
The PyMiniRacer binary builds have been tested on x86_64 with:
* OSX 10.10
* Ubuntu >= 12.04
* Debian >= 7
* CentOS >= 6
You need pip >= 8.1 to install the wheels - you can check and upgrade yours in
this way:
.. code-block:: bash
$ pip --version
$ pip install --upgrade pip
It should work on any Linux with a libc >= 2.12 and a wheel compatible pip (>=
8.1).
If you have a up-to-date pip and it doesn't use a wheel, you might have an environment for which no wheel is built. Please open an issue.
Installation
------------
We built Python wheels (prebuilt binaries) for OSX 64 bits and Linux 64 bits -
most recent distributions. You need pip >= 1.4 and setuptools >= 0.8.
.. code:: bash
$ pip install py-mini-racer
Build
-----
You can build v8 with the command:
.. code:: bash
$ python setup.py build_v8
You can also build the ctype extension:
.. code:: bash
$ python setup.py build_ext
Which automatically builds v8.
You can generate a wheel with the command:
.. code:: bash
$ python setup.py bdist_wheel
which builds v8, the extension, and generates a wheel.
Notes for building on macOS
'''''''''''''''''''''''''
The legacy Python binary builds (OSX 10.6) need to be downloaded from:
https://www.python.org/downloads/
They will allow to build a wheel compatible with former OSX versions.
If you're having build issues, you may either have to run the build a second time (which will be much faster than the first run) or run the following command before running the first build:
``export LDSHARED="clang++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64"``
Notes for building on Travis
'''''''''''''''''''''''''
The V8 build is cached in order to make the Travis builds faster.
Whenever V8 is updated, the caches need to be flushed `on Travis here`_.
.. _`on Travis here`: https://travis-ci.org/sqreen/PyMiniRacer/caches
Tests
-----
If you want to run the tests, you need to build V8 first, then launch:
.. code:: bash
$ python setup.py test --addopts tests
Credits
-------
Built with love by Sqreen_.
.. _Sqreen: https://www.sqreen.io
PyMiniRacer launch was described in `this blog post`_.
.. _`this blog post`: https://blog.sqreen.io/embedding-javascript-into-python/
PyMiniRacer is inspired by mini_racer_, built for the Ruby world by Sam Saffron.
.. _`mini_racer`: https://github.com/SamSaffron/mini_racer
Tools used in rendering this package:
* Cookiecutter_
* `cookiecutter-pypackage`_
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
Todo
----
Export V8 version.
Fix circular structures export.
History
-------
0.1.18 (2019-01-04)
---------------------
* Support memory and time limits
0.1.17 (2018-19-12)
---------------------
* Upgrade libv8
* Fix a memory leak
0.1.16 (2018-07-11)
---------------------
* Add wheel for Python without PyMalloc
0.1.15 (2018-06-18)
---------------------
* Add wheel for Python 3.7
0.1.14 (2018-05-25)
---------------------
* Add support for pip 10
* Update package metadata
0.1.13 (2018-03-15)
---------------------
* Add heap_stats function
* Fix issue with returned strings containing null bytes
0.1.12 (2018-17-04)
---------------------
* Remove dependency to enum
0.1.11 (2017-07-11)
---------------------
* Add compatibility for centos6
0.1.10 (2017-03-31)
---------------------
* Add the possibility to pass a custom JSON encoder in call.
0.1.9 (2017-03-24)
---------------------
* Fix the compilation for Ubuntu 12.04 and glibc < 2.17.
0.1.8 (2017-03-02)
---------------------
* Update targets build for better compatibility with old Mac OS X and linux platforms.
0.1.7 (2016-10-04)
---------------------
* Improve general performances of the JS execution.
* Add the possibility to build a different version of V8 (for example with debug symbols).
* Fix a conflict that could happens between statically linked libraries and dynamic ones.
0.1.6 (2016-08-12)
---------------------
* Add error message when py_mini_racer sdist fails to build asking to update pip in order to download the pre-compiled wheel instead of the source distribution.
0.1.5 (2016-08-04)
---------------------
* Build py_mini_racer against a static Python. When built against a shared library python, it doesn't work with a static Python.
0.1.4 (2016-08-04)
---------------------
* Ensure JSEvalException message is converted to unicode
0.1.3 (2016-08-04)
---------------------
* Fix extension loading for python3
* Add a make target for building distributions (sdist + wheels)
* Fix eval conversion for python 3
0.1.2 (2016-08-03)
---------------------
* Fix date support
* Fix Dockerfile for generating python3 wheels
0.1.1 (2016-08-02)
---------------------
* Fix sdist distribution.
0.1.0 (2016-08-01)
---------------------
* First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_mini_racer-0.1.18.tar.gz
(330.3 kB
view hashes)
Built Distributions
Close
Hashes for py_mini_racer-0.1.18-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c361993ffd77bed8b35039f3c383f090117244b1ec14478002362c1e6e91ac23 |
|
MD5 | 22fcdb01896276cf09852566a545be15 |
|
BLAKE2b-256 | 1038ac2b29b1d6ad891fee6ef85763ba05df7b3bd0bf35f04dc97f3076b23ef5 |
Close
Hashes for py_mini_racer-0.1.18-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25c39786471f9fe7ef3ce6ae53638d6b31924fa5e7d28c5e100907b930f931c1 |
|
MD5 | ffb172227fae329acedf6fcf44e2db14 |
|
BLAKE2b-256 | d419243079a8ae90bd8cd6355665b96e01379544edfed7d23e9107c24e32370c |
Close
Hashes for py_mini_racer-0.1.18-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f37917a37f9cc5f3a05640a12de86609736576846c5a55832a71db06ac64387b |
|
MD5 | ebb0d0d6abda9b63ef5ef8a673b9ce7e |
|
BLAKE2b-256 | 9ecf85e96e3c19f487d63f9601970f3f7fec86a907700f65dd731d11e549f9ed |
Close
Hashes for py_mini_racer-0.1.18-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d56f8a76b7e62d2dbe9e29afff5ef9fe033bc868fc0c26a331f3ab5dbbdbaf4 |
|
MD5 | 1d4f3dd063da126241f229298a61b995 |
|
BLAKE2b-256 | 7d07155960e92899a3c2ed4f137d4bd9d08f26993c010ac4f3ac1d620cab6b5f |
Close
Hashes for py_mini_racer-0.1.18-cp37-cp37-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8b58e2cc9de46506342046abc54c32ce63f3e8274aa6f6c3c9962011b14193c |
|
MD5 | acc1ad4f9894acc591817b44d0fe1c94 |
|
BLAKE2b-256 | ce6005961c12f36cea65d5d5b494697265a7614d40160614e41061da6bf8a803 |
Close
Hashes for py_mini_racer-0.1.18-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac77863bdcaf930e634d123f23e1d8db0adc04f68bac65565d2bf962f1286b3a |
|
MD5 | f87a125caeb4e657703a470ef8ae8d6e |
|
BLAKE2b-256 | 3d1a3489c52153187879c8b1ebfbc98e6d8fb53a049c45adc3a803a623fee6e9 |
Close
Hashes for py_mini_racer-0.1.18-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3263dca16d89d1be554884d32afe9366344bd7b302928becafe0b2de0b99520a |
|
MD5 | 032e46ab534324a00a44e34c08d6da69 |
|
BLAKE2b-256 | 53b0e296b6be40622409305998a56fda802a4ccf75dd171eaeeb7de8aa3448aa |
Close
Hashes for py_mini_racer-0.1.18-cp36-cp36-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3166b7ac1a00fc7520c7e6a1737abf10245bd225644163f4ed8039501f3c6e11 |
|
MD5 | 001cb819845046d763f0997ba5c0352c |
|
BLAKE2b-256 | 6525409543465c409efdd228f6b16e7a04d1781946c938b1b3eb2aa712f8f219 |
Close
Hashes for py_mini_racer-0.1.18-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d8c3553a1f960af32d9837656064374620cfaf92f9c238ff09f4fd6010eacfe |
|
MD5 | 73d4f202f96b01d022c1c497ee9fa236 |
|
BLAKE2b-256 | 1198ea5db59e11dad9dabc2aab3558104bea1c55f3c0481a29fcce82cd4117af |
Close
Hashes for py_mini_racer-0.1.18-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0f1136983c10fdadd271c6c8d4f3f866588905b94a12d8d4c97299669751b95 |
|
MD5 | e0a4f9015baee6685192c40e316da1b3 |
|
BLAKE2b-256 | eba261c3cbb7038ef6da54edc115c19c5ea9bf5734c7caba808cafecd0f9e395 |
Close
Hashes for py_mini_racer-0.1.18-cp35-cp35-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 145d5da31f6ef0a0edcb003f2e2500e73643e4ee76cab956babc11528664b9ec |
|
MD5 | 15b93c895fcfce6bdb38bf09d6d35190 |
|
BLAKE2b-256 | 0af12e1e858f6bfde4a9bb7894706e0e11682984b5878f725928e0b9117f2636 |
Close
Hashes for py_mini_racer-0.1.18-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0176dfd4d0c0f658bdec0314c4ef6c45652df13bcef9fb50899b224b22f0972b |
|
MD5 | 8fa2247c0ae38961673e2f6e9aa4cdb4 |
|
BLAKE2b-256 | f7310ccbc8ff4bd96b5746506405dc6d3793c72f405018e5d7f1b943bf27ebdf |
Close
Hashes for py_mini_racer-0.1.18-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e048e2aa6708a6e4cf0e426d87bcce0660850b3b70ed836bea6198156b89c8cd |
|
MD5 | a2ed4371c4e4ca68f0edc6812e7e6574 |
|
BLAKE2b-256 | 5fd8cf81d135ee3b0bdf0fdd37f74034113d4215b5a12b0c82a5acef13e90972 |
Close
Hashes for py_mini_racer-0.1.18-cp34-cp34-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 980accd6df7c646383ba314e8515c739a0d88c31f292f013f2fb1473b41f2992 |
|
MD5 | 2db7fb5b57da439cb86480269b3cfc31 |
|
BLAKE2b-256 | 1806a89d33f0f161a05657b4efc7588919022bf9ce4ce8f8ce1dab3b93e0b1be |
Close
Hashes for py_mini_racer-0.1.18-cp27-cp27u-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c942bf330aeff9268c472f9b287e352d9745745ebfd6de95cf7f6cd2b39e6b8 |
|
MD5 | 4ef392704169af246e90261d8012f3df |
|
BLAKE2b-256 | 39fb64eea8539c9c459ddab97be308c52edf7b954d483cf566b1dad699ec3362 |
Close
Hashes for py_mini_racer-0.1.18-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2888a2390d16f1c50501a49bb2beed1335c6a434792ac9765c84555016b098b2 |
|
MD5 | 4d21566a35b3a9d117445a9309dab32a |
|
BLAKE2b-256 | 327e08ca23a8a4d04f6cd5e9de02a68d403812c80320a033da0517323b92e934 |
Close
Hashes for py_mini_racer-0.1.18-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff2593eb1dde6615dbce69011a6bff42879449498710e5ba1c6e4b96ec45e970 |
|
MD5 | 561949ee1d1e80dee104869ca2299289 |
|
BLAKE2b-256 | efd97e63570e24be0302d7c9a59e8c2bbe164466dd424794fc7f1372a4d35141 |
Close
Hashes for py_mini_racer-0.1.18-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc0691f772d6451b0cdb0b2f4ca516a0467bcb936f9d6875bd7d95ea048a5531 |
|
MD5 | cfafeef29282567025bc2b2fec52f19e |
|
BLAKE2b-256 | f7301439f63185723ac5e3f17ac1009f231e0f78dfa5947ad7a91b8c7212c901 |
Close
Hashes for py_mini_racer-0.1.18-cp27-cp27-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38f125b7600a2cfb333e98267c78a5d40500aac849ca51de6d090bc8af7da9c6 |
|
MD5 | 9c5ca55ded1a6523e5156f22f597f62f |
|
BLAKE2b-256 | 9d3f785e85c17f4d0fa920b5add576bfee9ff8731fc44baf743e0a0dce5cf25a |