Minimal, modern embedded V8 for Python.
Project description
Minimal, modern embedded V8 for Python.
Free software: ISC license
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:
>>> 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:
>>> ctx.eval("x.company")
u'Sqreen'
You can give directly a custom JSON encoder when sending non-JSON encodable parameters:
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)
>>> 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:
>>> ctx.eval("[1,2,3].includes(5)")
False
V8 heap information can be retrieved:
>>> 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:
$ 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.
$ pip install py-mini-racer
Build
You can build v8 with the command:
$ python setup.py build_v8
You can also build the ctype extension:
$ python setup.py build_ext
Which automatically builds v8.
You can generate a wheel with the command:
$ python setup.py bdist_wheel
which builds v8, the extension, and generates a wheel.
Notes for building on OSX
- The legacy Python binary builds (OSX 10.6) need to be downloaded from:
They will allow to build a wheel compatible with former OSX versions.
Tests
If you want to run the tests, you need to build V8 first, then launch:
$ python setup.py test --addopts tests
Credits
Built with love by Sqreen.
PyMiniRacer launch was described in this blog post.
PyMiniRacer is inspired by mini_racer, built for the Ruby world by Sam Saffron.
Tools used in rendering this package:
Todo
Export V8 version. Fix circular structures export.
History
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
Built Distributions
Hashes for py_mini_racer-0.1.14-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6e8f9fabab1385d9d354e72c0be53311869850fae7d0a66a1fa5e025797ebe1 |
|
MD5 | 0e9682106d79ca59845b20b944c0e9df |
|
BLAKE2b-256 | 77dcb60c0c20e96cf472a04f91d6e21f95f7e21056bcb2fc0e8ec68d3e710be1 |
Hashes for py_mini_racer-0.1.14-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a432f24a7ed21dff5cea81516b1a11f8af42ecafb1f4ad64635cd0c0372ec63 |
|
MD5 | 4e5c2e7a73b76c1c97547b444e0b73c7 |
|
BLAKE2b-256 | bfe224b078e099b40159abe732f535a1c002f1135cbe4bcfd088a080607d4b48 |
Hashes for py_mini_racer-0.1.14-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c538b66645c9c387692f36b2a4d3b0a7ab06715a8d867c35b4b3f2e0058ce51 |
|
MD5 | 3ce84a336494c0b9bf80bd979416b55c |
|
BLAKE2b-256 | 98364d1604eda4ebcb3d8ce7297169891f1a35742650ea9bba3df71bccaf0bdf |
Hashes for py_mini_racer-0.1.14-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b27b51411aac964eb8e22341c00273b7132b041a303f005b59c60fda3a6b58a |
|
MD5 | 4ccaf59c03413a154c6f8fa431478e60 |
|
BLAKE2b-256 | ffb323030b8638f4dcf6c42b42d71ff54ca4ba4d7e4fbba48d2dd977a3b0d14f |
Hashes for py_mini_racer-0.1.14-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec45858f22a9736655b76142745f5ccbf525b7f1341a1b9f71bc9951785c8bff |
|
MD5 | c577d148ce15968d62f6034c128e2351 |
|
BLAKE2b-256 | 88bd85bde82a6506b17af4f552b228b368a633914ed4cd8d294eb7a733d2e627 |
Hashes for py_mini_racer-0.1.14-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c789f34c96ef300ad368e7aa3614eaa0d04669559bda6afcfb7382112d81d584 |
|
MD5 | b9b269196fbe55f0e168c72588ce519f |
|
BLAKE2b-256 | be0bbc98607918dec7b188e67041c894297e9550c4724296431ba7fb1e5265e9 |
Hashes for py_mini_racer-0.1.14-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef86b39d1a33ecd6c7f991f97ab006d5460ac47779cb26cf5d9e434d8e9b6da7 |
|
MD5 | c8c9fbf2ba100339d37abf333a8e54ba |
|
BLAKE2b-256 | d80c46df9eff2445812d4af69440e30ed052d6d0f50dcb5d133ec293b60aa567 |
Hashes for py_mini_racer-0.1.14-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45ca8a87580d75d4f56b90266f7713606dea091197d391ea08fedcd1d6fe701d |
|
MD5 | 73d451ce366be9811d50e75629caa1b5 |
|
BLAKE2b-256 | f8738246e90606663861f5d8a7ed139dfbeae8def96cabb6abac506e7587bc6e |
Hashes for py_mini_racer-0.1.14-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 621b68bc32aa281e65d167efb44e952c3e391ae613620ac0c492511f695f8bbc |
|
MD5 | b0d4aac0f5b92a7d7b01e1a2d44b00d5 |
|
BLAKE2b-256 | 6f1c59d4b58984f3c0492ecf6f9c26c1eeae1a0cdf4e16be17a10610174cd91f |