| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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(",")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.
You can easily embed JSPython into your web app and your end users will benefit from a Python-like scripting facility to:
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
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:
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.
jsPython()
.evaluate('print("Hello World!")')
.then(
r => console.log("Result => ", r),
e => console.log("Error => ", error)
) 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.
JSPython-cli is a command line tool what allows you to run JSPython in NodeJS environment
A permissive BSD 3-Clause License (c) FalconSoft Ltd.
| Back | FazBrowse Home | New Git URL |