| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Python By Example is a Go By Example-inspired learning site for Python 3.13. It presents small literate examples with prose, source fragments, expected output, official Python documentation links, and an editable runner.
Production: https://www.pythonbyexample.dev (workers.dev is disabled so the custom-domain WAF and rate-limit posture cannot be bypassed).
Python By Example is inspired by:
The project uses:
Python documentation links point to the official Python documentation.
Example runs are executed by Dynamic Workers. The parent Worker creates a Dynamic Worker module from the submitted code, disables outbound network access, and keys Worker Loader reuse by Python version, example slug, and code hash.
This project is developed with red-green-refactor TDD:
Use Node 22 (Pywrangler's Pyodide runtime is not compatible with Node 26), then install the exact committed Python and Node dependency sets:
node --version # v22.x
uv sync --locked --all-groups
npm ci --ignore-scripts
make testThe test suite (and the example loader it imports) requires Python 3.13; make test runs it through uv run --python 3.13 so a system python3 on another version still works.
After cloning, install the local git hooks once so merges and rebases regenerate src/asset_manifest.py instead of producing conflicts:
./scripts/install-git-hooks.shRun locally on Workers with the repository-pinned Wrangler:
make devOpen:
http://localhost:9696
Run a local Worker before the full browser-backed verification:
make devThen run the main checks before deploying or pushing:
make verify
scripts/format_examples.py --check
make verify-python-version VERSION=3.13
git diff --checkmake seo-cache-lint verifies that:
make browser-layout-test launches headless Chrome and checks the rendered Shiki code-block layout so generated line markup does not create visual blank rows.
Source assets live at stable paths such as:
public/site.css
public/syntax-highlight.js
public/editor.js
public/runner.js
Before tests/deploy, regenerate embedded example data, fingerprinted asset copies, and Python manifests:
make buildThis writes files such as:
public/site.<hash>.css
public/syntax-highlight.<hash>.js
public/editor.<hash>.js
public/runner.<hash>.js
src/asset_manifest.py
Rendered HTML uses only fingerprinted asset URLs. public/_headers gives these immutable cache headers:
Cache-Control: public, max-age=31536000, immutable
Rendered HTML pages are cached separately with a generated HTML_CACHE_VERSION in the Worker Cache API key. When templates, examples, app code, or asset fingerprints change, the generated HTML cache key changes too.
Prototype layout routes under /layout-options/* bypass the Worker Cache API and return Cache-Control: no-store.
Run checks, then deploy:
make verify
scripts/format_examples.py --check
make deploymake deploy first runs make check-generated, which rebuilds and rejects any generated output not committed to the branch. It then syncs the ignored Python Workers dependency bundle before Wrangler deploys.
See CONTRIBUTING.md for pull request workflow, example editing rules, and verification commands.
Edit Markdown files under src/example_sources/.
Each example has:
After editing examples, run:
make build
make verify-examples
scripts/format_examples.py --check
make check-generatedAfter adding an example or journey (or changing card title, summary, figure, or card CSS), regenerate social cards. make check-generated verifies the committed card-input provenance, exact JPEG set, JPEG decodability, and 1200×630 dimensions without byte-comparing Chrome's platform-variable raster output:
make social-cardsThis composes 1200x630 cards for home, examples, and journeys, records their deterministic HTML-input hashes in public/og/manifest.json, and rasterizes JPEGs under public/og/ with headless Chrome (set CHROME_PATH if needed).
make quality-checks runs the registry, confusable-pair, broad-tour, footgun, notes, program/cell, prose-duplication, inline-link, scoring, figure, journey, and example-graph gates.
src/example_sources_data.py is generated and committed so Cloudflare Workers can load examples in production. Do not edit it by hand.
For a Python version migration, update python_version and docs_base_url in src/example_sources/manifest.toml, then run:
make verify-python-version VERSION=3.13Use the active Cloudflare-supported Python version.
| Back | FazBrowse Home | New Git URL |