{"id":20660980,"url":"https://github.com/liatemplates/pyscript","last_synced_at":"2025-12-16T04:26:05.334Z","repository":{"id":107256846,"uuid":"500871641","full_name":"LiaTemplates/PyScript","owner":"LiaTemplates","description":"PyScript implementation for LiaScript","archived":false,"fork":false,"pushed_at":"2022-06-09T08:12:04.000Z","size":541,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T12:16:31.113Z","etag":null,"topics":["education","liascript","liascript-template","oer","pyscript","python","python3"],"latest_commit_sha":null,"homepage":"https://liascript.github.io/course/?https://raw.githubusercontent.com/liaTemplates/PyScript/main/README.md","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiaTemplates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-07T14:18:48.000Z","updated_at":"2022-06-07T15:01:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"062f8ddb-bb84-44e8-aaa5-f08b6d9a5306","html_url":"https://github.com/LiaTemplates/PyScript","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FPyScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FPyScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FPyScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FPyScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiaTemplates","download_url":"https://codeload.github.com/LiaTemplates/PyScript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242787945,"owners_count":20185190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["education","liascript","liascript-template","oer","pyscript","python","python3"],"created_at":"2024-11-16T19:06:42.561Z","updated_at":"2025-12-16T04:26:05.242Z","avatar_url":"https://github.com/LiaTemplates.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nauthor:   André Dietrich\n\nemail:    LiaScript@web.de\n\nversion:  0.0.4\n\nlanguage: en\n\nnarrator: US English Female\n\nlogo:     logo.png\n\ncomment:  Set of PyScript-macros to be used with LiaScript for creating interactive Python tutorial.\n\nlink:     https://cdn.jsdelivr.net/gh/liatemplates/pyscript@0.0.4/dist/pyscript.css\nscript:   https://cdn.jsdelivr.net/gh/liatemplates/pyscript@0.0.4/dist/pyscript.min.js\n\npersistent:  true\n\n\n@PyScript.env\n\u003clia-keep\u003e\n\u003cpy-env\u003e\n@0\n\u003c/py-env\u003e\n\u003c/lia-keep\u003e\n@end\n\n@PyScript.repl: @PyScript.replWith( ,```@0```)\n\n@PyScript.replWith\n\u003clia-keep\u003e\n\u003cstyle\u003e\n  .output {\n    font-style: inherit;\n    font-weight: inherit;\n    font-size: inherit;\n    line-height: inherit;\n    margin-left: 0px;\n    float: left;\n  }\n\n  .mt-2 {\n    margin-left: 0px !important;\n    margin-right: 0px !important;\n    margin-bottom: 15px !important;\n  }\n\n  .editor-box {\n    border: 1px solid black;\n  }\n\u003c/style\u003e\n\u003cpy-repl class=\"notranslate\" translate=\"no\" @0\u003e@1\u003c/py-repl\u003e\n\u003c/lia-keep\u003e\n@end\n\n--\u003e\n\n[![LiaScript](https://raw.githubusercontent.com/LiaScript/LiaScript/master/badges/course.svg)](https://LiaScript.github.io/course/?https://raw.githubusercontent.com/LiaTemplates/PyScript/main/README.md)\n\n# PyScript - Template\n\n          --{{0}}--\nThis document defines some basic macros for integrating the\n[PyScript](https://pyscript.net/) into [LiaScript](https://LiaScript.github.io)\nand to make Markdown code-blocks executable.\n\n__Try it on LiaScript:__\n\nhttps://liascript.github.io/course/?https://raw.githubusercontent.com/liaTemplates/PyScript/main/README.md\n\n__See the project on Github:__\n\nhttps://github.com/liaTemplates/PyScript\n\n          --{{1}}--\n\nThere are three ways to use this template. The easiest way is to use the\n`import` statement and the url of the raw text-file of the master branch or any\nother branch or version. But you can also copy the required functionality\ndirectly into the header of your Markdown document, see therefor the\n[last slide](#implementation). And of course, you could also clone this project\nand change it, as you wish.\n\n           {{1}}\n0. Add the header-definition `persistent: true` to your main comment or at least\n   to all slides that run a PyScript.\n\n1. Load the macros via\n\n   `import: https://raw.githubusercontent.com/liaTemplates/PyScript/main/README.md`\n\n   or use this specific version and you course will be stable:\n\n   `import: https://raw.githubusercontent.com/LiaTemplates/PyScript/0.0.4/README.md`\n\n2. Copy the definitions into your Project\n\n3. Clone this repository on GitHub\n\n## `@PyScript.repl`\n\n          --{{0}}--\nTo use the default REPL configuration of PyScript, simply add this macro to the\nhead of your code-block. This will insert a new REPL with the code you have\npassed to the LiaScript rendered version of the course.\n\n```` markdown\n``` python @PyScript.repl\nprint('Sammy says, \\'Hello!\\'')\n```\n````\n\n---\n\n__Result:__\n\n``` python @PyScript.repl\nprint('Sammy says, \\'Hello!\\'')\n```\n\n## `@PyScript.replWith`\n\n          --{{0}}--\nAdditionally, it is also possible to pass additional config parameters to the\nREPL, by using the `@PyScript.replWith` macro. For more information, please\nvisit the [PyScript website](https://pyscript.net):\n\n```` markdown\n``` python @PyScript.replWith(auto-generate=\"true\")\nprint(\"Hello World\")\n```\n````\n\n---\n\n__Result:__\n\n``` python @PyScript.replWith(auto-generate=\"true\")\nprint(\"Hello World\")\n```\n\n## `@PyScript.env`\n\n          --{{0}}--\nIf you need to make use of the `\u003cpy-env\u003e` to preload Python libraries, then use\nthe `@PyScript.env` macro. The content will be hidden to the LiaScript rendered\nversion of your course.\n\n```` markdown\n``` python @PyScript.env\n- matplotlib\n- numpy\n```\n\n``` python @PyScript.repl\nimport matplotlib.pyplot as plt\nimport matplotlib.tri as tri\nimport numpy as np\n\n# First create the x and y coordinates of the points.\nn_angles = 36\nn_radii = 8\nmin_radius = 0.25\nradii = np.linspace(min_radius, 0.95, n_radii)\n\nangles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)\nangles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)\nangles[:, 1::2] += np.pi / n_angles\n\nx = (radii * np.cos(angles)).flatten()\ny = (radii * np.sin(angles)).flatten()\nz = (np.cos(radii) * np.cos(3 * angles)).flatten()\n\n# Create the Triangulation; no triangles so Delaunay triangulation created.\ntriang = tri.Triangulation(x, y)\n\n# Mask off unwanted triangles.\ntriang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),\n                         y[triang.triangles].mean(axis=1))\n                \u003c min_radius)\n\nfig1, ax1 = plt.subplots()\nax1.set_aspect('equal')\ntpc = ax1.tripcolor(triang, z, shading='flat')\nfig1.colorbar(tpc)\nax1.set_title('tripcolor of Delaunay triangulation, flat shading')\n\nfig1\n```\n````\n\n---\n\n__Result:__\n\n``` python @PyScript.env\n- matplotlib\n- numpy\n```\n\n``` python @PyScript.repl\nimport matplotlib.pyplot as plt\nimport matplotlib.tri as tri\nimport numpy as np\n\n# First create the x and y coordinates of the points.\nn_angles = 36\nn_radii = 8\nmin_radius = 0.25\nradii = np.linspace(min_radius, 0.95, n_radii)\n\nangles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)\nangles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)\nangles[:, 1::2] += np.pi / n_angles\n\nx = (radii * np.cos(angles)).flatten()\ny = (radii * np.sin(angles)).flatten()\nz = (np.cos(radii) * np.cos(3 * angles)).flatten()\n\n# Create the Triangulation; no triangles so Delaunay triangulation created.\ntriang = tri.Triangulation(x, y)\n\n# Mask off unwanted triangles.\ntriang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),\n                         y[triang.triangles].mean(axis=1))\n                \u003c min_radius)\n\nfig1, ax1 = plt.subplots()\nax1.set_aspect('equal')\ntpc = ax1.tripcolor(triang, z, shading='flat')\nfig1.colorbar(tpc)\nax1.set_title('tripcolor of Delaunay triangulation, flat shading')\n\nfig1\n```\n\n## implementation\n\nIn order to use PyScript, we had to make a few changes to the standard project,\nin order to prevent event-bubbling, sanitize CSS, and add some\n[bug-fixes](https://github.com/pyscript/pyscript/issues/480), that are not yet\nin the PyScript project. And that is why, we currently have to load the script\nfrom our local repository.\n\nThe rest is simply LiaScript-macro syntax ... Do not forget to add\n`persistent: true` to your own project.\n\n``` html\nlink:     https://cdn.jsdelivr.net/gh/liatemplates/pyscript@0.0.4/dist/pyscript.css\nscript:   https://cdn.jsdelivr.net/gh/liatemplates/pyscript@0.0.4/dist/pyscript.min.js\n\npersistent:  true\n\n\n@PyScript.env\n\u003clia-keep\u003e\n\u003cpy-env\u003e\n@0\n\u003c/py-env\u003e\n\u003c/lia-keep\u003e\n@end\n\n@PyScript.repl: @PyScript.replWith( ,```@0```)\n\n@PyScript.replWith\n\u003clia-keep\u003e\n\u003cstyle\u003e\n  .output {\n    font-style: inherit;\n    font-weight: inherit;\n    font-size: inherit;\n    line-height: inherit;\n    margin-left: 0px;\n    float: left;\n  }\n\n  .mt-2 {\n    margin-left: 0px !important;\n    margin-right: 0px !important;\n    margin-bottom: 15px !important;\n  }\n\n  .editor-box {\n    border: 1px solid black;\n  }\n\u003c/style\u003e\n\u003cpy-repl @0\u003e@1\u003c/py-repl\u003e\n\u003c/lia-keep\u003e\n@end\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliatemplates%2Fpyscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliatemplates%2Fpyscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliatemplates%2Fpyscript/lists"}