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.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
Built Distributions
Hashes for py_mini_racer-0.1.17-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6b7e237ac6262ac3dd48373dc63f26a2966a532b272adb424b6a3333f1425f9 |
|
MD5 | 166e082d566c65fe25043381d487292b |
|
BLAKE2b-256 | 9b1648017e17288cf74b2a5bbadad2638dc9bf6848890806a47ea0108679e9cd |
Hashes for py_mini_racer-0.1.17-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 431d634e27b73f2ad6bcb964e870877cbe3a225223181a55777c76ea980349dc |
|
MD5 | 2a4293080642a166084b744b90f6165f |
|
BLAKE2b-256 | 20614b3c9f04df7d91ab10692274963157843950ac0c3562fb0facfc6f43c574 |
Hashes for py_mini_racer-0.1.17-cp37-cp37-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6237a2a3b4d37846ab227c34a6c7dbdeca3feaf07038cfc15ab5696892b04c14 |
|
MD5 | c0097fcf9a95c8613eb19c8c10041349 |
|
BLAKE2b-256 | 34779ba10d660e8dbad4d095884f46ed0bee23b42b230bf2927a7b077fecddc4 |
Hashes for py_mini_racer-0.1.17-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70570f3bdd208eba5a1ba531b9ea2ec36c7ff81f8e8c044c4d14ea66d6ba67d1 |
|
MD5 | e1b46743db998748e1e915ad1d18c75e |
|
BLAKE2b-256 | f13c750b32f11d6622a3cde75906f821ae4af0b1ae519c78db5f4c14f7c834d2 |
Hashes for py_mini_racer-0.1.17-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8b21a422d192a5cf3d24940a8b9d5ee427fcf8597b409e8ffbfe0259cf76fa4 |
|
MD5 | 33b190b5cfc4be62b112948a37966348 |
|
BLAKE2b-256 | 398644c268a1cfe1ce14d8df915ecff6dc19dbaee5b3410bad4996d9ed94c53f |
Hashes for py_mini_racer-0.1.17-cp36-cp36-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5daf4935e178f6fbd1f8656f7ef58d20795b740d180ca358ce944f8242654e6 |
|
MD5 | ad5b8ed01700db92a9d1c6c96cf5e6fb |
|
BLAKE2b-256 | bf2397da0f75cf106f73f52da30706dac22072a9b0381d3e586413b4a89d93c6 |
Hashes for py_mini_racer-0.1.17-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad170501a396de8cba3efb7641d860b9b6ace78b0a05da79364ce1945dadc2a |
|
MD5 | d8eb2f388e18e2ec1cfdad72a24d9348 |
|
BLAKE2b-256 | e5966b037f041ac36d333754d62bce4730c5cd6f16f943ef72e6e7e17c908c03 |
Hashes for py_mini_racer-0.1.17-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 209511182b580c9b4edff94ec2cc65e478da9198eed673643cfc6a61231f2ab4 |
|
MD5 | 8a13e301500b5c989725e97737c5fdd3 |
|
BLAKE2b-256 | 26f2c19e6aaee692e8d65ca3921d4a25a5d4055eeed37f7abbdfab05cbe88bd2 |
Hashes for py_mini_racer-0.1.17-cp35-cp35-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad108b06ddeed515c9ae2acaebdc58db0b7fd727b5695e7d21cf7d05cfbdbfdd |
|
MD5 | c4d7a3de82749c9b70384fed780293f7 |
|
BLAKE2b-256 | 55598b772fa64ab4bc4f37858fa325d4461824d4c8746d85e742759844a0880f |
Hashes for py_mini_racer-0.1.17-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b58b930e91ac0510f9bd4f1ff84810520fe9237217e1eef8dc1497be0c69fa18 |
|
MD5 | 265aaeb7b51eac60f564c949f920adfb |
|
BLAKE2b-256 | 161608300c93de09b14a734c1cf57adb3c7c755dd101a2c1157c411e8f651ae7 |
Hashes for py_mini_racer-0.1.17-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19594aaa00903531df7c01b8f6e4da75b41398bcee1d3070f8906a1938e02c1d |
|
MD5 | fd59191e71bae04f83058e32b38e18ee |
|
BLAKE2b-256 | e5a910408d1d7fbc3b8d3435377fd211114ce156129ed41ac8f822cb125dd3ff |
Hashes for py_mini_racer-0.1.17-cp34-cp34-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f15168aad9a1b012443e1469a075e0ecd351b016ceff44fd8c6a9c5731042b80 |
|
MD5 | dec5ff896be499e840f361a2803d2efa |
|
BLAKE2b-256 | 01301756cc0c0c4ce8568888178da049d3ea9328e9c9441a05b370913bd63562 |
Hashes for py_mini_racer-0.1.17-cp27-cp27u-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | febc7dd5bb4b8e9b12fe5972efbf7c38f5aa5981a3ffdaa5abada2eb047c2c5d |
|
MD5 | e74d08e1b3e11e59f36fa1778e90f497 |
|
BLAKE2b-256 | 223b7c43a5d7f90643133d304a82868287eae24452fc819c83a4c3b73ebdee7e |
Hashes for py_mini_racer-0.1.17-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59c619a54a66bfe330a7defeb68fed7ef84bd95493df9864d64e3c22668e585f |
|
MD5 | bfe6d9cd7b07d7d51836f07c4ca19a55 |
|
BLAKE2b-256 | ba5da1a341cfc2db2757eaf0034fbc2bf8fd0376180a29afd6b9d83177e52c00 |
Hashes for py_mini_racer-0.1.17-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad636a2d8683f9676353b790df9e8c7ae64f9d926b5b3f287fd28973c13cde20 |
|
MD5 | 22ecde0e56cefa834d7879ecf723c2a3 |
|
BLAKE2b-256 | 21aa89f172f8697059ad502a0d5a0c2c331bada8fccc65cc354697a7d4f19211 |
Hashes for py_mini_racer-0.1.17-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5103f60908623402e519bcddba78efc4da85c41438bf03ca7d444df3531212df |
|
MD5 | ffb27cf86d4ae1d0b131359364afc4a9 |
|
BLAKE2b-256 | 9c48369d1693f8f2fc71f8cfc91033a9d35f3f7d6f5183a1b82b1414b95cf527 |
Hashes for py_mini_racer-0.1.17-cp27-cp27-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9d73519bf2b74e76ced351879c38426dfbe742ee3d5571f4068428a3280e887 |
|
MD5 | 150eecfc0c3d5c0f92cc6d8d1bbc35c4 |
|
BLAKE2b-256 | 69b761daa1da750200b7a87e33cbb74580e1dc9d63232394adde769b8b998cfe |