npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jspython-interpreter

v2.1.15

Published

JSPython is a javascript implementation of Python language that runs within web browser or NodeJS environment

Downloads

308

Readme

JSPython

JSPython is a python-like syntax interpreter implemented with javascript that runs entirely in the web browser and/or in the NodeJS environment.

It does not transpile/compile your code into JavaScript, instead, it provides an interactive interpreter that reads Python code and carries out their instructions. With JSPython you should be able to safely use or interact with any JavaScript libraries or APIs in a nice Python language.

arr = [4, 9, 16]

def sqrt(a):
 return Math.sqrt(a)

# use Array.map() with Python function
roots = arr.map(sqrt).join(",")

# use Array.map() or use arrow function
roots = arr.map(i => Math.sqrt(i)).join(",")

Try out JSPython in the wild

Interactive Worksheet Systems JSPython editor with an ability to query REST APIs and display results in Object Explorer, a configurable Excel-like data grid or just as a JSON or text.

Why would you use it?

You can easily embed JSPython into your web app and your end users will benefit from a Python-like scripting facility to:

  • to build data transformation and data analysis tasks
  • allow users to configure JS objects at run-time
  • run a comprehensive testing scenarios
  • experiment with your JS Libraries or features.
  • bring a SAFE run-time script evaluation functions to your web app
  • bring Python language to NodeJS environment

Features

Our aim here is to provide a SAFE Python experience to Javascript or NodeJS users at run-time. So far, we implement a core set of Python feature which should be OK to start coding.

  • Syntax and code flow Same as Python, In JSPython we use indentation to indicate a block of code. All flow features like if - else, for, while loops - along with break and continue

  • Objects, Arrays JSPython allows you to work with JavaScript objects and arrays and you should be able to invoke their methods and properties as normal. So, all methods including prototype functions push(), pop(), splice() and many more will work out of box.

  • JSON JSPython allows you to work with JSON same way as you would in JavaScript or Python dictionaries

  • Functions Functions def def async def, arrow functions => - (including multiline arrow functions)

  • Strings Syntax and code flow s = "Strings are double quoated only! For now." represent a multiline string. A single or triple quotes are not supported yet.

  • Date and Time We have dateTime() function what returns JavaScript's Date object. So, you can use all Date get and set methods

  • None, null null and None are synonyms and can be used interchangeably

JSPython distinctive features

We haven't implemented all the features available in Python yet. However, we do already have several useful and distinctive features that are popular in other modern languages, but aren't in Python:

  • A single line arrow functions => (no lambda keyword required)
  • A multiline arrow function =>. Particularly useful when building data transformation pipelines
  • Null conditioning (null-coalescing) myObj?.property?.subProperty or "N/A".

Quick start

Zero install ! The simplest way to get started, without anything to install, is to use the distribution available online through jsDelivr. You can choose the latest stable release :

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jspython-interpreter/dist/jspython-interpreter.min.js">
</script>

Or local install

npm install jspython-interpreter

Run JS Python from your Javascript App or web page.

Basic

  jsPython()
    .evaluate('print("Hello World!")')
    .then(
        r => console.log("Result => ", r),
        e => console.log("Error => ", error)
    )

Or with your own data context and custom function:

  const script = `
  x = [1, 2, 3]
  x.map(r => add(r, y)).join(",")
  `;
  const context = {y: 10}

  const result = await jsPython()
    .addFunction("add", (a, b) => a + b)
    .evaluate(script, context);
  // result will be a string "11,12,13"

Also, you can provide an entire JS Object or even a library.

Run JSPython in a NodeJS with JSPython-CLI

JSPython-cli is a command line tool what allows you to run JSPython in NodeJS environment

License

A permissive BSD 3-Clause License (c) FalconSoft Ltd.