Open Source Adventures: Episode 58: PyScript: First Impressions

An alpha model of PyScript simply got here out, with tagline “Run Python in Your HTML”. Let’s test it out.

Documentation is generally all improper, so there’s numerous steps to get it even working.


The obtain directions are:

  • Obtain PyScript now
  • Unzip the downloaded file
  • Copy the property you wish to use and add the next traces to your html file

There’s only one drawback, there are not any asset information in that zip.

So as a substitute we have to manually obtain and as a substitute.

That nevertheless doesn’t work, because it then crashes making an attempt to get, so we have to get as effectively.

Native server

I attempted simply making a Whats up World HTML and opening it as a neighborhood file, however that received into instantaneous CORS error.

It is sadly an increasing number of widespread with something that makes use of fashionable internet applied sciences.

Fortuitously Python comes with a builtin HTTP server, so we are able to run python3 -m http.server 8080 after which open http://localhost:8080/howdy.html

Whats up, World!

OK, with that out of the way in which, let’s write the only potential Python script:

<!DOCTYPE html>
  <meta charset="utf-8" />
  <meta identify="viewport" content material="width=device-width, initial-scale=1" />
  <title>Whats up World</title>
  <hyperlink rel="stylesheet" href="./pyscript.css" />
  <script defer src="./pyscript.js"></script>
    print("Whats up World")
Enter fullscreen mode

Exit fullscreen mode

If opened from native server, it at the very least now not will get any errors within the community tab.

What occurs then is that about 10% of time I get “Whats up World” printed. And 90% of time there’s an error in console like this:

JsException: SyntaxError: Did not execute 'querySelector' on 'Doc': '#-49bea52c-4893-412d-cba1-447d24c65f0a' isn't a sound selector.
Enter fullscreen mode

Exit fullscreen mode

And solely a pink bar within the doc. I believed it is likely to be some points with some Chrome Extensions, so I attempted it in an incognito window or in Safari, identical factor.

It’s totally clearly some race situation.

Do you have to use PyScript?

Clearly not but.

Coming subsequent

All the code is on GitHub.

I wish to come again to PyScript in some unspecified time in the future, however within the subsequent episode we’ll really check out Opal Ruby, which just lately received 1.5 launch.

Add a Comment

Your email address will not be published. Required fields are marked *