A recent article by Luciano Abriata criticized PyScript. He made two statements:
- Pyscript is way too slow and heavy to load.
- Does not support all of Python’s features and libraries.
He then provided two example programs link and link. The first is written using the Google JavaScript Chart library and the second using the Python Bokeh library. He went on to state how much better the example using the Google JavaScript Chart library is. To quote his statement:
“Note that, moreover, this is not just a static graph but it is interactive: you can zoom in and out, get information when you hover over the bars, etc. None of this is possible in PyScript as of today’s version.”
I took his JavaScript example written to use the Google JavaScript Chart library and ported it to Python. This took about 10 minutes.
I put the port on my website: Google Chart Example.
As you can visually confirm, my PyScript example is identical to his JavaScript example in appearance and behavior with the exception of the PyScript load time (2 seconds on my system).
Summary
When critiquing a technology, it is important to have a solid understanding of the technology and how to use it. If your objective is to find fault, you will of course focus on weaknesses and overlook the strengths.
I can easily find 10 things I do not like about PyScript. I can easily find 10 things I do not like about JavaScript. Does that mean I will not use them? Of course not. I will use the most appropriate technology to solve my current task. Today, that might be JavaScript to solve problem X. Tomorrow, I might use PyScript to solve problem Y. Next week, I might use both at the same time.
Both PyScript and JavaScript work well together. Keep that in mind as you develop applications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<!DOCTYPE html> <html lang="en"> <head> <title>Google Chart Example</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script defer src="https://pyscript.net/alpha/pyscript.js"></script> </head> <body> <py-script> import js import asyncio from js import document, Object from js import google from pyodide import create_proxy, to_js def drawChart(_): data = google.visualization.arrayToDataTable(to_js( [ ["Fruit", "Fruit Counts", Object.fromEntries(to_js({ "role": "style" })) ], ["Apples", 5, "blue"], ["Pears", 3, "blue"], ["Nectarines", 4, "blue"], ["Plums", 2, "blue"], ["Grapes", 4, "blue"], ["Strawberries", 6, "blue"] ] )) view = google.visualization.DataView.new(data) view.setColumns(to_js([0, 1, Object.fromEntries(to_js( { "calc": "stringify", "sourceColumn": 1, "type": "string", "role": "annotation" })), 2])) options = Object.fromEntries(to_js({ "title": "Fruit Counts", "width": 800, "height": 400, "bar": Object.fromEntries(to_js({"groupWidth": "95%"})), "legend": Object.fromEntries(to_js( { "position": "none" } )) })) chart = google.visualization.ColumnChart.new(document.getElementById("columnchart_values")) chart.draw(view, options) google.charts.load("current", Object.fromEntries(to_js({"packages":["corechart"]}))) google.charts.setOnLoadCallback(create_proxy(drawChart)) </py-script> <div id="columnchart_values" style="width: 900px; height: 300px;"></div> </body> </html> |
More Information
Photography Credit
I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of Sivakumar B at Pexels.
I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.
For the past 14+ years, I have been working in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.
May 30, 2022 at 12:54 PM
Show John, very good, everything that the other criticized you showed the opposite. Congratulations!!!
May 30, 2022 at 1:42 PM
Thanks Mauricio. PyScript has enormous potential. I am looking forward to all the new feature that they will be releasing.