{ "info": { "author": "Stefano Dissegna", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", "Programming Language :: JavaScript", "Programming Language :: Python :: 3", "Topic :: Software Development :: Interpreters" ], "description": "Introduction\n############\n\nPyduktape is a python wrapper around `Duktape `_,\nan embeddable Javascript interpreter.\n\nOn top of the interpreter wrapper, pyduktape offers easy integration\nbetween the Python and the Javascript environments. You can pass\nPython objects to Javascript, call methods on them and access their\nattributes. Similarly, you can pass Javascript objects to Python.\n\nObjects are never copied or serialized. Instead, they are passed\nbetween the two environments using proxy objects. Proxy objects\ndelegate the execution to the original object environment.\n\nThreading\n#########\n\nIt is possible to invoke Javascript code from multiple threads. Each\nthread will need to use its own embedded interpreter. Javascript\nobjects returned to the Python environment will only be usable on the\nsame thread that created them. The runtime always checks this\ncondition automatically, and raises a ``DuktapeThreadError`` if it's\nviolated.\n\nGetting Started\n###############\n\nInstallation\n------------\n\nTo install from pypi::\n\n $ pip install pyduktape2\n\nTo install the latest version from github::\n\n $ pip install git+https://github.com/phith0n/pyduktape2\n\nRunning Javascript code\n-----------------------\n\nTo run Javascript code, you need to create an execution context and\nuse the method ``eval_js``::\n\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n context.eval_js(\"print('Hello, world!');\")\n\nEach execution context starts its own interpreter. Each context is\nindependent, and tied to the Python thread that created it. Memory is\nautomatically managed.\n\nTo evaluate external Javascript files, use ``eval_js_file``::\n\n // helloWorld.js\n print('Hello, World!');\n\n # in the Python interpreter\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n context.eval_js_file('helloWorld.js')\n\nPyduktape supports Javascript modules::\n\n // js/helloWorld.js\n exports.sayHello = function () {\n print('Hello, World!');\n };\n\n // js/main.js\n var helloWorld = require('js/helloWorld');\n helloWorld.sayHello();\n\n # in the Python interpreter\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n context.eval_js_file('js/main')\n\nThe ``.js`` extension is automatically added if missing. Relative\npaths are relative to the current working directory, but you can\nchange the base path using ``set_base_path``::\n\n # js/helloWorld.js\n print('Hello, World!');\n\n # in the Python interpreter\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n context.set_base_path('js')\n context.eval_js_file('helloWorld')\n\nPython and Javascript integration\n---------------------------------\n\nYou can use ``set_globals`` to set Javascript global variables::\n\n import pyduktape2\n\n def say_hello(to):\n print 'Hello, {}!'.format(to)\n\n context = pyduktape2.DuktapeContext()\n context.set_globals(sayHello=say_hello, world='World')\n context.eval_js(\"sayHello(world);\")\n\nYou can use ``get_global`` to access Javascript global variables::\n\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n context.eval_js(\"var helloWorld = 'Hello, World!';\")\n print context.get_global('helloWorld')\n\n``eval_js`` returns the value of the last expression::\n\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n hello_world = context.eval_js(\"var helloWorld = 'Hello, World!'; helloWorld\")\n print hello_world\n\nYou can seamlessly use Python objects and functions within Javascript\ncode. There are some limitations, though: any Python callable can\nonly be used as a function, and other attributes cannot be\naccessed. Primitive types (int, float, string, None) are converted to\nequivalent Javascript primitives. The following code shows how to\ninteract with a Python object from Javascript::\n\n import pyduktape2\n\n class Hello(object):\n def __init__(self, what):\n self.what = what\n\n def say(self):\n print('Hello, {}!'.format(self.what))\n\n context = pyduktape2.DuktapeContext()\n context.set_globals(Hello=Hello)\n context.eval_js(\"var helloWorld = Hello('World'); helloWorld.say();\")\n\nIn the same way, you can use Javascript objects in Python. You can\nuse the special method `new` to instantiate an object::\n\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n Hello = context.eval_js(\"\"\"\n function Hello(what) {\n this.what = what;\n }\n\n Hello.prototype.say = function () {\n print('Hello, ' + this.what + '!');\n };\n\n Hello\n \"\"\")\n\n hello_world = Hello.new('World')\n hello_world.say()\n\nYou can use Python lists and dicts from Javascript, and viceversa::\n\n import pyduktape2\n\n context = pyduktape2.DuktapeContext()\n res = context.eval_js('[1, 2, 3]')\n\n for item in res:\n print(item)\n\n context.set_globals(lst=[4, 5, 6])\n context.eval_js('for (var i = 0; i < lst.length; i++) { print(lst[i]); }')\n\n res = context.eval_js('var x = {a: 1, b: 2}; x')\n for key, val in res.items():\n print(key, '=', val)\n res.c = 3\n context.eval_js('print(x.c);')\n\n context.set_globals(x=dict(a=1, b=2))\n context.eval_js(\"\"\"\n var items = x.items();\n for (var i = 0; i < items.length; i++) {\n print(items[i][0] + ' = ' + items[i][1]);\n }\n \"\"\")\n context.set_globals(x=dict(a=1, b=2))\n context.eval_js('for (var k in x) { print(k + ' = ' + x[k]); }')", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/phith0n/pyduktape2", "keywords": "javascript duktape embed", "license": "GPL", "maintainer": "", "maintainer_email": "", "name": "pyduktape2", "package_url": "https://pypi.org/project/pyduktape2/", "platform": "", "project_url": "https://pypi.org/project/pyduktape2/", "project_urls": { "Homepage": "https://github.com/phith0n/pyduktape2" }, "release_url": "https://pypi.org/project/pyduktape2/0.3.1/", "requires_dist": null, "requires_python": "", "summary": "Python integration for the Duktape Javascript interpreter", "version": "0.3.1" }, "last_serial": 5607872, "releases": { "0.2.2": [ { "comment_text": "", "digests": { "md5": "ef1b98ab217f198e675e8a4e2e5a6dc5", "sha256": "ab261e7967aee1c32773d37f1956789a14038e5c7a15cfd601f99dd276626ccb" }, "downloads": -1, "filename": "pyduktape2-0.2.2-cp36-cp36m-macosx_10_11_x86_64.whl", "has_sig": false, "md5_digest": "ef1b98ab217f198e675e8a4e2e5a6dc5", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 370191, "upload_time": "2018-09-30T14:10:32", "url": "https://files.pythonhosted.org/packages/cf/42/16cc5e712665c331f0b4348872f48d6b2d78faec2cf7a67a4075c3e9727e/pyduktape2-0.2.2-cp36-cp36m-macosx_10_11_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "8f63ae66bf4640bebd1a53ccefc39596", "sha256": "79495b1e7ae866e6e0665379f9774d123b5b0a9e48b21e06ca843854d6224649" }, "downloads": -1, "filename": "pyduktape2-0.2.2.tar.gz", "has_sig": false, "md5_digest": "8f63ae66bf4640bebd1a53ccefc39596", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 917653, "upload_time": "2018-09-30T14:05:59", "url": "https://files.pythonhosted.org/packages/02/15/97d86596cdead6f2aed2d71996d3ee080295d804270c9cf31facf7b30bf2/pyduktape2-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "4f2226323348450eefee1716cc291854", "sha256": "3091e1be560f9798be1e06fd546ae29e6a694e3a236cd71f0d64ea19e7762cb6" }, "downloads": -1, "filename": "pyduktape2-0.2.3-cp36-cp36m-macosx_10_11_x86_64.whl", "has_sig": false, "md5_digest": "4f2226323348450eefee1716cc291854", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 370208, "upload_time": "2018-09-30T15:10:02", "url": "https://files.pythonhosted.org/packages/a5/ee/6f1a027c25bd29fa0c897d98db7ef67159de9c774b32805396fded26c93e/pyduktape2-0.2.3-cp36-cp36m-macosx_10_11_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "160845a670dd0a41b09b3edf5bde1eb4", "sha256": "6a335103d0ad5ab57013477f922b1a8117b678bd366c14d528efb82077a5155e" }, "downloads": -1, "filename": "pyduktape2-0.2.3.tar.gz", "has_sig": false, "md5_digest": "160845a670dd0a41b09b3edf5bde1eb4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 917686, "upload_time": "2018-09-30T14:58:43", "url": "https://files.pythonhosted.org/packages/e4/85/56966b8e1876434d5c31e7f3fc7a39e85802aac9c8d8ad707f6a524a54a2/pyduktape2-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "1bea4b9d7ba5b9dda872cefd245c4170", "sha256": "e53eb7b02231e9d9299d3f555c453710eb081415bf417109842069bbfc29fb38" }, "downloads": -1, "filename": "pyduktape2-0.2.4.tar.gz", "has_sig": false, "md5_digest": "1bea4b9d7ba5b9dda872cefd245c4170", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 916216, "upload_time": "2018-10-18T04:35:46", "url": "https://files.pythonhosted.org/packages/10/e4/2d000a1a5027762f674f7324455501427d199710e930288fbf8292639dda/pyduktape2-0.2.4.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "a7b9c200564f3b25dce49ff704613b3e", "sha256": "8bb4535143350bff1b74e5d54aa6b8924907164838bf85d39543a7a4513abbc6" }, "downloads": -1, "filename": "pyduktape2-0.3.0-py3.7-macosx-10.11-x86_64.egg", "has_sig": false, "md5_digest": "a7b9c200564f3b25dce49ff704613b3e", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 399409, "upload_time": "2019-07-30T14:00:26", "url": "https://files.pythonhosted.org/packages/18/18/d55e2b6ea887fdef6c34e6d72b4e7a3622871e561b85dd6abd13ded12f43/pyduktape2-0.3.0-py3.7-macosx-10.11-x86_64.egg" }, { "comment_text": "", "digests": { "md5": "ec5e16dc116c50808b79e55e5803087c", "sha256": "4a6e657074adc9249c862c669b12512e19dfaca4b7f053520d9f4afff77bca8c" }, "downloads": -1, "filename": "pyduktape2-0.3.0.tar.gz", "has_sig": false, "md5_digest": "ec5e16dc116c50808b79e55e5803087c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 916214, "upload_time": "2019-04-09T08:59:10", "url": "https://files.pythonhosted.org/packages/bc/33/8f44f6fd878b13d212f54004810c4dd6daeac83d1c02ec0339577f92e1de/pyduktape2-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "66f0dc7e37893fb17b1f5d3df48c5edb", "sha256": "af8988201c539529f92150bd96bdca6d8bd81682735b87ccad00d1d253b094a6" }, "downloads": -1, "filename": "pyduktape2-0.3.1-cp37-cp37m-macosx_10_11_x86_64.whl", "has_sig": false, "md5_digest": "66f0dc7e37893fb17b1f5d3df48c5edb", "packagetype": "bdist_wheel", "python_version": "cp37", "requires_python": null, "size": 398495, "upload_time": "2019-07-30T14:00:23", "url": "https://files.pythonhosted.org/packages/ae/24/1b9d3592a5bc2534c9c6611172120ca68383af38e60a70f1024c4bb897fd/pyduktape2-0.3.1-cp37-cp37m-macosx_10_11_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "1b88cfb8c35178b1f8489c0246301ff6", "sha256": "a65badf108cfdc58cf2253685f104936fe573b85e536d1c2f00c31e19b347ef1" }, "downloads": -1, "filename": "pyduktape2-0.3.1.tar.gz", "has_sig": false, "md5_digest": "1b88cfb8c35178b1f8489c0246301ff6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 921867, "upload_time": "2019-07-30T13:56:52", "url": "https://files.pythonhosted.org/packages/19/6e/09d22254a4a8eb5600675ed497468de4c114218d713dd1a5faa13c377c79/pyduktape2-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "66f0dc7e37893fb17b1f5d3df48c5edb", "sha256": "af8988201c539529f92150bd96bdca6d8bd81682735b87ccad00d1d253b094a6" }, "downloads": -1, "filename": "pyduktape2-0.3.1-cp37-cp37m-macosx_10_11_x86_64.whl", "has_sig": false, "md5_digest": "66f0dc7e37893fb17b1f5d3df48c5edb", "packagetype": "bdist_wheel", "python_version": "cp37", "requires_python": null, "size": 398495, "upload_time": "2019-07-30T14:00:23", "url": "https://files.pythonhosted.org/packages/ae/24/1b9d3592a5bc2534c9c6611172120ca68383af38e60a70f1024c4bb897fd/pyduktape2-0.3.1-cp37-cp37m-macosx_10_11_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "1b88cfb8c35178b1f8489c0246301ff6", "sha256": "a65badf108cfdc58cf2253685f104936fe573b85e536d1c2f00c31e19b347ef1" }, "downloads": -1, "filename": "pyduktape2-0.3.1.tar.gz", "has_sig": false, "md5_digest": "1b88cfb8c35178b1f8489c0246301ff6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 921867, "upload_time": "2019-07-30T13:56:52", "url": "https://files.pythonhosted.org/packages/19/6e/09d22254a4a8eb5600675ed497468de4c114218d713dd1a5faa13c377c79/pyduktape2-0.3.1.tar.gz" } ] }