Skip to main content

πŸ§ͺ Examples

24 Python examples, runnable in your browser

Each snippet runs in a real CPython environment (Pyodide). No install, no signup. Click any card to open the full playground with that snippet pre-loaded.

api Β· 1asyncio Β· 1basics Β· 2cleaning Β· 1concurrency Β· 1context-manager Β· 1csv Β· 1data Β· 2database Β· 1dataclasses Β· 1decorators Β· 1dict Β· 1exceptions Β· 1files Β· 1fstring Β· 1generators Β· 1idioms Β· 7itertools Β· 1json Β· 1math Β· 2matplotlib Β· 1memory Β· 1mypy Β· 1numpy Β· 3oop Β· 2pandas Β· 2properties Β· 1regex Β· 2requests Β· 1sqlite Β· 1stdlib Β· 5strings Β· 3typing Β· 1viz Β· 1
πŸ‘‹

Hello, World!

Confirm Python is running. Smallest possible example.

basics
🐍

List comprehensions

The one-liner that makes Python feel like Python.

basicsidioms
πŸ“Š

pandas in 12 lines

Load, filter, group, aggregate. No CSV download needed.

pandasdata
πŸ“ˆ

Plot with matplotlib

Headless matplotlib via Pyodide β€” figure renders inline in the output panel.

matplotlibnumpyviz
πŸ“

Linear regression with numpy

Fit a line to noisy data in 5 lines.

numpymath
🌐

Call a real HTTP API

Fetch GitHub's API with requests. Auto-installed via micropip.

requestsapi
⚑

asyncio in action

Run three coroutines concurrently with asyncio.gather.

asyncioconcurrency
πŸ“¦

Dataclasses + descriptors

Real validation without writing __init__ by hand.

dataclassesoop
πŸ”Ž

Regex extraction

Pull structured data out of messy text.

regexstrings
πŸ“„

CSV read + write

Pure-stdlib CSV with DictReader / DictWriter. No pandas needed.

csvstdlibfiles
πŸ“‹

JSON parse + serialise

json.loads, json.dumps, custom default for dataclasses.

jsonstdlib
πŸ”„

Generators + lazy eval

Memory-friendly streaming with yield and generator expressions.

generatorsidiomsmemory
πŸ› 

Custom context managers

with-statement support via class + via @contextmanager decorator.

context-manageridioms
⚠

Exception patterns

Custom exception hierarchy, EAFP, exception chaining.

exceptionsidioms
🏷

Modern type hints

PEP 604 union types, TypedDict, Protocol β€” what mypy expects in 2026.

typingmypy
πŸ”

itertools tricks

groupby, accumulate, pairwise, combinations β€” the lazy toolkit.

itertoolsstdlibidioms
πŸŽ€

Decorators β€” log + cache + retry

Real-world decorator patterns: logging wrapper, functools.cache, retry on failure.

decoratorsidioms
πŸ—„

SQLite from stdlib

Real database (in-memory) β€” no install. Create, insert, query, parameterise.

sqlitestdlibdatabase
🧡

f-string mini-cookbook

Padding, alignment, thousand separators, dates, debug syntax.

fstringstringsidioms
πŸ—‚

dict patterns

Default values, dict comprehensions, dict union (|), nested gets.

dictstdlib
🧹

pandas β€” clean a messy CSV

Real cleaning: parse dates, strip whitespace, fill missing, dedupe.

pandasdatacleaning
πŸ–Ό

numpy β€” toy blur kernel

Convolve a 1-D signal with a moving-average kernel.

numpymath
πŸͺ„

regex β€” find + replace

Capture groups in re.sub callbacks. Slugify a string.

regexstrings
🧱

OOP β€” properties + validation

@property + @setter pattern for invariant-protected attributes.

oopproperties

Want a blank canvas? Open the empty playground β€” full CPython runtime, Cmd/Ctrl + Enter to run, β†— Share to copy a URL with embedded code.