Python in JavaScript

Implementing and Running Python

Created by @ajlopez

https://github.com/ajlopez/Talks/PythonJavaScript

Using reveal.js

Agenda

  • JavaScript + Node.js
  • JPyScript
  • Demos
    • Console
    • Web
    • Browser
  • Other Projects

Node.js

http://nodejs.org/

Node.js

  • JavaScript Runtime
  • Based on Google V8 JavaScript Engine
  • One thread for JavaScript
  • Asynchronous operations via LibUv
  • Native Modules
  • Module Ecosystem
## A Web Server ```js var http = require('http'); http.createServer(function (req, res) { res.writeHeader(200, {'Content-type': 'text/plain'}); res.write('Hello '); res.end('World'); }).listen(8000); ```

Vibrant Community

Express

http://expressjs.com/

Express

  • Web Framework
  • Based on Connect
  • MVC routing and views
  • Minimalist

JPyScript

The Project

https://github.com/ajlopez/JPyScript
  • Python Subset
  • KISS
  • Python Syntax, JavaScript semantic
  • Written using TDD
  • Runs on server with Node.js
  • Runs on browser
  • MIT License

Internal Implementation

  • Lexer
  • Parser
  • Commands and Expression
  • Top module
  • TDD

Variables

  • Maps Python variable to JavaScript variable (variable.py)
  • Hoisting (badvariable.py)
  • Supports global, nonlocal (canvasserver.py)

Classes

  • Spikes
  • Wrapping constructors, prototypes

Import

  • Resolve to local files (test_calc.py)
  • Resolve to modules (domath.py)
  • Resolve to Node.js modules (!)

Web Demos

  • Using http
  • NPM install
  • Using express
  • Using socket.io

Browser Demos

  • Executing text/python
  • Using the canvas

Projects

Brython

http://www.brython.info/

Skulpt

http://www.skulpt.org/

PythonScript

http://apppyjs.appspot.com/

Things to Explore

THE END

BY Angel 'Java' Lopez / www.ajlopez.com / @ajlopez