Skip to content

2025 2 1 #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/beginning-pyscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ module in the document's `<head>` tag:
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>🦜 Polyglot - Piratical PyScript</title>
<link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css">
<script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script>
<link rel="stylesheet" href="https://pyscript.net/releases/2025.2.1/core.css">
<script type="module" src="https://pyscript.net/releases/2025.2.1/core.js"></script>
</head>
<body>

Expand Down Expand Up @@ -168,8 +168,8 @@ In the end, our HTML should look like this:
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>🦜 Polyglot - Piratical PyScript</title>
<link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css">
<script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script>
<link rel="stylesheet" href="https://pyscript.net/releases/2025.2.1/core.css">
<script type="module" src="https://pyscript.net/releases/2025.2.1/core.js"></script>
</head>
<body>
<h1>Polyglot 🦜 💬 🇬🇧 ➡️ 🏴‍☠️</h1>
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ CSS:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- PyScript CSS -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css">
<link rel="stylesheet" href="https://pyscript.net/releases/2025.2.1/core.css">
<!-- This script tag bootstraps PyScript -->
<script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script>
<script type="module" src="https://pyscript.net/releases/2025.2.1/core.js"></script>
</head>
<body>
<!-- your code goes here... -->
Expand Down
10 changes: 5 additions & 5 deletions docs/user-guide/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ For example, this will work because all references are contained within the
registered function:

```js
import { hooks } from "https://pyscript.net/releases/2024.11.1/core.js";
import { hooks } from "https://pyscript.net/releases/2025.2.1/core.js";

hooks.worker.onReady.add(() => {
// NOT suggested, just an example!
Expand All @@ -114,7 +114,7 @@ hooks.worker.onReady.add(() => {
However, due to the outer reference to the variable `i`, this will fail:

```js
import { hooks } from "https://pyscript.net/releases/2024.11.1/core.js";
import { hooks } from "https://pyscript.net/releases/2025.2.1/core.js";

// NO NO NO NO NO! ☠️
let i = 0;
Expand Down Expand Up @@ -147,7 +147,7 @@ the page.

```js title="log.js - a plugin that simply logs to the console."
// import the hooks from PyScript first...
import { hooks } from "https://pyscript.net/releases/2024.11.1/core.js";
import { hooks } from "https://pyscript.net/releases/2025.2.1/core.js";

// The `hooks.main` attribute defines plugins that run on the main thread.
hooks.main.onReady.add((wrap, element) => {
Expand Down Expand Up @@ -197,8 +197,8 @@ hooks.worker.onAfterRun.add(() => {
<!-- JS plugins should be available before PyScript bootstraps -->
<script type="module" src="./log.js"></script>
<!-- PyScript -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css">
<script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script>
<link rel="stylesheet" href="https://pyscript.net/releases/2025.2.1/core.css">
<script type="module" src="https://pyscript.net/releases/2025.2.1/core.js"></script>
</head>
<body>
<script type="mpy">
Expand Down
56 changes: 56 additions & 0 deletions docs/user-guide/pygame-ce.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# PyGame Support

!!! Danger

**Support for PyGame-CE is experimental** and its behaviour is likely to
change as we get feedback and bug reports from the community.

Please bear this in mind as you try PyGame-CE with PyScript, and all
feedback, bug reports and constructive critique is welcome via discord
or GitHub.


[PyGameCE](https://pyga.me/) is a Python library for building powerful games
(so says their website). They also say, to get started you just need to
`pip install pygame-ce`.

Thanks to work in the upstream [Pyodide project](https://pyodide.org/)
PyGame-CE is available in PyScript and to get started all you need to do is:
`<script type="py-game" src="my_game.py"></script>` Now you don't even need to
`pip install` the library! It comes with PyScript by default, and you can share
your games via a URL!

!!! Info

Please refer to
[PyGame-CE's extensive documentation](https://pyga.me/docs/) for how to
create a game. Some things may not work because we're running in a
browser context, but play around and let us know how you get on.

## How it works

When a `<script type="py-game"></script>` element is found on the page a
Pyodide instance is bootstrapped with the `pygame-ce` package already included.
Differently from other scripts, `py-game` cannot currently work through a
worker and it uses an optional target attribute to define the `<canvas>`
element id that will be used to render the game. If no target attribute is
defined, the script assumes there is a `<canvas id="canvas">` element already
on the page.

A config attribute can be specified to add extra packages but right now that's
all it can do.

This is an experiment, but:

* It is possible to use regular PyScript to load the pygame-ce package and use
all the other features. But there be dragons! This helper simply allows
multiple games on a page and forces game logic to run on the main thread to
reduce confusion around attributes and features when the `pygame-ce` package
is meant to be used. Put simply, we make it relatively safe and easy to use.
* The fact `pygame-ce` is the default "game engine" does not mean in the future
PyScript won't have other engines also available.
* Once again, as this is an experiment, we welcome any kind of feedback,
suggestions, hints on how to improve or reports of what's missing.

Other than that, please go make and share wonderful games. We can't wait to see
what you come up with.
4 changes: 2 additions & 2 deletions docs/user-guide/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ Here's how:
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<!-- PyScript CSS -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.11.1/core.css">
<link rel="stylesheet" href="https://pyscript.net/releases/2025.2.1/core.css">
<!-- This script tag bootstraps PyScript -->
<script type="module" src="https://pyscript.net/releases/2024.11.1/core.js"></script>
<script type="module" src="https://pyscript.net/releases/2025.2.1/core.js"></script>
<title>PyWorker - mpy bootstrapping pyodide example</title>
<script type="mpy" src="main.py"></script>
</head>
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ nav:
- The FFI in detail: user-guide/ffi.md
- Python terminal: user-guide/terminal.md
- Python editor: user-guide/editor.md
- PyGame-CE: user-guide/pygame-ce.md
- Plugins: user-guide/plugins.md
- Use Offline: user-guide/offline.md
- Built-in APIs: api.md
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2024.11.1"
"version": "2025.2.1"
}