run-js Goal: The Easiest Way to Run JavaScript in Python

Overview

run-js

Goal: The Easiest Way to Run JavaScript in Python

features

  • Stateless
  • Async JS Functions
  • No Intermediary Files
  • Functional Programming
  • CommonJS and ES6 Modules
  • Automatic JSON Conversion
  • Clear Installation Prompts

install

pip install run-js

usage

# import the package from JavaScript into Python
from js import lodash

# access a function as an attribute
result = lodash.uniq([1, 2, 2, 3, 3, 3])
# result is [1, 2, 3]

Frequently Asked Questions

what if my JavaScript package has a dash in the name?

Python doesn't allow - in import statements, so js is also a dictionary.

import js

fastMin = js['fast-min']

result = fastMin([1, 2, 2, 3, 3, 3])
// result is 1

do I need to understand JavaScript packaging?

If you try to run a JavaScript package and it isn't installed, run-js will automatically provide you a prompt to install it. You don't have to learn NPM's package.json format.

do I need to install NodeJS?

Yes, 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.)

limitations

only json-serializable input

run-js currently only supports running functions that accept JSON-serializable input. In other words, you can only call a function that accepts numbers, string, arrays, and simple objects. You 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.)

stateless

For security reasons, run-js doesn't keep a JavaScript process running in the background. Therefore, you can't chain JavaScript function calls.

more examples

import js

# calculate statistics
js['calc-stats']([291, 1723, 74, 741, 93, 84, 19])
{ "min": 1, "max": 100, "mean": 66.25, "median": 70, "mode": 95, "modes": [90, 100], "sum": 328350, "histogram": { ... } }

# run-length decoding
js['fast-rle/decode']([5, 3, 1, 8, 2, 0])
[3, 3, 3, 3, 3, 8, 0, 0]

# reprojecting geospatial bounding boxes
js["reproject-bbox"]({"bbox": [-122.51, 40.97, -122.34, 41.11], "from": 4326, "to": 3857})
[-13637750.817083945, 5007917.677222896, -13618826.503649088, 5028580.202823918 ]

# clipping hyperrectangle (multi-dimensional rectangle) from imagery data
js['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]}})
[213, 542, 521, 481, ...]

necessary disclaimer

Use at your own risk.

thanks

This project was partially inspired by the awesome Python package called sh.

support

Email the library author at [email protected] or post an issue at https://github.com/DanielJDufour/run-js/issues

Owner
Daniel J. Dufour
builds geotiff.io, geoblaze.io, georaster, georaster-layer-for-leaflet, date-extractor, geotiff-stats; built code.gov, and maintains proj4js/mgrs
Daniel J. Dufour
Customizable-menu-python - User customizable menu in Python

Menu personalizável pelo usuário em Python A minha ideia com esse projeto pessoa

Renan Barbosa 4 Oct 28, 2022
Procedural 3D data generation pipeline for architecture

Synthetic Dataset Generator Authors: Stanislava Fedorova Alberto Tono Meher Shashwat Nigam Jiayao Zhang Amirhossein Ahmadnia Cecilia bolognesi Dominik

Computational Design Institute 49 Nov 25, 2022
Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls

password-generator Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls Password generator

Amir Hussein Sharifnezhad 3 Oct 09, 2021
A simple project which is a ecm to found a good way to provide a path to img_dir in gooey

ECM to find a good way for img_dir Path in Gooey This code is just an ECM to find a good way to indicate a path of image in image_dir variable. We loo

Jean-Emmanuel Longueville 1 Oct 25, 2021
A python script providing an idea of how a MindSphere application, e.g., a dashboard, can be displayed around the clock without the need of manual re-authentication on enforced session expiration

A python script providing an idea of how a MindSphere application, e.g., a dashboard, can be displayed around the clock without the need of manual re-authentication on enforced session expiration

MindSphere 3 Jun 03, 2022
Python implementation of the ASFLIP advection method

This is a python implementation of the ASFLIP advection method . We would like to hear from you if you appreciate this work.

Raymond Yun Fei 133 Nov 13, 2022
Advanced IPv4 Subnet Calculator in Python3

Advanced IPv4 Subnet Calculator in Python3 Table of Contents Getting Started Installation How it works? SVI Configuration Template Previews Getting St

Osama Abbas 1 May 10, 2022
Block fingerprinting for the beacon chain, for client identification & client diversity metrics

blockprint This is a repository for discussion and development of tools for Ethereum block fingerprinting. The primary aim is to measure beacon chain

Sigma Prime 49 Dec 08, 2022
Simple calculator with random number button and dark gray theme created with PyQt6

Calculator Application Simple calculator with random number button and dark gray theme created with : PyQt6 Python 3.9.7 you can download the dark gra

Flamingo 2 Mar 07, 2022
The little-endian version of MessagePack

MessagePackEL This is the little-endian version of MessagePack, except the endianness is different, the rest is exactly the same as MessagePack. C lib

dukelec 9 May 13, 2022
Stori QA Automation Challenge

Stori-QA-Automation-Challenge This is the repository is created for the Stori QA Intern Automation Engineer Challenge! In this you can find the Requir

Daniel Castañeda 0 Feb 20, 2022
Final Fantasy XIV Auto House Clicker

Final Fantasy XIV Auto House Clicker

KanameS 0 Mar 31, 2022
A function decorator for enforcing function signatures

A function decorator for enforcing function signatures

Emmanuel I. Obi 0 Dec 08, 2021
Plugins for Agisoft Metashape

Данные плагины предназначены для расширения функциональных возможностей Agisoft Metashape. Плагины представляют собой отдельные программы с собственным интерфейсом, которые запускаются внутри Agisoft

GeoScan 17 Dec 10, 2022
Access Modbus RTU via API call to Sungrow WiNet-S

SungrowModbusWebClient Access Modbus RTU via API call to Sungrow WiNet-S Class based on pymodbus.ModbusTcpClient, completely interchangeable, just rep

8 Oct 30, 2022
Tensorboard plugin 3d with python

tensorboard-plugin-3d Overview In this example, we render a run selector dropdown component. When the user selects a run, it shows a preview of all sc

KitwareMedical 26 Nov 14, 2022
CalHacks 8 Repo: Megha Jain, Gaurav Bhatnagar, Howard Meng, Vibha Tantry

CalHacks8 CalHacks 8 Repo: Megha Jain, Gaurav Bhatnagar, Howard Meng, Vibha Tantry Setup FE Install React Native via Expo, run App.js. Backend Create

0 Aug 20, 2022
🇮🇳 A Indian Flag Animation Project Made With Python

🇮🇳 A Indian Flag Animation Project Made With Python

MuFaz-TG 2 Oct 21, 2022
Open Source defrag's mod code

Open Source defrag's mod code Goals: Code & License: Respect FOSS philosophy. Open source and community focus. Eliminate all traces of q3a-sdk licensi

sOkam! 1 Dec 10, 2022
Blender-3D-SH-Dma-plugin - Import and export Sonic Heroes Delta Morph animations (.anm) into Blender 3D

io_scene_sonic_heroes_dma This plugin for Blender 3D allows you to import and ex

Psycrow 3 Mar 22, 2022