mirror of
https://github.com/vladmandic/automatic
synced 2026-08-25 22:20:46 +02:00
Page:
Dev Extensions
Pages
AMD MIOpen
AMD ROCm
API
Advanced Install
Benchmark
CHANGELOG
CLI Arguments
CLI Tools
CLiP Skip
Caption
Control HowTo
Control Settings
Control Technical
Debug
Detailer
Dev AICoding
Dev Docs
Dev Extensions
Dev GettingStarted
Dev Hints
Dev Home
Dev Locale
Dev SelfStart
Dev Structure
Dev Theme
Dev UI
DirectML
Docker
Enso
FAQ
FLUX
Features
FramePack
Gated
Getting Started
Google GenAI
HiDream
Home
Hotkeys
HuggingFace
IPAdapter
Ideogram
Installation
Intel ARC
Kanvas
LTX
Launcher
LoRA Technical
LoRA
Loader
MacOS Python
Malloc
MiniMax
Model Loading
Model Support
Models Tab
Models
Networks Search
Networks
Notes
NudeNet
Nunchaku
ONNX Runtime
Offload
OpenVINO
Outpaint
Parameters
Performance Timers
Performance Tuning
Platforms
Process
Profiling
Prompt Enhance
Prompting
Python
Quantization
Reprocess
SD Pipeline How it Works
SD Training Methods
SD XL
SD3
SDNQ Quantization
Schedulers
Scripts
Stability Matrix
Stable Cascade
Styles
Themes
Troubleshooting
Update
Using LCM
VAE
Video
WSL
Wildcards
XYZ Grid
ZLUDA
_ToDo
index
nVidia
Clone
1
Dev Extensions
Vladimir Mandic edited this page 2026-05-20 20:09:25 +02:00
Dev: Script & Extensions Guide
Common Mistakes
- Execution on import:
Keep extension modules import-safe. Do not run work at import time (except trivial and allowed
install.pysetup). Put logic inside functions/classes and run it from app callbacks. Import-time execution can slow startup or crash the server. - Keeping all Python code in
/scripts: Use/scriptsas the entry point only. Split implementation into other modules outside/scriptsand import them from the entry file. Otherwise, server startup may load and execute files repeatedly. - Browser namespace collisions:
JavaScript files are loaded into a shared global namespace.
Use unique prefixes for functions and variables instead of generic names such as
log(). - Incorrect callback usage:
Choose callbacks carefully.
onUiLoadedruns once, whileonUiUpdatedcan run many times during startup. Running heavy initialization in a frequently called callback causes slow page loads and repeated work. This applies to both Python and JavaScript. - Executing code when disabled: If an extension is disabled, callbacks should early-exit and do no work. Otherwise, you can add avoidable delays before, during, or after generation.
- Unsafe references:
Treat callback data and server variables as optional unless guaranteed.
For example,
image.infomay not exist for every image. Use safe access helpers such asget()orgetattr(). The same applies to settings: do not assume they never change. - Unsafe patching:
Extensions can patch server methods, but patch carefully.
For example, replacing
forwardshould avoid global behavior that breaks other extensions. - Running platform-specific code:
Avoid hard-coding platform/backend behavior.
Do not force values such as
torch.to('cuda')ortorch.float16. Use server variables such asdevices.deviceanddevices.dtype. - Assuming values:
Do not assume install paths or runtime values.
For example, an extension may not be located under
/extensions.
Many popular extensions still hit several of these issues. Remember that installing an extension grants it broad access, so implementation quality and safety matter.
Extension vs Script
- Script is a single module that implements script callbacks.
- Script objects inherit from
Scriptand implement required methods plus optional callbacks. - Extension is a larger implementation with its own folder structure.
- Extension can contain multiple scripts or operate through its own hooks.
Extension Folder Structure
Note: all files listed below are optional.
/preload.pyLoaded early during startup to add command line arguments. Definepreload(parser: argparser)and avoid other work at this stage./install.pyLoaded early during startup to install optional requirements. Use supported helpers such aslaunch.run_pip. Avoid direct OS calls or unrelated work./javascript/*.jsJavaScript files are injected as-is. Keep files limited to defining functions/variables and registering callbacks./style.cssStyle is loaded as-is./scripts/*.pyMain extension entry points loaded by the server during startup. Keep files focused on definitions and callback registration.