Question:
Will there be a Python extension template? I have tried using JS and PyScript but that did not work. I also tried making a separate Python3 file to the HTML file.
Repl link:
https://replit.com/@SalladShooter/Versatile-Text-Extension-1
from colored import fg
import sys
colorR = fg('red')
colorO = fg('light_red')
colorL = fg('yellow')
colorG = fg('green')
colorB = fg('blue')
colorP = fg('purple_1a')
colorW = fg('white')
colorBl = fg('black')
def typingPrint(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.06)
def typingInput(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.06)
value = input()
return value
def br(times):
for i in range(times):
print()
There currently isn’t a Python API for extensions. You must use React, another web framework, or pure JS.
1 Like
@MiloCat with what I just researched is there a way to code the JS as Python 3 or not? The example was JS but acting as Python using a Python bridge.
2 Likes
You can use Pyscript to convert Python code to Javascript code:
You just need to include this into your HTML file:
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
You can check more about it here.
3 Likes
They said that they were not able to get pyscript to work with the extensions api.
1 Like
There isn’t a way without taking away many features/possibly breaking things. I suggest learning React and the bare minimum javascript. It isn’t very complicated, and you should be able to have basic understanding with a few hours of work.
You can look on youtube for a tutorial.
1 Like
Thanks @MiloCat I might look into that.
@MiloCat do you know if I would be able to make something similar to what I have and being able to use it in Python using React/JS?
I am wondering, in what way did it not work? Afaik someone has got it working for extensions.
1 Like
Oh well if u can that’s cool
That would just do that in the JavaScript console
Translating that to js should be simple
ask ChatGPT 
@MiloCat it is not really the same, as no one using your extension can see the JS console, and it is meant entirely for debugging, unlike the CLI
2 Likes
Yeah, but that translated to js would just put stuff in the console.
2 Likes
But things like pyscript have custom HTML/DOM consoles that the user can actually view, and have actual ansi code processing.
2 Likes
You can do all processing in the <py-script>
tag, but anything that has to do with the Replit API has to be done in Javascript.
3 Likes
I tried putting my code into PyScript both with Python 3 and I also converted it to JS and it still had errors with it.
@savardo here it my code for JS
import { fg } from 'colored';
import * as sys from 'sys';
var colorB, colorBl, colorG, colorL, colorO, colorP, colorR, colorW;
colorR = fg("red");
colorO = fg("light_red");
colorL = fg("yellow");
colorG = fg("green");
colorB = fg("blue");
colorP = fg("purple_1a");
colorW = fg("white");
colorBl = fg("black");
function typingPrint(text) {
for (var character, _pj_c = 0, _pj_a = text, _pj_b = _pj_a.length; _pj_c < _pj_b; _pj_c += 1) {
character = _pj_a[_pj_c];
sys.stdout.write(character);
sys.stdout.flush();
time.sleep(0.06);
}
}
function typingInput(text) {
var value;
for (var character, _pj_c = 0, _pj_a = text, _pj_b = _pj_a.length; _pj_c < _pj_b; _pj_c += 1) {
character = _pj_a[_pj_c];
sys.stdout.write(character);
sys.stdout.flush();
time.sleep(0.06);
}
value = input();
return value;
}
function br(times) {
for (var i = 0, _pj_a = times; i < _pj_a; i += 1) {
console.log();
}
}
You will have to add the <py-env>
tag above the <py-script>
tag and add the libraries in like so:
<py-env>
- colored
- sys
</py-env>
Also, if you want to include Javascript in your Python code, you can add import js
at the top of your code and run functions from it like js.myFunction()
. You do not need to add the library to the <py-env>
tag.
1 Like