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
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 >= 8
CentOS >= 7
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.17 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
Lower libc version needed. Export V8 version. Fix circular structures export.
History
UNRELEASED
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.11-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fe5175a1ce66cc2f25df1be092450c03f3d5c6af52bcec0a6099f4efd7aa902 |
|
MD5 | bf5a2ed868b232e734d5887a9ab8cd57 |
|
BLAKE2b-256 | 41c87210100c0e0d8f439f984cd3387f3ff4febd7714c6590ff12d9a9e490912 |
Hashes for py_mini_racer-0.1.11-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a09ff68b5c4bee29509e4eb3d416a526cbdd3396ff65f3f35251540a36bc741 |
|
MD5 | ecece524b11b053cfcc96bdd21a05a9b |
|
BLAKE2b-256 | 38f2ea9362c7192b2a158f9c9f808ef6a6850137f4202b0a901c3dcaeec1f7cf |
Hashes for py_mini_racer-0.1.11-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8680d65c7db818a7e36814bbaed241a9dab0a1339a367317f76f3494af1a15d2 |
|
MD5 | 64cc8b01a562da153a8a5b5e9d832cbd |
|
BLAKE2b-256 | 51e56d87e002ec4657b39a5dc2a12e4cf7068988bfc69ee2f51ad88bb01bfda1 |
Hashes for py_mini_racer-0.1.11-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8896d7c8121ad2a9dfbc51e2a7db0aa8e13388b700debb74e0db6a391ce4a858 |
|
MD5 | 2ec75e3c9852fe21deee4f6f4dd0f49f |
|
BLAKE2b-256 | 6df4a97acde4f05ad8ffb1587f38e123a1eadcbb127b2b36c7017e851eeb2087 |
Hashes for py_mini_racer-0.1.11-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4be546a1a7fa96b5308f1eb2009c3312d91316a2c11a48d27a3143baea6ffd6d |
|
MD5 | a113abfc224d5efb2b8efe39fa461bac |
|
BLAKE2b-256 | 5e44f27dda2be8281226b7d52613a8d6701c67128be273939cca8834e73eabc8 |
Hashes for py_mini_racer-0.1.11-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f64a75cd6c5bd019a49e34ed874fc1b616d6f4cdb9be238b3555ea3ed970a37 |
|
MD5 | 20e2d0d0db8db0741eb27898efc2866a |
|
BLAKE2b-256 | c405175d0de46eb84224064a1633025ab8f227bfd6c32f31f240d9a3b7709fa8 |
Hashes for py_mini_racer-0.1.11-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5212c6212d5f065aed9ec8255a538a332d3ebe4cd44c5ed6b692d6387be8425b |
|
MD5 | 811689eb265c8f8b26cfacbece75de60 |
|
BLAKE2b-256 | 550419712e46960c1c212cbdb99460d49584ff0e232a7530e7fed76c07bd48f2 |
Hashes for py_mini_racer-0.1.11-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d17fdc95adba6d288840c0acbebae1ee5c905da14d6debbf33b091d2419c097 |
|
MD5 | ccb1e47d2d5d8c5c450801105e04272f |
|
BLAKE2b-256 | 38c1501d2342f66ea59d44c148ae7bea571bd7365906c89b79e4fbcb68d5ec95 |
Hashes for py_mini_racer-0.1.11-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7986331a18833edf8ed47916a619fe753f9437cf60f1b8cdabe03d4469217c16 |
|
MD5 | a65794ae38cd62c38587a306ee4514ac |
|
BLAKE2b-256 | 86e4695fcd56f36d59b64324ceb770042d3c8d02740e487ef02fc23e66c4b093 |