What is PYSCRIPT?

Pyscript is a library which uses python functions inside JavaScript. What is "Py" stands for? "Python"? YES!!! What is Script? as you know well, guess it... YES!!! it's JavaScript. It is nothing big, It's all just plain JavaScript.

 

Use plain JavaScript

There is no website which don't has JavaScript. It's just JavaScript.
 

Fast development time

No time consuming. its all just your favourite language. It's JS.
 

Simple syntax

Isn't it? You will say yes, if you are a Python Developer. Just go for it.

Features

Get Started

Install

It's easy to install PYSCRIPT with NPM.

$ npm i pyscript-js

Use

Pass PYSCRIPT string and some data. Great! you've got some Python functions.

const py = require("pyscript-js");
let a = py.type("2");
py.print(a);

Browser support

Download a browser build from the latest release, and use it in a script tag.

<script src="pyscript.js"></script>
<script type="text/javascript">
  print("Hello User!")  // inspect -> console tab
</script>

Docs

Example

index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>PyScript.js</title>
</head>
<body>

  <!-- Your HTML Code Goes Here -->

  ...

  <!-- End -->

  <!-- Adding Scripts -->
  <!-- Use it above all the Script Files to make use of python functions -->
  <script src="https://cdn.jsdelivr.net/npm/pyscript-js@1.2.5/dist/js/pyscript.min.js" charset="utf-8"></script>
  
  <!-- User Defined Scripts / Other Scripts below -->
  <script src="script.js" charset="utf-8"></script>
  <script type="text/javascript">
          print("Hello User!")  // inspect -> console tab
     </script>
</body>
</html>


script.js
// program to generate fibonacci series up to n terms

// take input from the user
number = int(input('Enter the number of terms: '));
n1 = 0,
n2 = 1,
nextTerm = 0;

print('Fibonacci Series:');

for (let i = 1; i <= number; i++) {
      print(n1);
      nextTerm = n1 + n2;
      n1 = n2;
      n2 = nextTerm;
}
            

CDN

<script src="https://cdn.jsdelivr.net/npm/pyscript-js@1.2.5/dist/js/pyscript.min.js" charset="utf-8"></script>

Options

Python functions available in JavaScript

Indicates that the functions doesn't support in NodeJs. See Tutorial

Python Imediate Functions
  • input()
  • print()
  • jsprint()
  • int()
  • float()
  • str()
  • chr()
  • chr([ ])
  • ascii()
  • hex()
  • len()
  • round()
  • max()
  • min()
  • sum()
  • sorted()
  • type()
  • pow()
  • abs()
  • range()New
Random Class
  • random.randint()
  • random.randrange()
  • random.choice()
  • random.shuffle()
Dot Functions
  • " ".upper()
  • " ".lower()
  • " ".title()
  • " ".capitalize()
  • [ ].append()
  • [ ].extend()
  • [ ].index()
  • " ".index()
  • [ ].insert()
  • [ ].clear()
  • [ ].count()
  • [ ].remove()
  • [ ].copy()
Built-in Functions
  • " ".join()
  • " ".split()
  • [ ].sort()
  • [ ].pop()
  • [ ].reverse()
Play Around Functions
  • " ".charList()
  • " ".wordList()
En-glishers New
  • alphabet()
  • vowels()
  • consonants()

Support

GitHub

The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests.

License

PYSCIRPT is licensed under the MIT License. Information can found here: MIT.

Backend Developers

Become a backend developer click here