yusuf-wadi / pyscript-local-runtime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pyscript-local-runtime

This repository gives a template for running PyScript and all its runtime dependencies locally e.g. to create browser extensions using Python, or offline web apps using PyScript without internet access.

To download the runtime files on Linux/Posix using wget...

cd runtime
source setup.sh

To download the runtime files on Windows (with Python and requests):

cd runtime
python setup.py

EXAMPLE CHROME EXTENSION

This example is a simple Chrome Extension which creates a Popup box, renders the time using Python's datetime module, and sends a message to the Console.

  • The Python script is wrapped inside some simple HTML boiler-plate code in index.html.
  • On completion, index.html runs the JavaScript file finished.js.
  • PyScript runtime files are in /runtime
  • Icons are in /images
  • Other magic required for Chrome to recognise this as an extension are in manifest.json.

index.html must include a <py-config> block as follows:

<py-config>
      [[runtimes]]
      src = "runtime/pyodide.js"
      name = "pyodide-0.21.3"
      lang = "python"
</py-config>

And also these two lines to load PyScript locally into the browser:

<link rel="stylesheet" href="runtime/pyscript.css" />
<script defer src="runtime/pyscript.js"></script>

Now you're ready to load the unpacked extension into Chrome and run it following this tutorial.

Further information about getting started with Chrome Exentions is available here.

All the best, Pete

https://github.com/PFython

CREDITS

A big "Thank You" to https://github.com/tedpatrick (Engineering Manager at Anaconda) for pointing me in the right direction.

If this code helps you save time and focus on more important things, please feel free to to show your appreciation by starring the repository on Github.

I'd also be delighted if you wanted to:

Buy Me A Coffee

About


Languages

Language:CSS 65.9%Language:Python 17.3%Language:HTML 8.3%Language:Shell 8.2%Language:JavaScript 0.3%