apysc
raw JSON → 4.12.0 verified Fri May 01 auth: no python
apysc is a Python frontend library that generates HTML and JavaScript files with an ActionScript 3 (AS3)-like interface. Current version is 4.12.0, with frequent releases.
pip install apysc Common errors
error ModuleNotFoundError: No module named 'apysc' ↓
cause apysc is not installed.
fix
Run: pip install apysc
error ImportError: cannot import name 'Sprite' from 'apysc' ↓
cause Old import path used (e.g., from apysc.display import Sprite) which no longer exists in v4.
fix
Use: from apysc import Sprite
error TypeError: __init__() got multiple values for argument 'stage_width' ↓
cause Passing positional arguments to Stage constructor instead of keyword arguments.
fix
Use keyword arguments: Stage(stage_width=..., stage_height=..., ...)
Warnings
breaking In v4.x, many classes (e.g., Sprite, Rectangle) were moved from subpackages to top-level apysc. ↓
fix Update imports: from apysc import Sprite instead of from apysc.display import Sprite.
breaking The Stage constructor now requires explicit keyword arguments; old positional arguments may fail. ↓
fix Use named arguments: Stage(stage_width=..., stage_height=...).
gotcha HTML output has CSS class names that may conflict with existing page styles. ↓
fix Use stage_elem_id to prefix IDs or embed in an iframe.
Imports
- Stage wrong
from apysc.display import Stagecorrectfrom apysc import Stage - Sprite wrong
from apysc.display import Spritecorrectfrom apysc import Sprite - Rectangle wrong
from apysc.geom import Rectanglecorrectfrom apysc import Rectangle
Quickstart
from apysc import Stage, Sprite, Rectangle
stage = Stage(
stage_width=200,
stage_height=200,
background_color='#333',
stage_elem_id='stage'
)
sprite = Sprite(stage=stage)
sprite.graphics.begin_fill(color='#0af')
rect = sprite.graphics.draw_rect(x=50, y=50, width=100, height=100)
stage.save_as_html(file_path='output.html')