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.8.
Binary builds availability
The PyMiniRacer binary builds have been tested on x86_64 with:
macOS >= 10.13
Ubuntu >= 16.04
Debian >= 9
CentOS >= 7
Alpine >= 3.11
Windows 10
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’re running Alpine Linux, you may need to install required dependencies manually using the following command:
$ apk add libgcc libstdc++
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 macOS 64 bits, Linux 64 bits and Windows 64 bits. You need pip >= 1.4 and setuptools >= 0.8.
$ pip install py-mini-racer
If you’re running Alpine, Pypi isn’t able to host the dedicated wheels. We’re making them available with the following command.
$ pip install --index-url https://download.sqreen.io/python/alpine py-mini-racer
Build
First check that your current Python executable is version 2.7. This is required by the V8 build system.
$ python --version
Python 2.7.16
You can build the extension with the following command:
$ python setup.py build_ext
You can generate a wheel for whatever Python version with the command:
$ python setup.py build_ext # (for Python 2 and Python 3)
$ python setup.py bdist_wheel # (for Python 2 only)
$ python3 setup.py bdist_wheel # (for Python 3 only)
It will then build V8, the extension, and generates a wheel for your current Python version. The V8 builds are cached in the py_mini_racer/extension/v8/ directory. Please note that you can build Python 3 wheels by reusing the cached version of V8 built with Python 2.7.
Notes for building on macOS
- 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 the extension 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:
History
0.2.0 (2020-03-11)
Support for Alpine Linux
Avoid pip private modules in setup.py
0.2.0b1 (2020-01-09)
Support for Windows 64 bits
Support for Python 3.8
Upgrade V8 to 7.8
Support soft memory limits
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
Built Distributions
Hashes for py_mini_racer-0.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be887b1b28548e54323aa5b2509397afacbcc2f5d854384f3848161a33b62d11 |
|
MD5 | 950e8603994e88843a34637d9b70d639 |
|
BLAKE2b-256 | 5d0b3cce987593dae10882340003905e59f00b819d576132a752ea2b196cf14c |
Hashes for py_mini_racer-0.2.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df1f263fe31e05dab56eaec6a25dee0ff07d9be58cdffaa91b17bfad48e44f1f |
|
MD5 | 796b0da93260505179b853b7516df0be |
|
BLAKE2b-256 | 31ab6552cc06b7a983a153b8d219c916d5fe0bf2706e98961a0b8edefeef7027 |
Hashes for py_mini_racer-0.2.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fc48a5f63bbe5728f354fde0898dd4111613df287db945e2d38eea637b50fbd |
|
MD5 | 0579483ff778296afdd4712be3f58177 |
|
BLAKE2b-256 | 210f99e9b03fb205c1cd0ae4d4dfb119f2dc4e26a2af4c0d7ff8d199bc145631 |
Hashes for py_mini_racer-0.2.0-cp38-cp38-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f64955ad1cafa52247cc46e5b89d2338bf6a400bffe638154874b7d8c534bd5f |
|
MD5 | 683b9d4312fa02e9bbe6118aa613bd0c |
|
BLAKE2b-256 | 8d184c8563a8fa684f674fbbd393a55bed0980efc320f36996c701ea672d2afe |
Hashes for py_mini_racer-0.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ba3c6e621ebab2413091d894ac56d3309c364f24f7b6a4b3353b89c8b3f6fba |
|
MD5 | b51538e843e5ad6a411afdbdc631c445 |
|
BLAKE2b-256 | 41694a73480e9139350468405877d312a10276d2712c7f112a820157bb590567 |
Hashes for py_mini_racer-0.2.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a2a4e62eec80a7c630e2decf5b8909671737851840aa85aaca79cc0fd702cf |
|
MD5 | b2037c014233602c36a2ef31bab4883d |
|
BLAKE2b-256 | ef3131bcccd37b03921f6b4c651dcb699034ec1e86aa42ef947d47a94ecf16ba |
Hashes for py_mini_racer-0.2.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7982e983571e8083a51dc3fa8dd500581fdaa6c4b4f952bb07d0d1569b00744 |
|
MD5 | a83a2578836b88962de42cc7368eeac5 |
|
BLAKE2b-256 | 5f23bb05b2028abdab8d9f437d345c6fee3430cf996ac25613447ea77d84e838 |
Hashes for py_mini_racer-0.2.0-cp37-cp37m-macosx_10_10_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fadef1719dfe3876cd4c1b4271e52f0720f7880fbbc424e1d4e2cdd7f43b0618 |
|
MD5 | 4e78ad615802147021032daf567de92e |
|
BLAKE2b-256 | fa6459decf629fbcecba6dc9841e4f2511699c158948e02be62b2e4426e73025 |
Hashes for py_mini_racer-0.2.0-cp37-cp37-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae654457b52d79965c4763893d1ac2a91db33b5b07dc7a1c5b6e328d5d8631ec |
|
MD5 | e0d2ae3c65c8632c9b4c6526fe522659 |
|
BLAKE2b-256 | e5f8950217f1a73894b994d1c11a8e9200929ae0f61d2d14c364795e2d5a2e7c |
Hashes for py_mini_racer-0.2.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1680a19b1bdaf60e8d64c278a2da7abcf7d17872ade99614cc2fd13bea286f3 |
|
MD5 | 50f63f32519cfa1b7c748f92f61ab9b1 |
|
BLAKE2b-256 | 979f297ec128285a7ffdb028ceda8e61f810d9ed445148c43f2c48c6ea4a32b3 |
Hashes for py_mini_racer-0.2.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cf948400a13e9eae0eb04fb653f6e65942ec84caa54bde52902d9ff9f5afc0a |
|
MD5 | 6d92e91b320503599e8612af279b3055 |
|
BLAKE2b-256 | e94dd99e8d8dbe0be56c71d64260108d898b7c8eced16ebd978f6866c8bb182a |
Hashes for py_mini_racer-0.2.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91b5bb41286e2fab8a995d5204a05fc28aebe9abb7e66f069ed9bb4dc72c2f0d |
|
MD5 | 37b6769e95d6f62d45a214b6cb72cfb1 |
|
BLAKE2b-256 | 13a8e2ee34f3420c229b4ce01c634a9f90b184c5fca3b74b36ef5289dfc43dca |
Hashes for py_mini_racer-0.2.0-cp36-cp36m-macosx_10_10_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9824e9ad786e22dce1ee77e31ad484df28d727c55d80c1fbde8d45bf3fd6c45 |
|
MD5 | d374b30e9af3040d8a5b3d348cf77eff |
|
BLAKE2b-256 | 380a86a9f433348fe5a06dc1a9cb632e678c5ecbe3725cdafc5e4e0d5eb90bb9 |
Hashes for py_mini_racer-0.2.0-cp36-cp36-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 428afc3a4b1e0b2c49f2646fe2c518b96303a0a0594e6d02ac4e9e07bcffc829 |
|
MD5 | e689a6aa48da27bca7e8ef4924377343 |
|
BLAKE2b-256 | 743ea0499fe9a91396b65b19074b97a55b80cd02d40ef4721febe92ea8b38db2 |
Hashes for py_mini_racer-0.2.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b74377deacb7f7a14cfb44c0a4f4b036269287c8c1064888e52a271d1e5705b5 |
|
MD5 | 3ff821e1d695fb83396b73f8b737feb5 |
|
BLAKE2b-256 | c0a23fe4b4cd1a606f9aaee5ad991e13cff778b394692b973b13fc8d3468d736 |
Hashes for py_mini_racer-0.2.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49ecd95d590ecbbf98451d8c4841fbca0b3ba6b73be30fa589f228de9f6bedcd |
|
MD5 | 8861e223e930a855dc841e7d6d5280a7 |
|
BLAKE2b-256 | 0a73b95478e24746f2b9a4106000bcd0765b7ad785f1d0b3f071dbad781be141 |
Hashes for py_mini_racer-0.2.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03c7d1e4670f6b16ad1d6eefdc0f3a5614f3a60a5ac40f02fc6abc544090c1a5 |
|
MD5 | 426a97da0154a02f0894cbaa69957668 |
|
BLAKE2b-256 | 5e62edf9c4a0c48cd69313ec0f4bfbc4f747d5ab36946c4fb8bafbf2b4a5079b |
Hashes for py_mini_racer-0.2.0-cp35-cp35m-macosx_10_10_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cc74d8308f0a99d5524032de403b9d00e78c7b4b70b3a671a11f2a380a7ed31 |
|
MD5 | cf0cdabfe40f50581a507d664556e80c |
|
BLAKE2b-256 | b3bb90c4429f86102810859a47722a27be80075ea4524020039642db3f299588 |
Hashes for py_mini_racer-0.2.0-cp35-cp35-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06679047adccb05188d302e81a62bafcad36c7d17ae16d189e359987fe6e3ea7 |
|
MD5 | 0c10648cca8680b300149dfcdfe26ae2 |
|
BLAKE2b-256 | 2e54fefb8c7edefa78ede408434a996d677f97ccdf8e188fd1632a2edd27a4e6 |
Hashes for py_mini_racer-0.2.0-cp27-cp27u-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b59404c4753db77dce7fc60c37c4c70ae244070a6210b6e5c59895ba4dc0db7 |
|
MD5 | b453baf24e1794ff4b5aafd22b9a353b |
|
BLAKE2b-256 | a5b6fe7eab85b4167d9d22a2ddb419174d61464dbe9d55c07201f7673f9fec89 |
Hashes for py_mini_racer-0.2.0-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddfb9ea40fbc5bbe6ae51765b16226f4db795f4478215d570371a223d6bc782c |
|
MD5 | 534236f37496211f53bba1c3a42d2a14 |
|
BLAKE2b-256 | 5ba7f5ee66cb779c5892cd0bd8dfdb4aaf6df7ef9e669b2917259f1d385efe7a |
Hashes for py_mini_racer-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdfd7dbf8164a721688ede5e08e6d6afa258d26a9583309d677b3624bf9df5bd |
|
MD5 | 20ff444e2d462a750d676f624c97a8bf |
|
BLAKE2b-256 | 6ba3e2931c2709ba7862b3188e1b2c9f2a8259fc08642d086fa3de1a6a5391f6 |
Hashes for py_mini_racer-0.2.0-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c914f39c86ca17fb827a651f79195436929dd89a81597892b5a394c418e8c76 |
|
MD5 | dec86dc5c84f81b5f564230f59d85e31 |
|
BLAKE2b-256 | 51a983197972148139f7076dfadcf085463b10cb094df15f31b5d0abf0d72d89 |
Hashes for py_mini_racer-0.2.0-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9b9590b314b11777ea26cb751925eea80ec4953c71fdedc0c865e20e57f7f1e |
|
MD5 | 5c8a7fcd0d8fbe7f4f52fe1c768fec79 |
|
BLAKE2b-256 | fcdfbb8288bf8a62c6ddd76387533a0077f534cca5b1a55d3a0f31844fd6855b |
Hashes for py_mini_racer-0.2.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48a53e43963008b41c6b76c28285e4f699c7d0bd1e71164db0605357f59ee8e3 |
|
MD5 | d834ee1111fa8474a3a74b309c508512 |
|
BLAKE2b-256 | 5e1f2fe3a58075f65bee37c328a058e81d938e331a37314f4503e52d9fcc7649 |
Hashes for py_mini_racer-0.2.0-cp27-cp27m-macosx_10_10_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce61f537b7119668c7ad111756695331e0c895e9e8cbc2f09fb68b7910809167 |
|
MD5 | 9f36820b02194a2a949a353155d2cb67 |
|
BLAKE2b-256 | acc69e09c1927ef0567d1d3f7c863bdfe94a74b295c016b331f9557f3327b9d5 |
Hashes for py_mini_racer-0.2.0-cp27-cp27-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 975faa558fb0f2cabe94c4090866a668403d48aa4f3beca5f76b3c06590dbcba |
|
MD5 | 5e76c84bc0c51f47ab4b20d3727dc5eb |
|
BLAKE2b-256 | b3ecd2b7b5c1174b2da5d5b613ba9f5d5573751b08db34683d1633813efac51b |