Iframe embed Β· Runs in the browser Β· No account

Embed Python
Runnable Code in Any Website

Put a working Python program on your page with one iframe. Readers run it where they are reading, with nothing to install.

A real Python embed, running in this page

This window uses the same iframe=1 embed. Run it and the Playground opens right here. On narrow screens the button opens the Playground in a new tab.

scores = {"Ada": 9, "Sam": 7, "Mia": 10}
for name, score in scores.items():
print(name, "*" * score)
average = sum(scores.values()) / len(scores)
print("Average:", round(average, 1))
Output
Ada *********
Sam *******
Mia **********
Average: 8.7
The Snippet

One iframe, Ready to Paste

This is the code Pyroom copies for a one-line program with the default settings. Paste it into any page that accepts HTML.

  • s holds your program, so the code lives in the link
  • iframe=1 turns on embedded mode
  • ifcfg holds your settings
  • The height is 640, or 520 with the preview panel hidden
<iframe src="https://pyroom-playground-dev.pages.dev/playground?s=Ojo6cHJpbnQoIkhlbGxvIGZyb20gUHlyb29tISIpCg&iframe=1&ifcfg=eyJyZWFkT25seSI6dHJ1ZSwic2hvd01lbnUiOnRydWUsInNob3dTaGFyZSI6ZmFsc2UsInNob3dEb2NzIjp0cnVlLCJzaG93RXhhbXBsZXMiOnRydWUsInNob3dIaXN0b3J5Ijp0cnVlLCJzaG93U2V0dGluZ3MiOmZhbHNlLCJzaG93RmVlZGJhY2siOmZhbHNlLCJzaG93QWJvdXQiOnRydWUsInNob3dDb25zb2xlSW5wdXQiOnRydWUsInNob3dSdW5CdXR0b24iOnRydWUsInNob3dQcmV2aWV3Ijp0cnVlLCJmaXhlZEF1dGhvciI6IiIsInNob3dUYXNrUGFuZWwiOnRydWUsImF1dG9SdW4iOmZhbHNlfQ" width="100%" height="640" style="border:1px solid #334155;border-radius:12px;" loading="lazy" allow="clipboard-read; clipboard-write"></iframe>
Your Settings

Choose What Readers Can Do

Keep a clean, read-only example, or open the editor for practice. The dialog writes your choices into the snippet.

  • Code is read-only by default, and readers can still run it
  • Show or hide the menu, run button, preview panel and console input
  • Show your name with a fixed author
  • Set the language or follow the browser
Share as iframe
Configure embedded mode and copy iframe code

Possible settings: read-only code, fixed author, show/hide menu, run button, preview panel, console input, default language, and modal features (docs/examples/history/share/settings/about/feedback).

Default languageAuto (browser) Β· English Β· Ukrainian

Open the Playground to copy an iframe β†’
Run on Load

Show the Result Without a Click

Set autoRun and the program runs when the embed opens, so readers do not have to press Run. This snippet uses {"readOnly":false,"autoRun":true}.

  • The dialog does not offer autoRun, so add it to ifcfg yourself
  • Settings you leave out keep their defaults
  • It needs a program in the link, in the s parameter
<iframe src="https://pyroom-playground-dev.pages.dev/playground?s=Ojo6Zm9yIG4gaW4gcmFuZ2UoMSwgNik6CiAgICBwcmludChuLCBuICogbikK&iframe=1&ifcfg=eyJyZWFkT25seSI6ZmFsc2UsImF1dG9SdW4iOnRydWV9" width="100%" height="640" style="border:1px solid #334155;border-radius:12px;" loading="lazy" allow="clipboard-read; clipboard-write"></iframe>

Python iframe configuration options

The dialog stores these settings in ifcfg as JSON encoded with base64url. Any key you leave out uses its default.

KeyIn the dialogDefault
readOnlyRead-only codetrue
fixedAuthorFixed authorempty
showMenuShow menutrue
showRunButtonShow run buttontrue
showPreviewShow preview paneltrue
showConsoleInputShow console inputtrue
showShareEnable share modalfalse
showDocsEnable docstrue
showExamplesEnable examplestrue
showHistoryEnable historytrue
showSettingsEnable settingsfalse
showFeedbackEnable bug reportfalse
showAboutEnable abouttrue
defaultLangDefault language: "EN" or "UA"Auto (browser)
autoRunNot in the dialogfalse
showTaskPanelNot in the dialogtrue
fixedModeNot in the dialognot set
  • autoRun runs the program when the embed opens.
  • showTaskPanel set to false hides the task panel.
  • fixedMode takes "teacher" or "student" and keeps the embed in that mode.

Python embeds for lessons, courses and blogs

Bloggers: a worked example

Keep Read-only code on, so the example stays as you wrote it.

def is_even(number):
    return number % 2 == 0

for n in range(1, 6):
    print(n, is_even(n))
Open this example in Playground β†’

Course authors: an exercise

Turn Read-only code off, so learners can edit the program and run it again.

# Change the list, then press Run
prices = [12, 8, 20]
total = sum(prices)
print("Total:", total)
Open this example in Playground β†’

Teachers: a drawing

Keep Show preview panel on for the turtle, and add your name with Fixed author.

import turtle

pen = turtle.Turtle()
for _ in range(5):
    pen.forward(120)
    pen.right(144)
Open this example in Playground β†’

How to embed Python in a website

  1. Step 1

    Write your program

    Write and test your code in the Playground.

  2. Step 2

    Copy the iframe

    Open Menu β†’ Share β†’ Share as iframe, pick your settings and select Copy iframe.

  3. Step 3

    Paste it into your page

    Add the code to the HTML of your site, course or blog post.

Python embed questions

Do I need to change headers on my website?

No. The Playground page sends its own headers, and your site needs no COOP or COEP setup. On a normal page Python runs on the main thread of the embed instead of in a worker, so a long calculation can make the embed pause until it finishes.

Which iframe attributes are required?

The src carries everything Pyroom needs: the program, iframe=1 and your settings. The copied code also sets width, height, a border style, loading="lazy" and allow="clipboard-read; clipboard-write" for clipboard access. Add a title attribute so screen readers can name the embed.

Can readers change the code?

Only if you allow it. Read-only code is on by default, and readers can still run the program. Turn it off for practice exercises.

Will the embed update if I change my program?

No. The program is stored in the link, so a changed program needs a new snippet.

Do readers need an account?

No. They open your page and run the program in their browser. The embed opens the code directly and skips the "Open shared code?" prompt.

Are uploaded files included?

No. Share links include code and task information, but not uploaded resource files or downloaded library caches.

Does the embed work on phones?

Yes. When the iframe is under 768px wide it uses the phone layout, with a button that switches between the editor and the output.

Will it work in my LMS or blog platform?

It works wherever you can add an iframe to the HTML. Some platforms remove iframes or limit them to approved sites, so check your platform settings.

Embed your first Python program

Nothing to install, and no account needed.

Open Playground β†’