Enter your search term. Try searching for "all".
These course notes define the lecture I give introducing people to Python in the Browser.
Use Pyodide when:
Here are the 37 packages which have been compiled to Pyodide.
Plus all of the pure python packages on PyPi. Not including networking.
There are many different ways to run Python in the browser.
Here is tree of Links if you want more information on Pyodide.
Here is the workspace for this class. It is the official Django server for Pyodide.
So let us get started. First I review the django server functionality.
On the left hand side, with have this text called JSMD. I will say a few words about it.
Fetch the data and graph it.
raw cells - make notes, add comments
fetch cells - grab libraries, external stylesheets, and data sets
md cells - write your report, add DOM elements, etc.
css cells - style your report
Markdown cells support the full range of normal markdown formatting, like _multiple_ **levels** of ***emphasis***,
### of different
Make the Console larger. Select Py not JS.
The markdown and CSS is run automatically. The other cells we need to run as needed.
1. Which Python Version.
Let us see which version pf Python we have. Hint *sys.version'
2. Let us see which Iodide version.
from js import iodide
#and examine it.
2, Hello World in Python
And now we will do hello world in Python
The first unlabelled cell is an introduction.
The first markdown cell creates an output div.
The first css cell defines the css.
And click on report view in the upper right to see what is displayed.
2. Now we will do hello world.
write "hello world".
from js import document
from js import window
4. Simple Python examples.
Run the foo cell.
Create a foo object.
show the value of the foo object.
5. Now let us fire up numpy.
import numpy as np
5. What packages do you have?
from js import pyodide
7. Create x and y
x = np.linspace(0, 2.0 * np.pi, 100)
y = np.sin(x)
take a look at the x and y variables
8. And then plot them up with MatPlotLib. There is a cell for this. Run it.
9. And now plot them with plotly. The browser does not have plotly nstalled. So you have to run the fetch cell to fetch plotly. Then run the plotly cell.
10. Python Conclusion. We have read a remote file, loaded a library, calculated some numbers, and displayed the results.
Look what happens when converting large arrays. (Botton of the page)
Watch out for memory leaks. Use foo.destroy()
var foo = pyodide.pyimport("foo")
2. Get the string representation of foo.
Instead of pyimport, let us use pyodide.globals.
Access the Foo class.
get the value of the bar object.
So use that to create a biz object from Foo.
pyodide.globals to access them.
6. This time we will plot them from plotly. Please let me know when you reach this far and I will start up a docker container for you for the next part of the class. It takes a few minutes to issue the lets encrypt certificate.
7. Finally use the jsmd to load some data.
and plot it with plotly.
8. Next up we read a data file and plot the results
JSON.stringify() gives you a string.
9. JSON.stringify (jsonData)
to convert it to a string and pass it to python.
pyodide.globals["jsonData"] = newString
in Python json.loads() to convert it to Python data structures
Extract the x and y and plot it up again.
I am not a big fan of relational databases, so I will not say much about their server implmentation. But I do need to point out that they have a file api, so that you can save files to a particular notebook on the Django Iodide server.
After using Iodide for a while, I now believe that Iodide is good for a tutorial, but not yet ready for prime time. Maybe they bit off too large a bite. But Pyodide still looks very interesting. Being able to run Python code on WASM is very interesting, so let us fire up a small example, just to get you started.
So here are some critical commands
globals.window = window;
globals.document = document;
Here are the exercises.
2. Define the globals.
3. Add a CSS object.
4. Add an output div.
5. Write to the output div.
The hot item is running your Jupiter Kernels in the web browser. For this a number of things have to be done.
1. Get iPython running on Pyodide using zipimporter.
2. Get it all working using Jyve. Maybe starting with the Brython kernel.
If you liked this class please upvote my Awesome Python pull request.
And is your company on the map of Python companies in Europe?