Skip to content

Commit b0ed183

Browse files
ZDStudiosclaude
andcommitted
Add a built-in Web category, no package required
Talking to an API meant pip installing requests first, which is a wall for anyone on a locked down machine and pointless when urllib has been in the standard library all along. A new Web category (13 blocks) covering: - text from a url, and JSON already parsed into records and lists - an all purpose sender for GET/POST/PUT/PATCH/DELETE/HEAD - JSON bodies, form bodies, and plain text bodies - a header block that every later request carries, for API keys - status codes, an "is working" boolean, file downloads - query string building and percent encoding Failed requests still hand back the body, so the error message an API sends is readable. Only http and https addresses are accepted, so a redirect cannot be talked into reading a local file. Run > Try a web request opens a small tester: method, url, body, header, then the status, the timing and the reply with JSON pretty printed. Make a block from this drops the matching blocks into the workspace. The tester runs the very same helper functions the blocks compile to, by executing the block library's own source, so the two cannot drift apart. Also: category strip fits eleven categories, palette notes size themselves, and the readme encoding is repaired. Version 1.1.0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 758994b commit b0ed183

8 files changed

Lines changed: 588 additions & 15 deletions

File tree

README.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![Python](https://img.shields.io/badge/python-3.9%2B-4C97FF?logo=python&logoColor=white)](https://www.python.org/)
1010
[![Dependencies](https://img.shields.io/badge/dependencies-none-59C059)](#)
11-
[![One file](https://img.shields.io/badge/one%20file-6%2C700%20lines-FFAB19)](scratchpy_studio.py)
11+
[![One file](https://img.shields.io/badge/one%20file-7%2C000%20lines-FFAB19)](scratchpy_studio.py)
1212
[![Build](https://github.com/ZDStudios/scratchpy-studio/actions/workflows/build-apps.yml/badge.svg)](https://github.com/ZDStudios/scratchpy-studio/actions/workflows/build-apps.yml)
1313
[![Download](https://img.shields.io/badge/download-windows%20%7C%20macos%20%7C%20linux-855CD6)](https://github.com/ZDStudios/scratchpy-studio/releases/latest)
1414
[![License](https://img.shields.io/badge/license-MIT-0FBD8C)](LICENSE)
@@ -41,16 +41,60 @@ and hand in.
4141

4242
| | |
4343
|---|---|
44-
| 🧩 **135 blocks** | Hat blocks, C-shaped loops, hexagonal booleans, reporter ovals that drop into slots — the real Scratch 3 shapes and colours |
44+
| 🧩 **148 blocks** | Hat blocks, C-shaped loops, hexagonal booleans, reporter ovals that drop into slots — the real Scratch 3 shapes and colours |
4545
| 🐍 **Real Python, live** | The generated source updates as you drag. No hidden interpreter |
4646
| ▶️ **It actually runs** | `print`, `input`, errors and a stop button, all wired to the built-in console |
47+
| 🌐 **Talks to the web out of the box** | GET, POST, headers, JSON, downloads — using `urllib` from the standard library, so there is nothing to install |
4748
| 📥 **Import any `.py`** | Turn a program you already have into blocks — loops, functions, try/except, f-strings and all |
4849
| 📦 **Every PyPI package** | pip dashboard installs anything and turns it into blocks automatically |
4950
| 🤖 **Works with AI** | Built-in MCP server so an assistant can build blocks alongside you |
5051
| 🎨 **Looks the part** | Because half the point of Scratch is that it looks inviting |
5152

5253
---
5354

55+
## The internet, with nothing installed
56+
57+
The **Web** category is built in. No `pip install requests`, no venv, no
58+
waiting — it is `urllib` from the standard library dressed up as blocks.
59+
60+
<div align="center">
61+
<img src="docs/screenshot-web.png" width="900" alt="The built-in web blocks">
62+
</div>
63+
64+
| Block | What it does |
65+
|---|---|
66+
| `text from [url]` | The page or API answer as text |
67+
| `JSON from [url]` | The answer already turned into records and lists |
68+
| `send (GET▾) to [url]` | The all-purpose API sender — GET, POST, PUT, PATCH, DELETE, HEAD |
69+
| `send (POST▾) to [url] with JSON { }` | Send a record as a JSON body |
70+
| `post form { } to [url]` | The kind of form a web page would send |
71+
| `send header [name] as [value]` | Set it once; every request after it carries the header — this is where an API key goes |
72+
| `status code of [url]` · `[url] is working` | 200, 404, or 0 when nothing answers |
73+
| `download [url] to file [path]` | Save a picture or a file |
74+
| `[base] with values { }` | Builds `...?q=cats&page=2` safely |
75+
| `web safe [text]` | Percent-encodes anything for a URL |
76+
77+
A 404 still hands you the body, so you can read the error message an API sends
78+
back. Only `http://` and `https://` addresses are accepted — a redirect cannot
79+
be talked into reading a local file.
80+
81+
### Try it before you build it
82+
83+
**Run → Try a web request**, or the button at the top of the Web category:
84+
85+
<div align="center">
86+
<img src="docs/screenshot-webtester.png" width="900" alt="The built-in request tester">
87+
</div>
88+
89+
Pick a method, paste a URL, add a header, press Send. You get the status code,
90+
how long it took, and the reply with JSON pretty-printed. **Make a block from
91+
this** then drops the matching blocks straight into your workspace.
92+
93+
The tester runs the *same* helper functions your blocks compile to, so what you
94+
test is exactly what your program will do.
95+
96+
---
97+
5498
## Bring your own Python
5599

56100
Press **Import .py** and pick any file. The whole program becomes blocks.
@@ -238,7 +282,7 @@ writes a tidy module with a `main()` and an `if __name__ == "__main__":` guard.
238282
python scratchpy_studio.py --selftest
239283
```
240284

241-
Builds the entire interface head-lessly, then **compiles every one of the 135
285+
Builds the entire interface head-lessly, then **compiles every one of the 148
242286
blocks**, checks the block definitions are well formed, round-trips a project
243287
through save and load, exercises the Python importer and the MCP server, and
244288
finally runs the generated example program and checks its output.

docs/screenshot-web.png

124 KB
Loading

docs/screenshot-webtester.png

117 KB
Loading

forever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
forever - generated by ScratchPy Studio 1.0.2.
2+
forever - generated by ScratchPy Studio 1.1.0.
33
44
This file is written automatically from the blocks in the
55
'forever' tab. Editing it by hand is fine, but the next time

helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
helper - generated by ScratchPy Studio 1.0.2.
2+
helper - generated by ScratchPy Studio 1.1.0.
33
44
This file is written automatically from the blocks in the
55
'helper' tab. Editing it by hand is fine, but the next time

runtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
runtest - generated by ScratchPy Studio 1.0.2.
2+
runtest - generated by ScratchPy Studio 1.1.0.
33
44
This file is written automatically from the blocks in the
55
'runtest' tab. Editing it by hand is fine, but the next time

0 commit comments

Comments
 (0)