pygbag


Namepygbag JSON
Version 0.9.2 PyPI version JSON
download
home_pagehttps://pygame-web.github.io/
Summarypackage and run python/pygame-ce wasm (and more) directly in modern web browsers.
upload_time2024-08-18 22:45:38
maintainerNone
docs_urlNone
authorPaul Peny
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pygbag

Python WebAssembly for everyone ( packager + test server )

Intro : [https://github.com/pygame-web](https://github.com/pygame-web)

Community Documentation : [https://pygame-web.github.io](https://pygame-web.github.io)

Runs python code directly in modern web browsers, including mobile versions.


Quick Start:

"your.app.folder" must contain a main.py and its loop must be async aware eg:

```py
import asyncio

# Try to declare all your globals at once to facilitate compilation later.
COUNT_DOWN = 3

# Do init here
# Load any assets right now to avoid lag at runtime or network errors.


async def main():
    global COUNT_DOWN

    # avoid this kind declaration, prefer the way above
    COUNT_DOWN = 3

    while True:

        # Do your rendering here, note that it's NOT an infinite loop,
        # and it is fired only when VSYNC occurs
        # Usually 1/60 or more times per seconds on desktop
        # could be less on some mobile devices

        print(f"""

            Hello[{COUNT_DOWN}] from Python

""")
        # pygame.display.update() should go right next line

        await asyncio.sleep(0)  # Very important, and keep it 0

        if not COUNT_DOWN:
            return

        COUNT_DOWN = COUNT_DOWN - 1

# This is the program entry point:
asyncio.run(main())

# Do not add anything from here, especially sys.exit/pygame.quit
# asyncio.run is non-blocking on pygame-wasm and code would be executed
# right before program start main()
```

Usage:

    pip3 install pygbag --user --upgrade
    pygbag your.app.folder

Command help:

    pygbag --help your.app.folder


Example :

```
user@pp /data/git/pygbag $ py -m pygbag --help test/main.py
 *pygbag 0.8.2*
115: cache 0.7.2 mismatch, want 0.8.2, cleaning ...

Serving python files from [/data/git/pygbag/test/build/web]

with no security/performance in mind, i'm just a test tool : don't rely on me
usage: __main__.py [-h] [--bind ADDRESS] [--PYBUILD PYBUILD] [--app_name APP_NAME] [--ume_block UME_BLOCK] [--can_close CAN_CLOSE] [--cache CACHE] [--package PACKAGE] [--title TITLE] [--version VERSION] [--build] [--html] [--no_opt] [--archive] [--icon ICON] [--cdn CDN] [--template TEMPLATE] [--ssl SSL]
                   [--port [PORT]]

options:
  -h, --help            show this help message and exit
  --bind ADDRESS        Specify alternate bind address [default: localhost]
  --PYBUILD PYBUILD     Specify python version [default:3.11]
  --app_name APP_NAME   Specify user facing name of application [default:test]
  --ume_block UME_BLOCK
                        Specify wait for user media engagement before running [default:1]
  --can_close CAN_CLOSE
                        Specify if window will ask confirmation for closing [default:0]
  --cache CACHE         md5 based url cache directory
  --package PACKAGE     package name, better make it unique
  --title TITLE         App nice looking name
  --version VERSION     override prebuilt version path [default:0.8.2]
  --build               build only, do not run test server
  --html                build as html with embedded assets (pygame-script)
  --no_opt              turn off assets optimizer
  --archive             make build/web.zip archive for itch.io
  --icon ICON           icon png file 32x32 min should be favicon.png
  --cdn CDN             web site to cache locally [default:https://pygame-web.github.io/archives/0.8/]
  --template TEMPLATE   index.html template [default:default.tmpl]
  --ssl SSL             enable ssl with server.pem and key.pem
  --port [PORT]         Specify alternate port [default: 8000]
```

unlisted developper options:

    --git               force cdn use of pygbag current git github CI build
    --dev               change port to 8666 and use local build served on 8000



Now navigate to http://localhost:8000 with a modern internet browser.

Use http://localhost:8000?-i for getting a terminal with repl
 and a sized down canvas ( http://localhost:8000#debug also does the same )

For pygame-script go to http://localhost:8000/test.html
( for a game folder named "test" with option --html )


V8 based browsers are preferred ( chromium/brave/chrome ... )
starting with 81.0.4044 ( android 4.4 ).
Because they set baseline restrictions on WebAssembly loading.
Using them while testing ensure proper operation on all browsers


____


NOTES:
 - pygbag only provides support for pygame-ce ( pygame community edition )

 - safari/chrome mobile will not run until version ios 15.x

 - first load will be slower, because setting up local cache from cdn to avoid
useless network transfer for getting pygame and cpython prebuilts.

 - each time there's a major change in the code/assets/template
you must run `pygbag your.app.folder` but
cache will not be destroyed to save bandwidth.

 - if you want to reset prebuilts cache, remove the build/web-cache folder in
your.app.folder

 - pyodide wheels (non-standard wasm) aren't compatible ootb with pygbag runtime


HISTORY:

 - pygbag's concepts took roots in a 2016 Panda3D community experiment.


BUILDING:

Pygbag is not only a python module and its python runtimes are stored online !
Rebuilding all the toolchain can be quite hard.

https://github.com/pygame-web/python-wasm-sdk  <= build CPython (not pyodide)

The default is to build only pygame, but feel free to fork and add yours.

So read/use pygbag CI to see how to build pygame + the C loader (pymain) and
how it is linked it to libpython.
For modules loading since 0.6 the default is to use wasm dynamic libraries.
[wasm wheels info here](https://github.com/pygame-web/pkg-porting-wasm)

https://github.com/pygame-web/pygbag

Default prebuilts CPython + pygame-ce used by pygbag are stored via github pages
from the repo https://github.com/pygame-web/archives under versioned folders.


[TEST INTERACTIVE REPL 3.11 (default)](http://pygame-web.github.io/showroom/pygbag.html?cpython311&-i&noapp#src/hello.py%20arg1%20arg2)


[TEST INTERACTIVE REPL 3.12 (next)](http://pygame-web.github.io/showroom/pygbag.html?cpython312&-i&noapp#src/hello.py%20arg1%20arg2)


ADDING STATIC/DYNAMIC MODULES:

    see in package.d directory and use vendor/vendor.sh


SUPPORT FOR STATIC/DYNAMIC MODULES:

    see in package.d/<vendor>/README.md for module <vendor> specific support


____

[vendor readme (if applicable)](vendor/README.md)


GENERIC PYGBAG SUPPORT OR PYGAME MODULE:

[for generic help around pygbag](https://github.com/pygame-web/pygbag/blob/main/packages.d/pygame/README.md)

GENERIC CPYTHON WASM:

[python.org forum](https://discuss.python.org/c/webassembly/28)

            

Raw data

            {
    "_id": null,
    "home_page": "https://pygame-web.github.io/",
    "name": "pygbag",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Paul Peny",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5a/27/d6d9cf9c0831481b94606652c0861667d9254aecc59c0f1db0f948a126fe/pygbag-0.9.2.tar.gz",
    "platform": null,
    "description": "# pygbag\n\nPython WebAssembly for everyone ( packager + test server )\n\nIntro : [https://github.com/pygame-web](https://github.com/pygame-web)\n\nCommunity Documentation : [https://pygame-web.github.io](https://pygame-web.github.io)\n\nRuns python code directly in modern web browsers, including mobile versions.\n\n\nQuick Start:\n\n\"your.app.folder\" must contain a main.py and its loop must be async aware eg:\n\n```py\nimport asyncio\n\n# Try to declare all your globals at once to facilitate compilation later.\nCOUNT_DOWN = 3\n\n# Do init here\n# Load any assets right now to avoid lag at runtime or network errors.\n\n\nasync def main():\n    global COUNT_DOWN\n\n    # avoid this kind declaration, prefer the way above\n    COUNT_DOWN = 3\n\n    while True:\n\n        # Do your rendering here, note that it's NOT an infinite loop,\n        # and it is fired only when VSYNC occurs\n        # Usually 1/60 or more times per seconds on desktop\n        # could be less on some mobile devices\n\n        print(f\"\"\"\n\n            Hello[{COUNT_DOWN}] from Python\n\n\"\"\")\n        # pygame.display.update() should go right next line\n\n        await asyncio.sleep(0)  # Very important, and keep it 0\n\n        if not COUNT_DOWN:\n            return\n\n        COUNT_DOWN = COUNT_DOWN - 1\n\n# This is the program entry point:\nasyncio.run(main())\n\n# Do not add anything from here, especially sys.exit/pygame.quit\n# asyncio.run is non-blocking on pygame-wasm and code would be executed\n# right before program start main()\n```\n\nUsage:\n\n    pip3 install pygbag --user --upgrade\n    pygbag your.app.folder\n\nCommand help:\n\n    pygbag --help your.app.folder\n\n\nExample :\n\n```\nuser@pp /data/git/pygbag $ py -m pygbag --help test/main.py\n *pygbag 0.8.2*\n115: cache 0.7.2 mismatch, want 0.8.2, cleaning ...\n\nServing python files from [/data/git/pygbag/test/build/web]\n\nwith no security/performance in mind, i'm just a test tool : don't rely on me\nusage: __main__.py [-h] [--bind ADDRESS] [--PYBUILD PYBUILD] [--app_name APP_NAME] [--ume_block UME_BLOCK] [--can_close CAN_CLOSE] [--cache CACHE] [--package PACKAGE] [--title TITLE] [--version VERSION] [--build] [--html] [--no_opt] [--archive] [--icon ICON] [--cdn CDN] [--template TEMPLATE] [--ssl SSL]\n                   [--port [PORT]]\n\noptions:\n  -h, --help            show this help message and exit\n  --bind ADDRESS        Specify alternate bind address [default: localhost]\n  --PYBUILD PYBUILD     Specify python version [default:3.11]\n  --app_name APP_NAME   Specify user facing name of application [default:test]\n  --ume_block UME_BLOCK\n                        Specify wait for user media engagement before running [default:1]\n  --can_close CAN_CLOSE\n                        Specify if window will ask confirmation for closing [default:0]\n  --cache CACHE         md5 based url cache directory\n  --package PACKAGE     package name, better make it unique\n  --title TITLE         App nice looking name\n  --version VERSION     override prebuilt version path [default:0.8.2]\n  --build               build only, do not run test server\n  --html                build as html with embedded assets (pygame-script)\n  --no_opt              turn off assets optimizer\n  --archive             make build/web.zip archive for itch.io\n  --icon ICON           icon png file 32x32 min should be favicon.png\n  --cdn CDN             web site to cache locally [default:https://pygame-web.github.io/archives/0.8/]\n  --template TEMPLATE   index.html template [default:default.tmpl]\n  --ssl SSL             enable ssl with server.pem and key.pem\n  --port [PORT]         Specify alternate port [default: 8000]\n```\n\nunlisted developper options:\n\n    --git               force cdn use of pygbag current git github CI build\n    --dev               change port to 8666 and use local build served on 8000\n\n\n\nNow navigate to http://localhost:8000 with a modern internet browser.\n\nUse http://localhost:8000?-i for getting a terminal with repl\n and a sized down canvas ( http://localhost:8000#debug also does the same )\n\nFor pygame-script go to http://localhost:8000/test.html\n( for a game folder named \"test\" with option --html )\n\n\nV8 based browsers are preferred ( chromium/brave/chrome ... )\nstarting with 81.0.4044 ( android 4.4 ).\nBecause they set baseline restrictions on WebAssembly loading.\nUsing them while testing ensure proper operation on all browsers\n\n\n____\n\n\nNOTES:\n - pygbag only provides support for pygame-ce ( pygame community edition )\n\n - safari/chrome mobile will not run until version ios 15.x\n\n - first load will be slower, because setting up local cache from cdn to avoid\nuseless network transfer for getting pygame and cpython prebuilts.\n\n - each time there's a major change in the code/assets/template\nyou must run `pygbag your.app.folder` but\ncache will not be destroyed to save bandwidth.\n\n - if you want to reset prebuilts cache, remove the build/web-cache folder in\nyour.app.folder\n\n - pyodide wheels (non-standard wasm) aren't compatible ootb with pygbag runtime\n\n\nHISTORY:\n\n - pygbag's concepts took roots in a 2016 Panda3D community experiment.\n\n\nBUILDING:\n\nPygbag is not only a python module and its python runtimes are stored online !\nRebuilding all the toolchain can be quite hard.\n\nhttps://github.com/pygame-web/python-wasm-sdk  <= build CPython (not pyodide)\n\nThe default is to build only pygame, but feel free to fork and add yours.\n\nSo read/use pygbag CI to see how to build pygame + the C loader (pymain) and\nhow it is linked it to libpython.\nFor modules loading since 0.6 the default is to use wasm dynamic libraries.\n[wasm wheels info here](https://github.com/pygame-web/pkg-porting-wasm)\n\nhttps://github.com/pygame-web/pygbag\n\nDefault prebuilts CPython + pygame-ce used by pygbag are stored via github pages\nfrom the repo https://github.com/pygame-web/archives under versioned folders.\n\n\n[TEST INTERACTIVE REPL 3.11 (default)](http://pygame-web.github.io/showroom/pygbag.html?cpython311&-i&noapp#src/hello.py%20arg1%20arg2)\n\n\n[TEST INTERACTIVE REPL 3.12 (next)](http://pygame-web.github.io/showroom/pygbag.html?cpython312&-i&noapp#src/hello.py%20arg1%20arg2)\n\n\nADDING STATIC/DYNAMIC MODULES:\n\n    see in package.d directory and use vendor/vendor.sh\n\n\nSUPPORT FOR STATIC/DYNAMIC MODULES:\n\n    see in package.d/<vendor>/README.md for module <vendor> specific support\n\n\n____\n\n[vendor readme (if applicable)](vendor/README.md)\n\n\nGENERIC PYGBAG SUPPORT OR PYGAME MODULE:\n\n[for generic help around pygbag](https://github.com/pygame-web/pygbag/blob/main/packages.d/pygame/README.md)\n\nGENERIC CPYTHON WASM:\n\n[python.org forum](https://discuss.python.org/c/webassembly/28)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "package and run python/pygame-ce wasm (and more) directly in modern web browsers.",
    "version": "0.9.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/pygame-web/pygbag/issues",
        "Homepage": "https://pygame-web.github.io/",
        "Project Page": "https://github.com/pygame-web",
        "Source Code": "https://github.com/pygame-web/pygbag",
        "Wiki": "https://pygame-web.github.io/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a196c4b2a515651849138cef43d878eba9a4f8e39113499a99e7c3d97890c5e",
                "md5": "849a0a7577d50d9b7cccc1b5928a5a36",
                "sha256": "3a60a80cc28ed21e3d5d98c08a5d8f857911e38e411b6e590ba640158e8656c1"
            },
            "downloads": -1,
            "filename": "pygbag-0.9.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "849a0a7577d50d9b7cccc1b5928a5a36",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 171937,
            "upload_time": "2024-08-18T22:45:36",
            "upload_time_iso_8601": "2024-08-18T22:45:36.536342Z",
            "url": "https://files.pythonhosted.org/packages/3a/19/6c4b2a515651849138cef43d878eba9a4f8e39113499a99e7c3d97890c5e/pygbag-0.9.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a27d6d9cf9c0831481b94606652c0861667d9254aecc59c0f1db0f948a126fe",
                "md5": "4562774a1a94dd2bda1f4687534f9060",
                "sha256": "0e31860742a8ba9c527135cbb6d64f6d7d8d7b23b71ee87a15f1de9474690c25"
            },
            "downloads": -1,
            "filename": "pygbag-0.9.2.tar.gz",
            "has_sig": false,
            "md5_digest": "4562774a1a94dd2bda1f4687534f9060",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 152074,
            "upload_time": "2024-08-18T22:45:38",
            "upload_time_iso_8601": "2024-08-18T22:45:38.498418Z",
            "url": "https://files.pythonhosted.org/packages/5a/27/d6d9cf9c0831481b94606652c0861667d9254aecc59c0f1db0f948a126fe/pygbag-0.9.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 22:45:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pygame-web",
    "github_project": "pygbag",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pygbag"
}
        
Elapsed time: 0.28767s