Skip to content

Instantly share code, notes, and snippets.

@ericmjl
Last active May 1, 2022 19:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericmjl/0e46f3810b7bac281ddc419176944483 to your computer and use it in GitHub Desktop.
Save ericmjl/0e46f3810b7bac281ddc419176944483 to your computer and use it in GitHub Desktop.
pyscript templates and examples (HTML and Markdown)
<script defer src="https://pyscript.net/unstable/pyscript.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

PyScript Pre-populated REPL

Here is a pre-populated REPL that outputs to the right hand side.

Press `Shift+Enter` or `Ctrl+Enter` to execute code in the REPL.

import random names = ["Erik", "Eric", "Rohit", "Carol"] random.choice(names)
<!-- Taken from: https://pyscript.net/examples/hello_world.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>PyScript Hello World</title>
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="https://pyscript.net/unstable/pyscript.css" />
<script defer src="https://pyscript.net/unstable/pyscript.js"></script>
</head>
<body>
Hello world! <br>
Here is a polynomial curve.
<py-env>
- numpy
- matplotlib
</py-env>
<py-script output="out">
# Replace this stuff here!
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
x = np.linspace(-3, 3, 1000)
y = x**2
plt.plot(x, y)
fig
</py-script>
<div id="out"></div>
</body>
</html>
<script defer src="https://pyscript.net/unstable/pyscript.js"></script>

PyScript Hello World

Hello world!

Here is a polynomial curve.

- matplotlib - numpy
import numpy as np import matplotlib.pyplot as plt fig = plt.figure() x = np.linspace(-3, 3, 1000) y = x**2 plt.plot(x, y)

fig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment