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.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.10.tar.gz (326.6 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.10-cp36-cp36m-manylinux1_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.6m

py_mini_racer-0.1.10-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.10-cp35-cp35m-manylinux1_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.5m

py_mini_racer-0.1.10-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.10-cp34-cp34m-manylinux1_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.4m

py_mini_racer-0.1.10-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.10-cp27-cp27mu-manylinux1_x86_64.whl (4.6 MB view details)

Uploaded CPython 2.7mu

py_mini_racer-0.1.10-cp27-cp27m-manylinux1_x86_64.whl (4.6 MB view details)

Uploaded CPython 2.7m

py_mini_racer-0.1.10-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.10.tar.gz.

File metadata

  • Download URL: py_mini_racer-0.1.10.tar.gz
  • Upload date:
  • Size: 326.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py_mini_racer-0.1.10.tar.gz
Algorithm Hash digest
SHA256 a6281fe7886d6b0b39904c1ecb23928671c9808d0fd51fcf443068839bad7629
MD5 340169b72affa9b72edd4b73418f2b6c
BLAKE2b-256 4c68a0fe3e6ff9878c0adafe1c76b18b3089594add072c7706c355c47bd5c317

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cadafa7267a662666b1b4572e56c8f0c5fe471274d718c0353b7d50d396d6a8b
MD5 f5af1f192670eb8b45968e96c3c88f20
BLAKE2b-256 9206104a426ab2fb8d8425139b7e1b3ee39408160f26e76f8e36f2b02fc7e386

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 928c74daace71b663f534efeffb16ab0b320a540b4b149a4d9f1a94d51bcfe6e
MD5 adaa227218a8f55bc8565a4c110cd433
BLAKE2b-256 1cecd0589d8f75a4d473106e0b90067fb08fd8acea255b4e066bf48a97f06f04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8039d5518c15d831a930f3a9427cd6caa3df2ce9df90fc98db6b8969a63fedfd
MD5 9f9d6c7344c1b2be969c519ff405002e
BLAKE2b-256 07cbae031aa639e8690969f949f2f6dd952de48dfc6b0d66651c2db52556f26a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5bc131f7500b8b0f4f0e28688635f0eb3cddaa065b26e4f7107432c854d1e3ce
MD5 3322a106b481130bde40b3244fa8662b
BLAKE2b-256 b816656e0482670203dda443123de8cbca17181f3c7740d4109fe615ebf95910

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2805a81e4faacee17f575f61509b21c5b1a308f5bfa627e7636284833444ca53
MD5 4efb6445cbe13bc968544a4fc5f7aad3
BLAKE2b-256 3f97300b370524145e767f10d047742c5f32c26fde217323563bf528d02a8110

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 2522f13ab333551dd0e2063773192f73dc8a4e2bab770eecc79e270cb828ab3f
MD5 2aa22c621c3816a4265c544ae2809f04
BLAKE2b-256 9911c922130c2951ecd35dda53591f4d0aceb39d78d411c1b7d1777226911ebd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f15932c8bccfbfe9965f9ee96cbcd4451c2db751d2ea8ad6f6d97e20abad61ca
MD5 210bfcad61e9b93cf67f69815c70952d
BLAKE2b-256 74e8ec13ca10d7524441081393314c9b24d646b23a79f6015f84b99a3e0cebdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cafd4c6a5351a39e5b1eab877e9aa350854d8670494bbb8273db2856da9f39cf
MD5 41e5d2f4219250bc7e6a6bebe0826066
BLAKE2b-256 639c0810402d57feec0da729ab297dc9b43345480db78ae3b0073501c2b737fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_mini_racer-0.1.10-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5b67ddc81de741a218148ae16e8601fa6f22e272fe0713f0050da1ce41ca9ec4
MD5 a35388add5f3b88233001edd35a5f62f
BLAKE2b-256 d038ab2461076e838c5d675664621b7038d0fb67f14a4aa9213bac728f851ea2

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