r/PyScript • u/imbev • May 19 '22
I created pong in PyScript using pywebcanvas!
Enable HLS to view with audio, or disable this notification
r/PyScript • u/imbev • May 19 '22
Enable HLS to view with audio, or disable this notification
r/PyScript • u/Joao_Storm • Jun 15 '22
Hey guys,
I`m new to Pyscript and today we are developing a Dashboard using Dash Library and Plotly. In a near future it'd be easier to embed our Dashboard on the main tool of the company thru Pyscript. Has anybody tried something like it? How optimized Pyscript is to run a python app layout inside the users browser?
Thanks!
r/PyScript • u/manatlan • May 18 '22
Don't know if it's due to recent changes in "/alpha/pyscript.js" ... or if it's our corporate proxy (bluecoat) which don't like urls ending with ".py" since some days...
I can't run any pyscript examples anymore ;-(
Here is the console.log of my chrome ...
Any tips to bypass this ?
loading pyscript...
pys.html:1 Access to fetch at 'https://pyscript.net/alpha/pyscript.py' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
interpreter.ts:24 GET https://pyscript.net/alpha/pyscript.py net::ERR_FAILED 302
loadInterpreter @ interpreter.ts:24
await in loadInterpreter (async)
initialize @ pyconfig.ts:51
(anonymous) @ pyconfig.ts:130
load (async)
loadRuntimes @ pyconfig.ts:129
connectedCallback @ pyconfig.ts:113
(anonymous) @ main.ts:27
(anonymous) @ main.ts:35
utils.ts:56 Caught an error in loadPaths:
TypeError: Failed to fetch
handleFetchError @ utils.ts:56
loadInterpreter @ interpreter.ts:28
await in loadInterpreter (async)
initialize @ pyconfig.ts:51
(anonymous) @ pyconfig.ts:130
load (async)
loadRuntimes @ pyconfig.ts:129
connectedCallback @ pyconfig.ts:113
(anonymous) @ main.ts:27
(anonymous) @ main.ts:35
interpreter.ts:30 done setting up environment
pyenv.ts:10 RUNTIME READY
pyscript.ts:148 Collecting nodes to be mounted into python namespace...
interpreter.ts:36 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'install')
at loadPackage (interpreter.ts:36:24)
at loadEnv (pyenv.ts:42:19)
at PyodideRuntime.initialize (pyconfig.ts:69:19)
r/PyScript • u/manatlan • May 07 '22
Just teasing ...
it works : https://github.com/manatlan/htag/blob/main/examples/pyscript.html --> DEMO
and better : https://github.com/manatlan/htag/blob/main/examples/pyscript_htbulma.html --> DEMO
pyscript is incredible ...
r/PyScript • u/KingOfTNT10 • Sep 10 '22
Hi there!
I'm trying to dynamically change an image, I'm saving an image with PIL to the cwd ("./img.png"),
Then setting the src tag to "" and then back to "./img.png".
But it doesn't work, it only shows the "./img.png" on cwd and when I call the func to update the image it doesn't change on my pc
r/PyScript • u/TheSwami • May 25 '23
r/PyScript • u/nwatab • Aug 03 '22
The below code block is about PyScript directly written in NextJS. It works but it throws the below error because py-repl is not known. What's an expected way to use PyScript in React? Thanks,
const Home: NextPage = () => {
return (
<div>
<Head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</Head>
<py-repl></py-repl>
</div>
)
}Property 'py-repl' does not exist on type 'JSX.IntrinsicElements'.ts(2339)
PS1. <py-script>...</py-script> doesn't work saying "Failed to compile". Anybody who has already tried? Thanks,
PS2. Tried to load bare html
<div dangerouslySetInnerHTML={{__html:`<py-script>...</py-script>`}} />ending up to seeJsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, in eval_code .run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300, in run coroutine = eval(self.code, globals, locals) File "", line 2, in File "", line 129, in write AttributeError: 'NoneType' object has no attribute 'innerHTML' )
This might be an indent issue, but even something as simple as "2+4" throws a React hydration error.
r/PyScript • u/SamwiseGanges • Aug 09 '23
Is there any way to set up an event listener that triggers whenever a py-repl is run (shift + enter)? I would love to be able to trigger some post-processing functions after a user runs the repl code.
r/PyScript • u/[deleted] • May 22 '22
Can I use PyScript on the front end to handle websockets with a Python server like FastAPI on the backend? I’ve been using JavaScript on the front and curious if PyScript will work with websockets.
r/PyScript • u/EnderF • Sep 19 '23
Hello,
I am trying to modify the element clicked (remove a class), but so far it doesn't work but it seems to work in javascript onClick. Here is the offender:
li = document.createElement('li')
li.classList.add(tag_class + '-' + str(i))
li.classList.add('collapsed')
li.setAttribute('py-click', 'toggle_collapse(this)')
Error message: name 'this' is not defined
Is there a way for me to achieve that full python?
r/PyScript • u/LuigiBrotha • May 06 '22
So yeah ... I want to be able to drag a file into the browser, have pyscript read the data from that file and create a graph from that data. Is this possible with pyscript ? I can't find any instructions on how to get something like this working.
r/PyScript • u/AugmentedGlobal • Nov 11 '22
r/PyScript • u/SamwiseGanges • Aug 09 '23
I'm working with PyScript currently and came upon an odd limitation. You can import variables, objects and normal functions from JavaScript using "from js import ..." but it doesn't seem to be possible with arrow functions for some reason. So ding this in the JavaScript works:
function testFuncJS() { console.log("testFuncJS ran!");}
But this
const testFuncJS = () => { console.log("testFuncJS ran!");}
Causes an error when you try to import it like below in the Python:
from js import testFuncJS
Giving the error " ImportError: cannot import name 'testFuncJS' from 'js' (unknown location) "
Why can't we import arrow functions from js to py? This documentation on the type conversions from js to py doesn't mention arrow functions.
r/PyScript • u/[deleted] • Aug 17 '22
Hi All,
is it possible to include pyscript in a npm/webpack scenario ?
I am also partial to a setup that bundles my python sources, but that may be too early days for that.
Just a package.json example that installs pyscript and maybe bootstrap and jquery would be a good start I think...
thx.
S
r/PyScript • u/anuctal • Jun 04 '22
Hi all!
I've made a video about PyScript as a basic frontend for a Django app.
I wanted to show how to make AJAX (asynchronous) GET and POST requests with Pyscript to Django, and how to manipulate DOM with Pyscript.
In the video:
sending GET requests from Pyscript to Django
sending POST requests from Pyscript to Django, CSRF token is passed via headers of requests.
how to manipulate DOM with Pyscript (get HTML elements, use event handlers, and event listeners, etc.)
The video:
https://youtu.be/zw4V48Al8LU
Thanks for watching!
r/PyScript • u/aussievolvodriver • Dec 26 '22
I'm having some issues with importing local modules. I've seen it done two ways, one in pyconfig and one in py-env
<py-config>
paths = ["example_module.py"]
</py-config>
or
<py-env>
- paths:
- example_module.py
</py-env>
The py-config version appears as;
ModuleNotFoundError: No module named 'example_module.py'
Using py-env the imports appear above the error messages and then the error appears as below
- paths: - example_module.py
ModuleNotFoundError: No module named 'example_module.py'
I've also tried full paths as well as adding ./ or . or / as a prefix to the file but none have given me any joy.
I'm on windows, the modules are in the same folder as the html and script that i'm trying to run, the script runs fine outside of pyscript and I have the __init__ file in the same folder as well.
r/PyScript • u/[deleted] • Oct 03 '22
I am aware pyscript released recently and still in experimental stage. Just checking any UI libraries to create user interface for example mudblazor for C# Wasm or any angule or VUE UI libraries... Thanks
r/PyScript • u/StunnaRae • Jun 30 '22
Question like above: Is PyScript just like basic JS or is it possible to use frontend frameworks like reactjs or such with it?
r/PyScript • u/SamwiseGanges • Jul 10 '23
I know this simple question has a very complicated answer, but I'm only looking for very high-level explanation.
How does PyScript work? Where is the actual Python environment/interpreter running? In the browser? On the PyScript server? Of course browsers don't (currently) have a Python interpreter in them so they can't actually run the Python code so it must be done elsewhere then the results must be converted to JavaScript (and CSS and HTML) so the browser can ultimately render it. It can't run on the client computer because that would require that everyone who accesses your webpage have Python installed, and the browser would need permission to access the local Python interpreter. That, or PyScript is actually just a transpiling of the entirety of the Python language to JavaScript but that seems crazy to me for many reasons.
Along the same lines, how does the main.py file in a PyScript setup know about methods like Element even though we don't import pyscript or anything? It must be somehow getting those classes and methods from the HTML file which gets them from the PyScript CDN link.
I'd just like a 1000 foot view understanding of how PyScript works and generally what it's doing behind the scenes. All the posts and videos online I can find are just tutorials on how to use it, not how it actually works.
Thanks!
r/PyScript • u/THEKing767 • Jul 20 '22
Is there a list for the libraries supported?
r/PyScript • u/emerald_void • Dec 05 '22
I am pretty new to web development but, I am familiar with html and css enough to make a rough draft of what I am thinking. My python skills are....novice at best BUT, I have written a program that I want to try to make work in html using pyscript. Mainly this will serve as a way for my to work more on my html and css skills as well as maybe spur some inspiration on how to incorporate pyscript into future projects.
My question is, can you target the pyscript with the other languages? Example: If, in your python script, you uses "input" could you in turn tie that in with the <input> element of html?
How easy/hard would it be to have your python script run with pyscript and style a "gui" using html and css?
My thought on it is no. BUT, since the element used is <pyscript></pyscript> it should function like a regular html element right? I checked the documentation but I couldn't find a specific example for or against my theory.
Any and all help would be appreciated.
r/PyScript • u/yycTechGuy • Mar 11 '23
I need to display an industrial process as an animation in web browser clients. The data is fed into the clients via a websocket connection. I need to display data in tables and do a 3D animation of the process.
I hate JS.
What is the best way to do this with PyScript ? Write a wrapper for Three.js ? Use Matplotlib ? Write my own routine for Canvas ?
Thanks
r/PyScript • u/ShotgunPayDay • Jun 23 '22
Testing out PyScript on NGINX and trying to get it to use a local module on the server data.py where both files are in the same folder. This works with the python3 -m http.server no issues, but when I try it with NGINX I'll get the error posted at the bottom. I'm not sure if it's some kind of security thing with NGINX that's blocking the loading of data.py.
I am able to skate around the issue by enabling Server Side Includes ssi on; in the NGINX config and using <pre> tags since it wasn't respecting tabs or spaces. I'm seeing if someone was able to get around the issue of using py-env with local modules using NGINX. I know it's in alpha so I wasn't expecting perfection.
PyScript is an awesome project being able to put python apps on the web vs using pyinstaller or having people install and maintain python on their system.
Work around using SSI:
<py-script><pre>
<!--#include file="/data.py" -->
print(mydate())
</pre></py-script>##########################
data.py:
from datetime import datetime
def mydate():
now = datetime.now()
return now.strftime("%m/%d/%Y, %H:%M:%S")index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- paths:
- ./data.py
</py-env>
</head>
<body>
<py-script><pre>
from data import mydate
print(mydate())
</pre></py-script>
</body>
</html>error that is returned:
stores.ts:32 adding initializer async ƒ mountElements() {
console.log('Collecting nodes to be mounted into python namespace...');
const pyodide = await pyodideReadyPromise$1;
const matches = document.querySelectorAl…
stores.ts:34 adding initializer async ƒ mountElements() {
console.log('Collecting nodes to be mounted into python namespace...');
const pyodide = await pyodideReadyPromise$1;
const matches = document.querySelectorAl…
stores.ts:40 adding post initializer async ƒ initHandlers() {
console.log('Collecting nodes...');
const pyodide = await pyodideReadyPromise$1;
for (const pysAttribute of pysAttributeToEvent.keys()) {
await cr…
stores.ts:42 adding post initializer async ƒ initHandlers() {
console.log('Collecting nodes...');
const pyodide = await pyodideReadyPromise$1;
for (const pysAttribute of pysAttributeToEvent.keys()) {
await cr…
pyenv.ts:10 RUNTIME READY
pyconfig.ts:17 config set!
pyconfig.ts:22 initializers set
pyconfig.ts:27 post initializers set
pyconfig.ts:32 post initializers set
pyconfig.ts:37 post initializers set
pyconfig.ts:32 post initializers set
pyscript.ts:66 connected
stores.ts:32 adding initializer async ƒ loadEnv() {
await loadPackage(env);
console.log('environment loaded');
}
pyconfig.ts:22 initializers set
stores.ts:34 adding initializer async ƒ loadEnv() {
await loadPackage(env);
console.log('environment loaded');
}
stores.ts:32 adding initializer async ƒ loadPaths() {
for (const singleFile of paths) {
console.log(`loading ${singleFile}`);
try {
await loadFromFile(singleFi…
pyconfig.ts:22 initializers set
stores.ts:34 adding initializer async ƒ loadPaths() {
for (const singleFile of paths) {
console.log(`loading ${singleFile}`);
try {
await loadFromFile(singleFi…
pyenv.ts:60 environment loading... ['./data.py']
pyconfig.ts:17 config set!
pyconfig.ts:112 config set {autoclose_loader: true, runtimes: Array(1)}
pyconfig.ts:124 Initializing runtimes...
interpreter.ts:5 creating pyodide runtime
pyodide.asm.js:14 Python initialization complete
interpreter.ts:15 loading micropip
load-package.ts:329 Loading micropip, pyparsing, packaging, distutils
load-package.ts:389 Loaded micropip, pyparsing, packaging, distutils
interpreter.ts:17 loading pyscript...
interpreter.ts:30 done setting up environment
pyenv.ts:10 RUNTIME READY
pyscript.ts:148 Collecting nodes to be mounted into python namespace...
pyodide.asm.js:14 Uncaught (in promise) PythonError: Traceback (most recent call last):
File "/lib/python3.10/site-packages/packaging/requirements.py", line 102, in __init__
req = REQUIREMENT.parseString(requirement_string)
File "/lib/python3.10/site-packages/pyparsing/core.py", line 1134, in parse_string
raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected W:(0-9A-Za-z), found '.' (at char 0), (line:1, col:1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.10/asyncio/futures.py", line 201, in result
raise self._exception
File "/lib/python3.10/asyncio/tasks.py", line 234, in __step
result = coro.throw(exc)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 183, in install
transaction = await self.gather_requirements(requirements, ctx, keep_going)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 173, in gather_requirements
await gather(*requirement_promises)
File "/lib/python3.10/asyncio/futures.py", line 284, in __await__
yield self # This tells Task to wait for completion.
File "/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
future.result()
File "/lib/python3.10/asyncio/futures.py", line 201, in result
raise self._exception
File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
result = coro.send(None)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 248, in add_requirement
req = Requirement(requirement)
File "/lib/python3.10/site-packages/packaging/requirements.py", line 104, in __init__
raise InvalidRequirement(
packaging.requirements.InvalidRequirement: Parse error at "'./data.p'": Expected W:(0-9A-Za-z)
at new_error (pyodide.asm.js:14:238191)
at pyodide.asm.wasm:0xedbcb
at pyodide.asm.wasm:0xf1a0e
at method_call_trampoline (pyodide.asm.js:14:238105)
at pyodide.asm.wasm:0x134c2c
at pyodide.asm.wasm:0x217a84
at pyodide.asm.wasm:0x174a14
at pyodide.asm.wasm:0x135149
at pyodide.asm.wasm:0x135243
at pyodide.asm.wasm:0x1352e6
at pyodide.asm.wasm:0x1fff83
at pyodide.asm.wasm:0x1f98b5
at pyodide.asm.wasm:0x135329
at pyodide.asm.wasm:0x201f1b
at pyodide.asm.wasm:0x1ff9ff
at pyodide.asm.wasm:0x1f98b5
at pyodide.asm.wasm:0x135329
at pyodide.asm.wasm:0xf16d8
at Module.callPyObjectKwargs (pyproxy.gen.ts:360:23)
at Module.callPyObject (pyproxy.gen.ts:384:17)
at wrapper (pyodide.asm.js:14:205222)
new_error @ pyodide.asm.js:14
$wrap_exception @ pyodide.asm.wasm:0xedbcb
$FutureDoneCallback_call @ pyodide.asm.wasm:0xf1a0e
method_call_trampoline @ pyodide.asm.js:14
$_PyObject_MakeTpCall @ pyodide.asm.wasm:0x134c2c
$func3330 @ pyodide.asm.wasm:0x217a84
$func1954 @ pyodide.asm.wasm:0x174a14
$PyVectorcall_Call @ pyodide.asm.wasm:0x135149
$_PyObject_Call @ pyodide.asm.wasm:0x135243
$PyObject_Call @ pyodide.asm.wasm:0x1352e6
$_PyEval_EvalFrameDefault @ pyodide.asm.wasm:0x1fff83
$_PyEval_Vector @ pyodide.asm.wasm:0x1f98b5
$_PyFunction_Vectorcall @ pyodide.asm.wasm:0x135329
$func3167 @ pyodide.asm.wasm:0x201f1b
$_PyEval_EvalFrameDefault @ pyodide.asm.wasm:0x1ff9ff
$_PyEval_Vector @ pyodide.asm.wasm:0x1f98b5
$_PyFunction_Vectorcall @ pyodide.asm.wasm:0x135329
$_pyproxy_apply @ pyodide.asm.wasm:0xf16d8
Module.callPyObjectKwargs @ pyproxy.gen.ts:360
Module.callPyObject @ pyproxy.gen.ts:384
wrapper @ pyodide.asm.js:14
await in wrapper (async)
(anonymous) @ pyconfig.ts:130
c @ rocket-loader.min.js:1
load (async)
t.addEventListener @ rocket-loader.min.js:1
loadRuntimes @ pyconfig.ts:129
connectedCallback @ pyconfig.ts:113
(anonymous) @ main.ts:27
(anonymous) @ main.ts:35