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.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.15-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9460970a2868f0eaaf7e305a76a96fb776c0c2b0cf61b4bea3589dfa75616cbc |
|
MD5 | 4822f5ffc398fbfba8229648372eaa98 |
|
BLAKE2b-256 | 5b35da40463c08f8acaddedbc5b7ad668f5d454c85a3e0972dfc845f9d0939cc |
Hashes for py_mini_racer-0.1.15-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae2b88fcb5a578547874afdd5be118833c79bc9f9f9590cd9eb5711d01390f6 |
|
MD5 | c2f8477d914e302a7667dfaa85c2a253 |
|
BLAKE2b-256 | 6d36e43fd8c1d6b39eaae504795f925e307d35e742a64030746ad58ec9741ce6 |
Hashes for py_mini_racer-0.1.15-cp37-cp37-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d80a05b1da5c20690fe7895ee27ba1491e72da78bcda494d834942d424f2888f |
|
MD5 | 8e494715b9c9dd3d0e1f0f9ee4de3e53 |
|
BLAKE2b-256 | e1cf0577bb72a3c6f9eb9336e2bca7279d5efd63ec68fa2869ad2dea373ea587 |
Hashes for py_mini_racer-0.1.15-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58036859da735787632d3646127ef5dd3bd672c5c703059671efad7fd5864106 |
|
MD5 | 30da910eeab5a0be5be8b4e3f587d262 |
|
BLAKE2b-256 | 853fb2a9247131e90dfe275e9f18cba441affafb0327b6475c58eee2a0a75c5d |
Hashes for py_mini_racer-0.1.15-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6872a4127603f3e8334ac63107e3af708d6b1a84d4afd893846704c6f12e0e84 |
|
MD5 | a8621286bd759530f81d3a8ca5aad400 |
|
BLAKE2b-256 | ecd74bfb297304dfd289d4fe300f572f0dd89c79bf4ee1cfea3b52b509e32e4b |
Hashes for py_mini_racer-0.1.15-cp36-cp36-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e75f6bdadfcad428b0d327f73c10a15b1833cfb01b6d3c26af99b3611891bcbd |
|
MD5 | f701fa1a944ac0752eea59182420208d |
|
BLAKE2b-256 | 6cab699727a86ade2ba3fb2d2f515373e2421204642694d8c020be998894dab9 |
Hashes for py_mini_racer-0.1.15-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ade8e02816310a7f731f905b74238e20407be9adfaee2127ef844d3ec75bdd0 |
|
MD5 | d48b3640a2ba2eab63f7fe4e880bfe20 |
|
BLAKE2b-256 | e03ba427095d66e61e6605d34cd05f9c1902bca6ee245dd3fdde2d3c78c0013d |
Hashes for py_mini_racer-0.1.15-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f06d3335c1559c07be1a4bfc525502d4cea6b2b340dfb3ae0414d16ad2c11eb |
|
MD5 | 3a25ac8c0c95531e41ec02cd18697175 |
|
BLAKE2b-256 | 30957c0dcaf82bd29b582bf0b89b1897033b068c9899818b2b55eb7351051c61 |
Hashes for py_mini_racer-0.1.15-cp35-cp35-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47a7174d77eab24a360ed17b749f47fed8f85cf8c46fe640d6c47e860e8be318 |
|
MD5 | a898efcf084d8bb4bd13050a75f66431 |
|
BLAKE2b-256 | 7d6f28c77c640206f38b3a26e122dfadf77921f81bdc10e4295a3f6b18b158c9 |
Hashes for py_mini_racer-0.1.15-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 094dc71422b27bb34683e5054a4211a5ec5bc7326b950ef16bfea56b4f355803 |
|
MD5 | 7b3dd503f060fe1afd4c3368a687c26d |
|
BLAKE2b-256 | 46593066bcf18c726873bff92d310c94a961d5456f5bb474f5513951d708b0b1 |
Hashes for py_mini_racer-0.1.15-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 118e54020e157fc375d4bfc17c53a96468b3f928e28a389434eb3b0de39b6d57 |
|
MD5 | 9fa4ddb31afc8f35e90e9f5edd3dac2a |
|
BLAKE2b-256 | aba49eb0a14f4d49420d9af842332a1c1efbfe684aad74bbd6d8b9d319846d57 |
Hashes for py_mini_racer-0.1.15-cp34-cp34-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3e96067013b36422bb181d71588afab07b1e5ba4a50bf72028c7fe4feee6ceb |
|
MD5 | 296d82e4e2b49e07a6b8b68de71dab45 |
|
BLAKE2b-256 | e78e1830fb80813b369efbed10caae8c31551112d5b6c439c525463e0b66714b |
Hashes for py_mini_racer-0.1.15-cp27-cp27u-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49b054a4fdbf99e1fa68806c4c50f916580a639b52315cf8b526a6f8a85240e0 |
|
MD5 | f844fbbaee7461b03f9894bda1531655 |
|
BLAKE2b-256 | c7d0040448f901b5c50fe159f10342f7a7c6798ad2fd2dc444d0db1ef37d2a92 |
Hashes for py_mini_racer-0.1.15-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a31128947b70a9ccaf389196ef8cfc88995b78ea0d375b83e5bf3a3ed7e6efe |
|
MD5 | 69a217555a4f572a8d58a10ac17444ef |
|
BLAKE2b-256 | db5140e53512e3f922db6819bcc6c9851f840b953dd29b63d26df9097ecf04db |
Hashes for py_mini_racer-0.1.15-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c23882f00e7589b4fc282b2a7ac356eb1f5b60951da4776793dccc6f93cd1368 |
|
MD5 | cb72063ac801b92b96707bc4b0f4410a |
|
BLAKE2b-256 | 234c8b62b59fbcc172ee40eb06d023408f52de06ac8a6cc8eae6646c8b3debd4 |
Hashes for py_mini_racer-0.1.15-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95b9fbb4c884552a75ec86bab614c7b164429179913db8e30a0bbd4f956169e5 |
|
MD5 | 45b0210f8714ae6e9322d5a6bee5c4e3 |
|
BLAKE2b-256 | 8fe43d26dcd610aebb360097a35b2fbb4acb9c3ae2cdd2c3b639adc16696cfd4 |
Hashes for py_mini_racer-0.1.15-cp27-cp27-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77f5bc83fa1fe23915bdb57f78e43668a1fe3de7e9afc06023b4b78ae969a78a |
|
MD5 | d2a3aee8124efb95c099dd99319fe303 |
|
BLAKE2b-256 | a07cc68b41cba3eea3c51f737c0213506f93a7afcc0f1eb48129ac2962693675 |