packages = ["matplotlib", "numpy", "pandas"]
PyTink Editor

Blocks

Basic Functions
Variables & I/O
Variable
Print
Input
Comment
Math Operations
Addition
Subtraction
Multiplication
Division
Control Flow
If Statement
Elif Statement
Else Statement
Loops
For Loop
While Loop
For Range
Functions & Lists
Define Function
Call Function
Return
Create List
Append to List
Custom Code
Custom Code
NumPy
Pandas
Matplotlib

Drag blocks here to build your program

Interactive Python Terminal

Ready

Python 3.11 (PyScript) - Interactive Python Terminal

Type your Python commands below or run blocks from the canvas above.

>>>

Generated Python Code

# Your Python code will appear here
# Drag blocks to the canvas to get started

Plots & Images

Matplotlib plots will appear here

import js import sys from io import StringIO terminal_globals = {} def setup_uploaded_files(): """Make uploaded files available to Python environment""" try: uploaded_files = js.window.uploadedFiles if uploaded_files: import os # Ensure we're in a writable directory try: os.getcwd() except: os.chdir('/tmp') # Convert JavaScript object to Python dict # Use Object.keys() to get the filenames, then access each file filenames = js.Object.keys(uploaded_files).to_py() for filename in filenames: # Use JavaScript object property access via js module content = js.eval(f"window.uploadedFiles['{filename}']") # Write to current working directory try: with open(filename, 'w', encoding='utf-8') as f: f.write(content) # Verify file exists and is readable if os.path.exists(filename): with open(filename, 'r', encoding='utf-8') as f: test_content = f.read(100) # Read first 100 chars except Exception as write_error: # Only show errors that might matter to users if "Permission denied" in str(write_error) or "No space left" in str(write_error): print(f"Error: Could not save file {filename}") # Silently handle when no files are uploaded except Exception as e: # Only show critical errors to users if "Permission denied" in str(e) or "No space left" in str(e): print(f"Error: Could not access file system") def input(prompt=""): """Custom input function that works with PyScript by using the terminal interface""" import js # Show the prompt in terminal output print(prompt, end='', flush=True) # For now, use a simple prompt to get input # This shows the prompt in the terminal and gets input via browser prompt result = js.prompt(prompt) or "" # Show the user's input in the terminal for continuity print(result) return result async def execute_code(code): old_stdout = sys.stdout sys.stdout = captured_output = StringIO() result = "" error = "" plot_data = None try: exec_globals = {"__builtins__": __builtins__} # Override Python's input function with our custom one exec_globals["input"] = input try: import numpy as np exec_globals["np"] = np except: pass try: import pandas as pd exec_globals["pd"] = pd except: pass try: import matplotlib.pyplot as plt exec_globals["plt"] = plt except: pass # Setup uploaded files before executing code setup_uploaded_files() # File system is ready for use exec(code, exec_globals) result = captured_output.getvalue() # Capture matplotlib plots if 'matplotlib' in code or 'plt.' in code: try: import matplotlib.pyplot as plt if plt.get_fignums(): import base64 from io import BytesIO buf = BytesIO() plt.savefig(buf, format='png', dpi=100) buf.seek(0) plot_data = base64.b64encode(buf.getvalue()).decode('utf-8') plt.close('all') except: pass except Exception as e: error = str(e) finally: sys.stdout = old_stdout js.displayResults(result, error, plot_data) async def execute_terminal_command(command): global terminal_globals if not terminal_globals: terminal_globals = {"__builtins__": __builtins__} # Add custom terminal input function terminal_globals["terminal_input"] = terminal_input try: import numpy as np terminal_globals["np"] = np except: pass try: import pandas as pd terminal_globals["pd"] = pd except: pass try: import matplotlib.pyplot as plt terminal_globals["plt"] = plt except: pass # Setup uploaded files before executing terminal commands too setup_uploaded_files() old_stdout = sys.stdout sys.stdout = captured_output = StringIO() result = "" error = "" plot_data = None try: if command.strip() == 'help': result = "Available: import math, numpy as np, pandas as pd, matplotlib.pyplot as plt" elif command.strip() == 'vars()': user_vars = {k: v for k, v in terminal_globals.items() if not k.startswith('__')} result = f"Variables: {list(user_vars.keys())}" else: exec(command, terminal_globals) result = captured_output.getvalue() # Capture matplotlib plots from terminal if 'matplotlib' in command or 'plt.' in command: try: import matplotlib.pyplot as plt if plt.get_fignums(): import base64 from io import BytesIO buf = BytesIO() plt.savefig(buf, format='png', dpi=100) buf.seek(0) plot_data = base64.b64encode(buf.getvalue()).decode('utf-8') plt.close('all') except: pass except Exception as e: error = str(e) finally: sys.stdout = old_stdout js.displayResults(result, error, plot_data) js.window.executeCode = execute_code js.window.executeTerminalCommand = execute_terminal_command