{"id":18417769,"url":"https://github.com/danieljdufour/run-js","last_synced_at":"2025-04-07T12:32:50.845Z","repository":{"id":50659195,"uuid":"408992879","full_name":"DanielJDufour/run-js","owner":"DanielJDufour","description":"Goal: The Easiest Way to Run JavaScript in Python","archived":false,"fork":false,"pushed_at":"2022-08-05T23:24:29.000Z","size":50,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T18:51:25.514Z","etag":null,"topics":["javascript","library","package","python","python3","universal"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanielJDufour.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-21T22:34:15.000Z","updated_at":"2025-03-03T19:41:27.000Z","dependencies_parsed_at":"2022-09-14T16:40:09.848Z","dependency_job_id":null,"html_url":"https://github.com/DanielJDufour/run-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielJDufour%2Frun-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielJDufour%2Frun-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielJDufour%2Frun-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielJDufour%2Frun-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanielJDufour","download_url":"https://codeload.github.com/DanielJDufour/run-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247653385,"owners_count":20973820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","library","package","python","python3","universal"],"created_at":"2024-11-06T04:11:13.218Z","updated_at":"2025-04-07T12:32:50.063Z","avatar_url":"https://github.com/DanielJDufour.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# run-js\n\u003e Goal: The Easiest Way to Run JavaScript in Python\n\n# features\n- Stateless\n- Async JS Functions\n- No Intermediary Files\n- Functional Programming\n- CommonJS and ES6 Modules\n- Automatic JSON Conversion\n- Clear Installation Prompts\n\n# install\n```bash\npip install run-js\n```\n\n# usage\n```python\n# import the package from JavaScript into Python\nfrom js import lodash\n\n# access a function as an attribute\nresult = lodash.uniq([1, 2, 2, 3, 3, 3])\n# result is [1, 2, 3]\n```\n\n# video introduction\n[\u003cimg width=\"300\" alt=\"Screen Shot 2022-08-05 at 7 22 42 PM\" src=\"https://user-images.githubusercontent.com/4313463/183222966-ec7854ce-8b1e-4bdc-9538-4e192743a006.png\"\u003e](https://www.youtube.com/watch?v=m9gOaMBLkpk)\n\n# Frequently Asked Questions\n### what if my JavaScript package has a dash in the name?\nPython doesn't allow `-` in import statements, so `js` is also a dictionary.\n```python\nimport js\n\nfastMin = js['fast-min']\n\nresult = fastMin([1, 2, 2, 3, 3, 3])\n// result is 1\n```\n### do I need to understand JavaScript packaging?\nIf you try to run a JavaScript package and it isn't installed, run-js will automatically\nprovide you a prompt to install it.  You don't have to learn NPM's [package.json format](https://docs.npmjs.com/files/package.json/).\n\n### do I need to install NodeJS?\nYes, you currently must install NodeJS on your system before using run-js.  The NPM CLI is also required, but usually comes with the NodeJS installation.  If you are using MacOS, you can install it with `brew install node`.  We will try to add friendly prompts to install NodeJS in the future.  (It's a little complicated because of all the different platforms to support.)\n\n# limitations\n## only json-serializable input\nrun-js currently only supports running functions that accept JSON-serializable input. \nIn other words, you can only call a function that accepts numbers, string, arrays, and simple objects.\nYou can't pass functions or sets as a parameter. (We may try to fix this in the future, but only if it can be done securely.)\n\n## stateless\nFor security reasons, run-js doesn't keep a JavaScript process running in the background.  Therefore,\nyou can't chain JavaScript function calls.\n\n# more examples\n```python\nimport js\n\n# precise mathematics\njs.preciso.divide(\"1\", \"234\", { \"ellipsis\": True })\n'0.0042735042735042735...'\n\n# calculate statistics\njs['calc-stats']([291, 1723, 74, 741, 93, 84, 19])\n{ \"min\": 1, \"max\": 100, \"mean\": 66.25, \"median\": 70, \"mode\": 95, \"modes\": [90, 100], \"sum\": 328350, \"histogram\": { ... } }\n\n# run-length decoding\njs['fast-rle/decode']([5, 3, 1, 8, 2, 0])\n[3, 3, 3, 3, 3, 8, 0, 0]\n\n# reprojecting geospatial bounding boxes\njs[\"reproject-bbox\"]({\"bbox\": [-122.51, 40.97, -122.34, 41.11], \"from\": 4326, \"to\": 3857})\n[-13637750.817083945, 5007917.677222896, -13618826.503649088, 5028580.202823918 ]\n\n# clipping hyperrectangle (multi-dimensional rectangle) from imagery data\njs['xdim'].clip({ \"data\": [0, 123, 123, 255, ...], \"layout\": \"[row,column,band]\", \"sizes\": {\"band\": 4, \"row\": 768, \"column\": 1024 }, \"rect\": { \"band\": [2,2], \"row\": [20, 219], \"column\": [47, 211]}})\n[213, 542, 521, 481, ...]\n```\n\n# necessary disclaimer\nUse at your own risk.\n\n# thanks\nThis project was partially inspired by the awesome Python package called [sh](https://github.com/amoffat/sh).\n\n# support\nEmail the library author at daniel.j.dufour@gmail.com or post an issue at https://github.com/DanielJDufour/run-js/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanieljdufour%2Frun-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanieljdufour%2Frun-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanieljdufour%2Frun-js/lists"}