Skip to main content

Minimal, modern embedded V8 for Python.

Project description

https://img.shields.io/pypi/v/py_mini_racer.svg

Minimal, modern embedded V8 for Python.

  • Free software: ISC license

https://github.com/sqreen/PyMiniRacer/raw/master/data/py_mini_racer.png

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:

https://www.python.org/downloads/

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_mini_racer-0.1.12.tar.gz (325.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

py_mini_racer-0.1.12-cp36-cp36m-manylinux1_x86_64.whl (6.6 MB view details)

Uploaded CPython 3.6m

py_mini_racer-0.1.12-cp36-cp36m-macosx_10_6_intel.whl (4.1 MB view details)

Uploaded CPython 3.6mmacOS 10.6+ Intel (x86-64, i386)

py_mini_racer-0.1.12-cp35-cp35m-manylinux1_x86_64.whl (6.6 MB view details)

Uploaded CPython 3.5m

py_mini_racer-0.1.12-cp35-cp35m-macosx_10_6_intel.whl (4.1 MB view details)

Uploaded CPython 3.5mmacOS 10.6+ Intel (x86-64, i386)

py_mini_racer-0.1.12-cp34-cp34m-manylinux1_x86_64.whl (6.6 MB view details)

Uploaded CPython 3.4m

py_mini_racer-0.1.12-cp34-cp34m-macosx_10_6_intel.whl (4.1 MB view details)

Uploaded CPython 3.4mmacOS 10.6+ Intel (x86-64, i386)

py_mini_racer-0.1.12-cp27-cp27mu-manylinux1_x86_64.whl (6.6 MB view details)

Uploaded CPython 2.7mu

py_mini_racer-0.1.12-cp27-cp27m-manylinux1_x86_64.whl (6.6 MB view details)

Uploaded CPython 2.7m

py_mini_racer-0.1.12-cp27-cp27m-macosx_10_6_intel.whl (4.1 MB view details)

Uploaded CPython 2.7mmacOS 10.6+ Intel (x86-64, i386)

File details

Details for the file py_mini_racer-0.1.12.tar.gz.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12.tar.gz
Algorithm Hash digest
SHA256 dd13b470d3ea6c9336eb451977f365bcd5d0fd4fa9c1bf86514b6c916d7d79aa
MD5 65dd00b8ae70d262ddef517c9639c14f
BLAKE2b-256 b45bd5e5ceb55311e5295fd5c81a152ce70bb4bc967b6d4908c4cc3e151390d9

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 85dd1abb961dd721e2fae363cb97d2fb057c272be3772a14bb50d5b8de45f6ee
MD5 628003aa356af55ebf5479d7840feff8
BLAKE2b-256 11a1275bb5a365c67c77b688e48fad068be1300dde9f53fe96498d962fbde8cf

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 31c5668f0556a21944f5bc045e80c3f772189052a5032d894f42689832e5f497
MD5 19700ac1f889dc3067ecf3173730fbe2
BLAKE2b-256 8c7423a112233603392250abca4bb0db1d2216d53e0d761669f9a12b60cd4769

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1775a5b05578fdebab3d0d56701cf2d1c1f0132814ac432bc5e602543f423253
MD5 655f7de7aac8afbe613e697d8e8ba1fb
BLAKE2b-256 f4ca22ec2af2d7bcf9030565abd11793f4c92ca5301f37f6634244bf0da24b7e

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5dd496f5f3b7b70ad7fbfe4cd03c909fd5aa49993d089a221c13c5eee68fe7db
MD5 4e6680f9a16c09d3c28831331bea2e7b
BLAKE2b-256 681a92ef9aab711c8202d474bcea8ad3a0d789fcae8049292917e62ff47956e2

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 92984c201bb4ee7f8056b1c2b8b4176906cf785abf20a2db9c37d76d83dae83a
MD5 fa4e089ea52736a46cdff96c473f7cd7
BLAKE2b-256 c1bf28dc7486b17d939995b7261822ca8eb65c5074d7919d91541393011c4e30

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 f2b0b322b08d9e4a664deb74366a89bf99e6fffbe52817ff879bf1ce83e5c5a5
MD5 499cbbc90964218e45d08abdb3c46c78
BLAKE2b-256 1807d17849d972f7149344ba5cd9763a02edbfbaa121f7df01054a97cefd6f74

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 19ac989eee86fc48b07d013e92d8c5180abe098c1ceda5a8fa75f8d869fbca67
MD5 c2ff35ebd4cbb7997fb2f4fd0f95b53e
BLAKE2b-256 2e8452dd7259d111342249b0a5f49719ee2530f7c71ccc237c0a6becc96ae1b5

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 df4c651bdc5b415c4a5704b360bc2c3617f842a29f614c519c331b538a16dc34
MD5 8886f991799ca91937f737491c1126b0
BLAKE2b-256 cb11948645c9776216827c880764ba49338eeb96485b98168fae1fa69c8f138e

See more details on using hashes here.

File details

Details for the file py_mini_racer-0.1.12-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for py_mini_racer-0.1.12-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 9828ff395891e2ab7f7ab37fb4fbef59255e880c73d6c22b160c823537f2f18c
MD5 5114dce5926e825cc3f5d3c8bd7a6f19
BLAKE2b-256 05165f5dd2ccdcdcaf869d14c9bd2ee47161f2192f7240f258747b0d577e1289

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page