Python API¶
Everything the CLI does is available programmatically:
from pathlib import Path
import sharepack
result = sharepack.build(Path("myproject"), Path("demo.html"))
print(result.n_files, "files,", result.size_bytes, "bytes")
for skipped in result.skipped:
print("skipped:", skipped.path, "—", skipped.reason)
Errors are typed: build raises sharepack.ProjectError for a bad
project path and sharepack.DetectionError when no supported
framework is found — both subclasses of sharepack.SharepackError.
sharepack¶
sharepack: turn a local Python web app into a single shareable HTML file.
- class sharepack.BuildResult(out, adapter_name, n_files, size_bytes, scrubbed, skipped, warnings, db_files, db_bytes)[source]¶
Everything a build produced, for reporting or programmatic use.
- Parameters:
- out¶
Path of the written HTML file.
- Type:
- skipped¶
Files that were not bundled, with reasons.
- class sharepack.CollectionResult(files=<factory>, scrubbed=<factory>, skipped=<factory>)[source]¶
Everything the collect pass learned about a project.
- skipped¶
Files that were not bundled, with reasons.
- exception sharepack.DetectionError[source]¶
No supported framework could be detected in the project.
- sharepack.build(project, out, *, include=(), exclude=(), settings_module=None, app_spec=None, pyodide_version='0.26.4', pip_pin=None)[source]¶
Bundle a project into a single self-contained HTML file.
- Parameters:
project (Path) – Project root directory (for Django: contains manage.py).
out (Path) – Path of the HTML file to write.
include (Sequence[str]) – Glob patterns forcing extra files into the bundle.
exclude (Sequence[str]) – Glob patterns keeping files out of the bundle.
settings_module (str | None) – Explicit Django settings module, bypassing detection from manage.py.
app_spec (str | None) – Explicit
module:variablelocating a Flask or FastAPI app, bypassing entry-module scanning.pyodide_version (str) – Pyodide release loaded from the CDN at view time.
pip_pin (str | None) – Override for the framework’s pip requirement string.
- Returns:
A report of what was built.
- Raises:
ProjectError – If
projectdoes not exist or is not a directory.- Return type:
Note
A
DetectionErrorpropagates from framework detection when no supported framework is found inproject.
- sharepack.collect(project, include=(), exclude=())[source]¶
Collect a project’s files for bundling, scrubbing secrets.
- Parameters:
project (Path) – Project root directory to walk.
include (Sequence[str]) – Glob patterns (against posix relative paths) that force files into the bundle even if their extension is not bundled by default. Secret exclusions still apply.
exclude (Sequence[str]) – Glob patterns that keep files out of the bundle; they take precedence over everything else.
- Returns:
The bundled files plus scrub and skip diagnostics.
- Return type:
sharepack.collect¶
Walk a project directory, collect files, scrub secrets.
- class sharepack.collect.SkippedFile(path, reason)[source]
A file that was not bundled, and why.
- class sharepack.collect.CollectionResult(files=<factory>, scrubbed=<factory>, skipped=<factory>)[source]
Everything the collect pass learned about a project.
- skipped
Files that were not bundled, with reasons.
- property total_bytes: int
Total size of all bundled files in bytes.
- property db_bytes: int
Total size of bundled database files in bytes.
- sharepack.collect.collect(project, include=(), exclude=())[source]
Collect a project’s files for bundling, scrubbing secrets.
- Parameters:
project (Path) – Project root directory to walk.
include (Sequence[str]) – Glob patterns (against posix relative paths) that force files into the bundle even if their extension is not bundled by default. Secret exclusions still apply.
exclude (Sequence[str]) – Glob patterns that keep files out of the bundle; they take precedence over everything else.
- Returns:
The bundled files plus scrub and skip diagnostics.
- Return type:
sharepack.build¶
Assemble the single-file HTML artifact.
- class sharepack.build.BuildResult(out, adapter_name, n_files, size_bytes, scrubbed, skipped, warnings, db_files, db_bytes)[source]
Everything a build produced, for reporting or programmatic use.
- Parameters:
- out
Path of the written HTML file.
- Type:
- adapter_name
Name of the detected framework adapter.
- Type:
- n_files
Number of files bundled.
- Type:
- size_bytes
Size of the written HTML file in bytes.
- Type:
- skipped
Files that were not bundled, with reasons.
- db_bytes
Total size of bundled database files in bytes.
- Type:
- sharepack.build.build(project, out, *, include=(), exclude=(), settings_module=None, app_spec=None, pyodide_version='0.26.4', pip_pin=None)[source]
Bundle a project into a single self-contained HTML file.
- Parameters:
project (Path) – Project root directory (for Django: contains manage.py).
out (Path) – Path of the HTML file to write.
include (Sequence[str]) – Glob patterns forcing extra files into the bundle.
exclude (Sequence[str]) – Glob patterns keeping files out of the bundle.
settings_module (str | None) – Explicit Django settings module, bypassing detection from manage.py.
app_spec (str | None) – Explicit
module:variablelocating a Flask or FastAPI app, bypassing entry-module scanning.pyodide_version (str) – Pyodide release loaded from the CDN at view time.
pip_pin (str | None) – Override for the framework’s pip requirement string.
- Returns:
A report of what was built.
- Raises:
ProjectError – If
projectdoes not exist or is not a directory.- Return type:
Note
A
DetectionErrorpropagates from framework detection when no supported framework is found inproject.
sharepack.adapters¶
Framework adapters.
Each adapter knows how to detect a framework and supply the template context that boots it inside Pyodide.
- sharepack.adapters.detect(project, files, settings_module=None, app_spec=None)[source]¶
Return the first adapter that recognizes the project, or raise.
- Parameters:
project (Path) – Project root directory.
files (dict[str, bytes]) – Collected project files keyed by relative path.
settings_module (str | None) – Explicit Django settings module, bypassing detection from manage.py.
app_spec (str | None) – Explicit
module:variablelocating a Flask or FastAPI app, bypassing entry-module scanning.
- Returns:
The adapter instance for the detected framework.
- Raises:
DetectionError – If no adapter recognizes the project.
- Return type:
DjangoAdapter | FlaskAdapter | FastAPIAdapter
Django adapter: detection, compatibility warnings, and boot script.
- class sharepack.adapters.django.DjangoAdapter(settings_module, db_files, warnings, static_url='/static/')[source]¶
Detects a Django project and supplies its Pyodide boot context.
- classmethod detect(project, files, settings_module=None, app_spec=None)[source]¶
Recognize a Django project from its collected files.
- Parameters:
- Returns:
An adapter instance, or None if this is not a Django project.
- Return type:
DjangoAdapter | None