Status: design agreed 2026-11-30. Revised 2026-12-01: the package list uses the official MicroPython index instead of a PyBlocks-curated catalogue, and local upload accepts ZIP archives. Implemented: nested library paths, local .py/.zip upload with path confirmation, the micropython.org package list and nested deployment. Pending: URL import. This document supersedes the earlier proposed in-browser library source editing workflow in Reuse.
- Paths and conflicts:
src/project/libraries.js(validation, batch planning, UTF-8 decoding). Project format v1 is unchanged;nameis the relative path. Projects whose libraries includemain.py/boot.pyat the library root or invalid paths are now rejected on load, without migration. - Package list:
src/libraries/micropython-index.jsreadshttps://micropython.org/pi/v2/index.json(CORS*, 129 packages on 2026-12-01) andpackage/py/<name>/<version>.json, downloads content-addressed files fromfile/<hash[:2]>/<hash>and verifies each SHA-256 prefix. The index already flattensrequire()into each package's file list; a package that declares remotedepsis rejected rather than resolved. All 129 packages (249 files) passed path validation. Only thepysource variant is used, never.mpy. Descriptions are upstream English text, and about two thirds are empty. - The editor reads the curated package list from
src/libraries/curated-packages.json. The list includes TM1637 from mcauser/micropython-tm1637. PyBlocks pins the upstream commit and checks the downloaded Python file against its SHA-256. The source contains its MIT notice and is stored in the project after installation. - ZIP:
src/libraries/zip.jsreads stored/deflated entries with nativeDecompressionStream, enforces declared sizes and CRC-32, and rejects encryption and ZIP64.src/libraries/archive.jssuggests a root (dropping a non-identifier wrapper such asrepo-main/) and pre-selects files outsidetests/,examples/,docs/. The user confirms the root and each destination path. - Limits: 256 KB per file, 1 MB per addition, 8 MB per local archive.
- Deployment:
deployPrograminsrc/device/micropython.jscreates parent directories under the library directory and rejects nested paths on flat filesystems before writing anything.
Project format v1 stores optional dependencies alongside libraries. Each dependency records source (micropython, curated, or local), its display name, the downloaded version for indexed and curated packages, and the library paths in files. Local imports use the original ZIP or Python filename. Older snapshots without group records show their files in a single expandable group. Adding the original package associates matching files with the named dependency.
The Libraries panel expands each dependency to show its files. Removing a dependency keeps files referenced by other groups. If a confirmed import overwrites a package file, that package no longer represents its downloaded version. Its remaining files are kept, and any unshared files appear in the expandable group. Deployment still reads the Python source directly from libraries.
The original proposal below describes the earlier catalogue and file-by-file UI.
Make third-party MicroPython modules easy to discover and attach to a project without choosing or connecting a board. The browser downloads or reads source files; the project owns a portable snapshot; ordinary Python imports refer to those files; the existing Upload and run flow deploys them with the entry program.
Keep PyBlocks a lightweight block programming environment, not a full Python IDE or package manager. Do not require a backend, a desktop helper, a Python runtime in the browser, or network connectivity on the board.
Extend the existing Libraries category/panel rather than introducing another independent project-file panel.
| Action | Source | User experience |
|---|---|---|
| Browse libraries (浏览库) | PyBlocks curated Registry | Browse the curated entries directly in the existing Libraries flyout, inspect name, description, version, upstream source, compatibility notes and file paths, then select Add to project. |
| Import from URL (从 URL 导入) | User-provided public HTTPS source URL | Accept a direct Python source URL or a supported GitHub file-page URL. Explain that the source server must permit browser cross-origin access. Show/confirm the destination module-relative path and add the downloaded source. |
| Upload file (上传文件) | User's computer | Keep the existing local file picker; read a valid .py file, default to its basename and allow an explicit relative destination path. |
All three converge on the same validation, collision handling, project mutation, autosave and library list. Use the existing visual style, compact controls, localized statuses and explicit confirmation before replacing differing files. Show the resulting filename(s), not a separate package installation state. An attached library can be removed from the project. No library source editor or new-file editor in this scope; users can author their Python externally and upload it.
The Libraries flyout itself contains the current project files (with relative paths and per-file removal) and the curated Registry entries (with Add and an expandable file list). Place URL import and local upload controls at its top. Do not build a separate library management page or a custom Blockly block type. The catalogue groups files for discovery only; the project owns actual files, not installed package records. No package uninstall, dependency ownership tracking or automatic file removal. A catalogue entry may be marked present only when all its paths and expected contents are known to match; do not infer a version match from filenames alone.
No device is needed for browsing, importing, adding, removing, saving or exporting libraries.
A curated, version-controlled static JSON catalogue in the PyBlocks repository, served with the static application. Prefer bundling the catalogue as a regular JSON import with Vite so that the existing static/PWA deployment remains simple. It is not a separate service, a search engine for all GitHub repositories, or a mirror of all upstream code. Keep actual source hosted by the respective upstream projects.
Proposed minimal schema (illustrative placeholder values, not verified downloadable entries):
{
"version": 1,
"libraries": [
{
"id": "example-display",
"name": "Example display",
"description": {
"en": "Example display driver",
"zh-CN": "示例屏幕驱动"
},
"version": "1.0.0",
"homepage": "https://github.com/example/display",
"license": "MIT",
"notes": {
"en": "Requires machine.I2C and framebuf",
"zh-CN": "依赖 machine.I2C 和 framebuf"
},
"files": [
{
"path": "example_display/__init__.py",
"url": "https://raw.githubusercontent.com/example/display/COMMIT/example_display/__init__.py"
},
{
"path": "example_display/driver.py",
"url": "https://raw.githubusercontent.com/example/display/COMMIT/example_display/driver.py"
}
]
}
]
}- IDs are stable and unique. Each entry describes an intentionally selected source release, with a list of one or more .py files at explicit paths relative to the device library root needed for that library. Prefer immutable upstream commit URLs and actual release/version labels. A displayed version is descriptive, not a version-resolution algorithm.
- Preserve upstream licensing notices and attribution; verify redistribution terms, license, URLs, module names and expected imports before publishing an entry. Provide any required license text/notices with the imported source or portable project; do not rely on a homepage link alone when the license requires redistribution of notices.
- Start with a small set of genuinely usable, source-based MicroPython hardware drivers (SSD1306 is a candidate), not a huge index. Verify browser CORS and actual source content before adding entries. Do not claim a driver works on every board; firmware-provided modules do not need to be downloaded again.
- List all required source files explicitly, including known transitive dependencies, preserving their upstream import layout and any required init.py files. Curation, not a runtime dependency solver, supplies the complete file set. Do not invent package directories around flat modules or rewrite their imports. Do not implement recursive dependency resolution, semantic-version solving, .mpy ABI selection, arbitrary manifest execution or automatic updates in V1. Libraries requiring unsupported runtime features, binaries or non-Python resources remain out of scope.
The catalogue is deliberately simpler than mip. Reconsider compatibility with the upstream mip manifest format if concrete use cases justify it; do not invent a general package standard.
Use normal browser fetch, without cookies or credentials, and respect CORS. Accept public HTTPS URLs only. A supported GitHub blob file-page URL can be converted to raw.githubusercontent.com; preserve the explicit ref and path. For ambiguous refs containing slashes or unsupported repository/tree URLs, request the exact Raw file URL rather than guessing. Raw URLs with query strings must not leak secrets into logs; avoid accepting credential-bearing URLs. Arbitrary HTTPS hosts are allowed only when their responses can actually be read by the browser. No CORS bypass, proxy service or GitHub token requirement.
Resolve the destination relative path from the catalogue, or default to the source basename for a URL/local file; allow explicit correction for user imports. Use canonical slash-separated paths relative to the library root, not to the device root. Each directory and the final .py stem must be a valid Python identifier (ASCII identifier rule consistent with current validation). Reject absolute paths, backslashes, empty/dot/dot-dot segments, drive prefixes, control characters, unsupported extensions and reserved entry/runtime filenames main.py and boot.py at least at the library root (case-insensitive). Do not silently normalize traversal or flatten packages. Apply the same rules to all three entry points and revalidate before deployment; report invalid legacy names explicitly.
Fetch failures, HTTP errors, CORS/network errors, empty or non-source responses (e.g. HTML login/error pages), invalid UTF-8 and oversized downloads should produce actionable localized messages. JavaScript fetch cannot reliably distinguish CORS from every network failure; explain both without asserting an unsupported cause. Choose a documented modest size limit before implementation, enforce it on downloaded bytes and local uploads, and avoid rendering or executing remote code in the browser. Source is untrusted device code: indicate its origin and let users choose only trusted libraries. Source is data until the explicit program upload/run step.
Existing portable project format v1 contains libraries: [{name, source}]. Proposed minimal extension: retain the existing name field, interpreting it as the canonical relative file path (e.g. ssd1306.py, umqtt/simple.py, sensor_a/utils.py). Existing flat records remain valid; no IndexedDB migration or redundant package records are needed. Older editor versions with the flat-only validator will reject nested paths, so test and document that compatibility boundary rather than claiming backward readability. The registry is only a discovery source: never save only an external URL or fetch dependency contents again automatically on opening/exporting/uploading a project.
Proposed import transaction:
- Resolve candidate file(s) and fetch/read their UTF-8 source.
- Validate every path and source size; compare the entire staged set against itself and existing project files. Different directories may contain the same basename. Use case-insensitive path keys for portability, and reject inconsistent directory casing, file/directory collisions and ambiguous module/package layouts (e.g. foo.py together with foo/init.py), reporting the affected paths.
- Identical canonical paths with identical source may be deduplicated. The same path with different contents is a conflict, not a new version to install silently. Reject conflicting files within the incoming batch; for existing project conflicts, list the paths and require explicit replacement confirmation (or cancel the whole addition). Reject invalid batches before any mutation. Do not rename files automatically or assume two libraries requiring incompatible versions of the same import can coexist; the user must resolve such a conflict.
- Commit the complete set in one panel state change and use the existing project autosave path. If fetch fails or the user cancels, preserve the prior project. Guard asynchronous imports against project replacement/navigation and concurrent library changes.
- Report success only for files actually added; storage failures must remain visible. Use the existing project export/import and duplicate behavior to carry the complete source snapshot.
Keep source/licensing notices in the source as required. If additional provenance metadata is necessary, make it optional and backward compatible in the existing library records, with a documented round-trip test; do not introduce a second library database or new project format by default. Project copies must not share mutable external source references. Removing a library from a project must not automatically delete any file on a connected device.
Use the existing native Python import and from-import blocks. Adding a library does not automatically generate an import or new blocks. For example, adding ssd1306.py allows the user to write from ssd1306 import SSD1306_I2C if that class is provided by the actual upstream source.
The current src/device/micropython.js downloadProgram implementation writes project libraries first (to a library directory found in sys.path on directory-capable devices, or the flat filesystem otherwise) and then writes main.py. Extend this existing path to create validated parent directories under that library root before writing each file, using the current raw REPL and filesystem helpers. For a flat-only device, preflight all project paths and reject any nested path before writing libraries or main.py; never flatten a package. Check directory creation failures and distinguish an existing directory from a conflicting file. Preserve the upload sequence and current upload/run interface. No direct installation action from the library browser. Do not introduce a second serial implementation or install mip on the device. A failed dependency write must not proceed as if the new main.py was deployed; the existing filesystem path is not a transactional rollback mechanism.
SPIKE slot deployment does not support project libraries in the current path; keep its explicit unsupported error. Do not silently omit libraries. No device discovery, firmware installation, class blocks or custom Blockly block registration changes are required.
- Audit
src/editor/libraries.js, the Libraries panel markup, translations,src/project/storage.js,src/device/micropython.jsandsrc/device/micropython/filesystem.js. Introduce shared relative-path validation and batch conflict checks, extend portable validation and deployment to nested paths, and keep existing flat imports working. - Add the static catalogue and a small browser-only URL/source loader with injectable fetch for tests. Validate the initial curated entries against upstream source, license and browser CORS. Keep fetching independent of serial/device APIs.
- Add curated entries and URL-import UI inside the existing Libraries flyout; route curated, remote and local source through the common project mutation path. Handle pending, failure, cancellation, empty catalogue, duplicates and replacement. Preserve the existing library panel layout.
- Verify autosave, portable round trips, offline use of attached files, and upload ordering; update user guide and localized messages. Keep the dependency feature independent of Backpack.
- Browse curated entries, add a single file or explicit multi-file entry without any attached board; all files appear in the current project.
- Add a GitHub Raw URL, supported GitHub blob URL, and arbitrary CORS-enabled HTTPS URL; the selected filename is importable. A blocked/unreachable URL, invalid source or partial download leaves the project unchanged.
- Upload a local .py file; invalid, reserved and conflicting paths receive consistent treatment for all entry points. Cancel replacement without losing existing contents. Add two packages each with its own utils.py and verify both survive, retaining required init.py files and original imports. Reject traversal, absolute paths, file/directory conflicts, case aliases and incompatible same-path sources. Deduplicate identical shared sources.
- Refresh, reopen, duplicate, export and reimport the project: exact attached source contents survive and no remote fetch is required to use them. A different project has no implicit libraries.
- Confirm nested parent directories are created and dependencies are sent before main.py through existing MicroPython deployment; verify a flat-only device rejects nested paths before writes and unsupported SPIKE library uploads still fail explicitly. Test at least one real MicroPython device separately.
- Add automated tests for catalogue schema, URL normalization, validation, mocked fetch/error paths, collision/batch atomicity, stale async operations, project serialization and upload ordering. Run npm test and the existing build/deployment CI. Browser interaction and real-device validation are separate from CI.
ViperIDE package manager source (MIT): browser-side index retrieval, GitHub URL normalization and file downloading are relevant precedents; its direct installation, recursive dependencies, cross-origin proxy and device/MPY handling are not requirements for PyBlocks. If code is copied, preserve the applicable MIT copyright and license notice.
MicroPython package management: mip and official package formats are useful reference material, not runtime dependencies for the browser implementation.
Existing internal paths: src/editor/libraries.js, src/project/storage.js, src/project/repository.js, src/device/micropython.js.