sme-sim-common
Shared runtime for the smart-edge simulator series (SME BACnetSim, SME ModbusSim, the OCPP simulator,
SME SerialHub): the web shell (header, menus, theme, languages, About), vendor texts, the common.*
UI strings, and the protocol-independent Python layer (web helpers, config I/O, behaviors, device
templates, test helpers, PyInstaller hook). The templates/ directory holds the build-time skeleton
(CI, release, packaging, docs, page) that products copy by hand; it is not part of the wheel.
MIT-licensed, developed by smart-edge (智届科技).
Install
pip install "sme-sim-common>=1.0,<2" # in a product's pyproject.toml dependencies
pip install "sme-sim-common[xlsx]>=1.0,<2" # with the .xlsx import / export helpers (openpyxl)
pip install -e ../sme-sim-common # local development against a checkout
Python 3.11 or newer.
Using it in a product
Mount the common static files
from fastapi import FastAPI
from sme_sim_common.web import mount_common, mount_product_static
app = FastAPI()
mount_common(app) # serves /sme-sim-common/{shell,vendor,i18n,brand}/...
mount_product_static(app, STATIC_DIR) # the product's own /static (skipped if the directory is missing)
The common files live under their own prefix /sme-sim-common, never under /static: Starlette matches
mounts in registration order, so a nested path would be swallowed by the product's /static mount.
Minimal app
import argparse
from pathlib import Path
from sme_sim_common.cli import add_common_args, run_web
from sme_sim_common.web import make_base_app
ap = add_common_args(argparse.ArgumentParser(), default_http_port=8080, app_name="sme-my-sim")
args = ap.parse_args()
engine = MyEngine(...) # follows sme_sim_common.engine.EngineProtocol (or subclass BaseEngine)
app = make_base_app(engine, config_path=args.config, static_dir=Path(__file__).parent / "static")
run_web(app, args) # uvicorn on args.host / args.http_port, opens the browser
Page skeleton
Start from templates/static/index.html. The load order is fixed:
/sme-sim-common/shell/shell.cssthen the product/static/style.css/sme-sim-common/shell/shell.jsin<head>withdata-storage="<dist name>"(localStorage prefix; the stored theme is applied before first paint)/sme-sim-common/vendor/vendor.js, then/sme-sim-common/i18n/common.js- the product dictionaries
/static/i18n/en.js,ja.js,zh.js, then/static/app.js
The common assets carry a ?v= version query so browsers do not keep stale shell files after an upgrade;
Shell.version reports the sme-sim-common version and the About dialog shows it.
Vendor
vendor/vendor.js registers the company preset Shell.vendors.smartEdge and the vendor.* strings.
Products pass it explicitly:
Shell.init({ ...PRODUCT, vendor: Shell.vendors.smartEdge });
Company texts are maintained only here, so a change reaches every product with the next common release.
i18n prefixes
| Prefix | Owner |
|---|---|
shell.* |
sme-sim-common: UI framework (menus, theme, language, help, About) — shell.js |
vendor.* |
sme-sim-common: company texts — vendor/vendor.js |
common.* |
sme-sim-common: features provided by the common layer — i18n/common.js |
| anything else | the product — static/i18n/{en,ja,zh}.js |
Products must not define the three reserved prefixes. Guard it in the product tests:
from sme_sim_common.testing import check_i18n_keys
def test_no_reserved_i18n_keys():
check_i18n_keys(STATIC_DIR)
common.* keys are named after the feature, not the menu position, and must be unambiguous in every
product of the series (e.g. common.backend.connected, not ws.on).
Accent color
Each product has its own accent color. shell.css defaults to the brand blue #087def; a product
overrides --accent, --accent-ink and --accent-weak in three blocks of its style.css
(:root, :root[data-theme="dark"] and the prefers-color-scheme: dark block) — see
templates/static/style.css. The vendor area uses --vendor-accent (always brand blue) and must not be
overridden.
Extension points
All optional; products pass them instead of re-implementing the standard routes.
- Device keys:
key_type(default: the type of thedevice_keyfield,intorstr) converts the path parameter —make_base_app(engine, device_key="device_id")reads/api/devices/1001/configas1001. create_hook(engine, body) -> dictcompletes a new device before validation:create_hook=lambda e, b: {**b, "device_id": b.get("device_id") or free_id(e)}.duplicate_hook(engine, dev, new_key, body) -> dictruns before the "already exists" check and may change the key:duplicate_hook=lambda e, d, k, b: {**d, "unit": free_unit(e)}. Without a hook the copy is keyed{key}_copy(strkeys) or largest key + 1 (intkeys).simulation_hook(engine, rest) -> dict | Nonegets thePOST /api/simulationfields other thanrunning/time_scale; a dict result is merged into the response:simulation_hook=lambda e, rest: e.apply_set_time(rest).TemplateRegistry(..., extra_keys=("identification",))allows extra top-level keys in user templates;registry.expand_device_extras(dev)returns them merged with the device's own fields (non-empty device value wins, dicts merged shallowly) anddevice_as_templateexports them.import_hooks={".csv": import_ede, ".zip": import_ede, ".yaml": import_text}forPOST /api/config/import:hook(engine, files: dict[name, bytes]) -> (config | None, messages[, config_text]);.xlsx(and any other extension) still goes to theXlsxSchema. The event log records the warning count and the first 5 warnings.add_common_args(ap, ..., open_browser=False): do not open the browser by default (--browseropens it,--no-browseris kept).engine.wake(): run one_on_tick(scan / push) now, without advancing simulated time or shifting the tick schedule; thread-safe:stack.on_write = lambda *a: engine.wake().logger_name = "sme_my_sim.engine"on aBaseEnginesubclass namesself.logger, used for all engine logging.duplicate_hookwith asrc_keykeyword (or**kwargs) also gets the source device's key, e.g. "first free key after the source":def dup(engine, dev, new_key, body, *, src_key). Hooks without it are called as before;devis a fresh copy (source dump + new key), the source device is never passed.- 404 for an unknown device shows the converted key:
unknown device 1008(intkeys unquoted). Sheet(..., open_columns=True): on export the scalar fields without a column become dynamic columns (after the known ones, in order), sotext_1...text_12round-trip;export_rowsmay also return(rows, {sheet: [(header, help), ...]})to name extra columns explicitly (they come first).export_rowsmay return(rows, extra_columns, warnings)(extra_columnsmay beNone): the product's own export warnings (e.g. a dangling reference) come back fromexport_xlsxbefore the shared ones (cell limit).Sheet(..., required_headers=("value",)): the column must exist but cells may be empty (requiredkeeps "present and non-empty");skip_blank=("value",)silently skips rows whosevalueis empty (key / value sheets such asNetwork).
Migration notes
stateis an instance attribute ofBaseEngine(the result of_build); a subclass must not define astate()method.BaseEngine.event_history(limit)is the common event log; it does not clash with a product's own history (e.g. a per-pointhistory(device_id, key)API).- The routes of a FastAPI
APIRouterpassed inproduct_routersare flattened intoapp.routes(noinclude_routerwrapper); they remainAPIRoutes, dependency injection works as usual.
Tests and packaging
- The pytest plugin (asyncio timeout + hang dump) is activated automatically through the
pytest11entry point. - The PyInstaller hook (
pyinstaller40entry point) collects the common static files and the uvicorn hidden imports, so product spec files list only their own files.
Series port table
Default web UI ports, so that sibling products can run side by side. New products register here first.
| Product | Default HTTP port |
|---|---|
| SME BACnetSim | 8080 |
| SME ModbusSim | 8081 |
| OCPP simulator | TBD |
| SME SerialHub | TBD |
Series accent table
| Product | --accent |
--accent-ink |
--accent-weak |
Dark theme |
|---|---|---|---|---|
| SME BACnetSim | #087def (brand blue, shell default) |
#fff |
#e7f2fe |
shell default (#3d9bff / #fff / #11304f) |
| SME ModbusSim | #0f766e (teal) |
#ffffff |
#ccfbf1 |
#2dd4bf / #042f2e / #134e4a |
| OCPP simulator | TBD | TBD | TBD | TBD |
| SME SerialHub | TBD | TBD | TBD | TBD |
Versioning
- Semantic Versioning, first release
1.0.0. Within 1.x only backward-compatible additions (new keys, new optional parameters, new modules) and fixes; a breaking change would be 2.0 and is avoided. - Products depend on
sme-sim-common>=1.0,<2. - The single version source is
sme_sim_common.__version__;Shell.versioncarries the same value.
Templates
See templates/CHECKLIST.md for adopting the templates in a new or migrated
product (placeholders, port / accent registration, i18n rules, PyInstaller, PyPI trusted publishing).
Releasing sme-sim-common
- Update
__version__and theCHANGELOG.mdsection## [x.y.z] - YYYY-MM-DD. - Push the tag
vx.y.z..github/workflows/release.ymlbuilds the sdist and wheel, checks them withtwine, publishes to PyPI with trusted publishing (environmentpypi) and creates the GitHub Release with the CHANGELOG section as notes. The workflow file namerelease.ymland the environment namepypiare registered on PyPI; do not rename them.
License
MIT — see LICENSE.
Metadata
Release files for sme-sim-common 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sme_sim_common-1.0.0.tar.gz | 84.2 kB | With provenance | Details for sme_sim_common-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sme_sim_common-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for sme_sim_common-1.0.0-py3-none-any.whl |
Total release size: 148.7 kB
Release files / sme_sim_common-1.0.0.tar.gz
| Download URL | sme_sim_common-1.0.0.tar.gz |
|---|---|
| Size | 84.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35031fe877492603182929c347a723c5d208c33ab9d5f9cb711f8e796ee32b7e
|
|
BLAKE2b-256 checksum How to use checksums |
f2cd58bd137708085c9ea3380fa1b9a8e15ed221c9a74744204655bd427c02fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / sme_sim_common-1.0.0-py3-none-any.whl
| Download URL | sme_sim_common-1.0.0-py3-none-any.whl |
|---|---|
| Size | 64.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7d8301ac53ddebd6f572686a77603ef23ca9457ae6999c9c45c083bcb043c2a
|
|
BLAKE2b-256 checksum How to use checksums |
67aedb73f6c2214f097df5d196a62f6cd0090c5c2979d6bd739a3da758f447cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for sme-sim-common 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sme_sim_common-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.