Embed subfiles (HTML, CSS, JS) inside Python scripts and display them in a native window
Project description
ScriptCore
ScriptCore is a tiny Python library and standalone script that lets you embed web assets
(HTML/CSS/JS/etc.) directly inside a Python source file. When the Python file is run, the
is_main="true" subfile is extracted and rendered inside a built‑in browser window (via
QtWebEngine) or printed/text‑viewed.
Features
- HTML/CSS/JS can live alongside Python code in
main.py. - Works as a standalone script or as an importable package.
- Embedded viewer uses PySide6 (
QtWebEngine) for true web rendering. - Also supports simple CLI extraction/listing via
scriptcoreconsole command.
Installation
pip install scriptcore # from PyPI once published
# or for development:
pip install -e .
PySide6 is a runtime dependency; it is declared in pyproject.toml and will be pulled
in automatically. On platforms where QtWebEngine is unavailable you can still use the
parse_subfiles/write_subfiles_to_dir API without the viewer.
Usage as standalone main.py
Create a Python file with embedded SCRIPTCORE blocks:
#!/usr/bin/env python3
import re
# (parser code omitted for brevity; see provided template)
SCRIPTCORE subfile
subfile{
FileType=".html"
FileID="index.html"
is_main="true"
{
<h1>Hello world</h1>
}
}
Run the script:
python main.py
A window will open rendering the HTML. You can copy the standalone script anywhere – it does not need access to the package directory.
CLI / Package API
from scriptcore import parse_subfiles, write_subfiles_to_dir, launch_viewer
subs = parse_subfiles(open('main.py').read())
write_subfiles_to_dir(subs, 'out') # extract files
launch_viewer(subs) # open Qt viewer
The console script scriptcore provides --source, --list, --extract, --open.
Publishing
This project uses a minimal pyproject.toml (PEP 621). To build and upload to
PyPI:
python -m build
python -m twine upload dist/*
License
MIT – see LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scriptcore-0.1.0.tar.gz.
File metadata
- Download URL: scriptcore-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dbdb9d71168cdb75fe82973b1f22625e288389b0763b98446ca88f330fc26f8
|
|
| MD5 |
8916418e2e7ba6f57e81b87f5bfb3987
|
|
| BLAKE2b-256 |
c4ca3f107c4caeccb6b5fe61d5e988cea700b17bd3e9cf37e9e1ee6a3d998c33
|
File details
Details for the file scriptcore-0.1.0-py3-none-any.whl.
File metadata
- Download URL: scriptcore-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbb27e41a7cc52fb49f961cdb39507ac80921dd45fa0b5df08569cb7d2d11fe7
|
|
| MD5 |
14a19df14b5dbb7940ba5473688412b6
|
|
| BLAKE2b-256 |
a79345331765fb377c5e03af912fe86d82a4cf0a8262b17d0fb5d4e1027c18d5
|