Code Monkey home page Code Monkey logo

pyscript-local-runtime's Introduction

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

pyscript-local-runtime's People

Contributors

pfython avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.