All Projects → florimondmanca → python-in-browser

florimondmanca / python-in-browser

Licence: MIT License
🐍🛥🌟 Running Python in the browser with Batavia and Starlette

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to python-in-browser

code-tour-rs
Enhanced example-based learning, i.e. awesome example user experience
Stars: ✭ 20 (+66.67%)
Mutual labels:  example
APIConnectors
A curated list of example code to collect data from Web APIs using DataPrep.Connector.
Stars: ✭ 22 (+83.33%)
Mutual labels:  example
match stream
A sample project to show in our scale blog post
Stars: ✭ 30 (+150%)
Mutual labels:  example
graphql-example
Intuitive GraphQL Resolver Example - Application example using RawModel.js as GraphQL rootValue on steroids.
Stars: ✭ 25 (+108.33%)
Mutual labels:  example
SimplePipes
A small test pipes mod based around LibBlockAttributes
Stars: ✭ 22 (+83.33%)
Mutual labels:  example
microservice-template-ddd
Golnag microservice-template by DDD
Stars: ✭ 13 (+8.33%)
Mutual labels:  example
aiodogstatsd
An asyncio-based client for sending metrics to StatsD with support of DogStatsD extension
Stars: ✭ 26 (+116.67%)
Mutual labels:  starlette
go-wasm-examples
Some small examples of using Go and WebAssembly
Stars: ✭ 22 (+83.33%)
Mutual labels:  example
play-scala-secure-session-example
An example Play application showing encrypted session management
Stars: ✭ 54 (+350%)
Mutual labels:  example
cypress-example-docker-compose
Example running Cypress tests against Apache server via docker-compose
Stars: ✭ 106 (+783.33%)
Mutual labels:  example
solana-web3-demo
a quick demo for solana web3
Stars: ✭ 93 (+675%)
Mutual labels:  example
nodejs-with-postgres-api-example
k8s course example - node.js app with Postgres, Hapi.js and Swagger
Stars: ✭ 59 (+391.67%)
Mutual labels:  example
djcra
Django ❤️ create-react-app integration example
Stars: ✭ 12 (+0%)
Mutual labels:  example
play-scala-anorm-example
Example Play Database Application using Anorm
Stars: ✭ 41 (+241.67%)
Mutual labels:  example
fastapi-tdd-docker
Test-Driven Development with FastAPI and Docker
Stars: ✭ 89 (+641.67%)
Mutual labels:  starlette
aita dataset
AITA dataset based on r/AmItheAsshole/
Stars: ✭ 27 (+125%)
Mutual labels:  example
UWO
Unity WebGL x WebSocket MMO demo
Stars: ✭ 49 (+308.33%)
Mutual labels:  example
Examples Gtkmm
Shows how to use Gtkmm controls by programming code (c++17).
Stars: ✭ 23 (+91.67%)
Mutual labels:  example
laravel-docker-redis
Simple example: How to use laravel and redis using docker compose
Stars: ✭ 23 (+91.67%)
Mutual labels:  example
tensorflow flask
tensorflow model deployment in flask REST API
Stars: ✭ 26 (+116.67%)
Mutual labels:  example

python-in-browser

Running Python in the browser using Batavia and Starlette.

Demo

# frontend/app.py
import dom

print("Hello from Python!")

dom.document.title = "Hello world"
div = dom.document.getElementById("pyconsole")
div.innerHTML = div.innerHTML + "\n\nHello, World!\n\n"

raise ValueError("Just testing out exceptions!")

Installation

First, install Batavia. The full instructions are here, but we provide a convenience script that should work on Linux/macOS:

chmod +x scripts/install_batavia
./scripts/install_batavia

Then install Python dependencies:

python -m venv venv
. venv/bin/activate
pip install -r requirements.txt

You're good to go!

Quickstart

Start the web server:

uvicorn server:app

Go to http://127.0.0.1:8000, and the following will happen:

  • An HTML page is shown. It was server-rendered via Jinja2 by the Starlette web app.
  • The HTML page contains a script that contains the Python bytecode for frontend/app.py.
  • The Batavia JS virtual machine is loaded and runs that bytecode.
  • As a result, frontend/app.py ends up running in your browser, and doing stuff such as printing to the browser console and manipulating the DOM.

🌟

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].