Brython

Brython(Browser Python)是在浏览器中运行的 Python 3 的一个实现。「Brython (Browser Python) is an implementation of Python 3 running in the browser」

  • 所有者: brython-dev/brython
  • 平台: Linux,Mac,Windows,Web browsers
  • 许可证: BSD 3-Clause "New" or "Revised" License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

brython

Brython (Browser Python) is an implementation of Python 3 running in the
browser, with an interface to the DOM elements and events.

Here is a simple example of an HTML page running Python:

    <html>

        <head>
            <script type="text/javascript" src="/path/to/brython.js"></script>
        </head>

        <body onload="brython()">

            <script type="text/python">
            from browser import document, alert

            def echo(event):
                alert(document["zone"].value)

            document["mybutton"].bind("click", echo)
            </script>

            <input id="zone"><button id="mybutton">click !</button>

        </body>

    </html>

To use Brython, all there is to do is:

  1. Load the script brython.js.
  2. Run the function brython() on page load, like <body onload="brython()">.
  3. Write Python code inside tags <script type="text/python">.

Main features

Brython supports the syntax of Python 3,
including comprehensions, generators, metaclasses, imports, etc.
and many modules of the CPython distribution.

It includes libraries to interact with DOM elements and events,
and with existing Javascript libraries such as jQuery, 3D, Highcharts, Raphael etc.
It supports the latest specs of HTML5/CSS3, and can use CSS Frameworks like
Bootstrap3, LESS, SASS etc.

Getting started

Zero install !

The most simple way to get started, without anything to install, is to use the
distribution available online through jsDelivr.
You can choose the latest stable release :

<script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/brython@3.8.8/brython.min.js">
</script>

The previous code will allow you to use raw python code, but if you import
modules from the standard library you have to load a single javascript file
with the available stdlib:

<script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/brython@3.8.8/brython_stdlib.js">
</script>

If you want to use the latest development version, you can load these scripts
instead:

https://raw.githack.com/brython-dev/brython/master/www/src/brython.js
https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js

Local install

To install Brython locally, if you have a CPython distribution with pip :

pip install brython

then create a new directory and run

python -m brython --install

or by loading the latest version of the Brython zip file from the
releases page.

In both cases, the distribution includes brython.js (the core Brython engine)
and brython_stdlib.js (a bundle of all the files in the standard distribution).

It also includes the page demo.html that shows a few examples of how you
can interact with a web page using Python as the scripting language : create
new elements, access and modify existing elements, create graphics, animations,
send Ajax requests, etc.

Test Brython online

If you want to test Brython online you can visit the following:

Gallery of examples

There is a gallery of examples
where you can see simple and advanced examples using vanilla Brython or
interacting with Javascript libraries.

Documentation

You can start by reading the official Brython tutorial.

Full documentation is available on the official site.
You can read the docs in English,
French and
Spanish.

The most updated docs usually are the English and French versions so if you
want to be up-to-date, please, use these versions.

Curious about how Brython works ?

A tutorial
explains how to build Android applications with Brython.

Community (questions, feedback, issues, new features, ...)

You can subscribe and post to the
mailing list.

If you find a bug/issue or do you want to see a new feature in Brython, please,
open a new issue.

If you want to contribute to Brython, please read the contributing guide.

Thank you

  • BrowserStack for providing an access
    to their online testing environment.

概览

名称与所有者brython-dev/brython
主编程语言Python
编程语言Python (语言数: 7)
平台Linux, Mac, Windows
许可证BSD 3-Clause "New" or "Revised" License
发布数74
最新版本名称3.12.3 (发布于 )
第一版名称2.2.0 (发布于 )
创建于2014-09-15 06:58:21
推送于2024-04-27 06:06:23
最后一次提交2024-04-27 08:06:14
星数6.3k
关注者数137
派生数512
提交数8.7k
已启用问题?
问题数1941
打开的问题数48
拉请求数352
打开的拉请求数4
关闭的拉请求数74
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?
去到顶部