Some of the scripts sold on this site run automatically every time QGIS opens — applying styles, detecting layer types, generating indices. This guide explains how to set that up. You only need to do this once, and no coding is required.
What you need
- QGIS 3.28 or newer
- The startup scripts you have downloaded (each is a
.pyfile) startup_script.py— the entry point that tells QGIS which scripts to load (included with your purchase or downloadable below)
Step 1 — Create a scripts folder
Make a folder anywhere on your machine to hold all your QGIS scripts. A good location:
Documents/QGIS_scripts/Startup_scripts/
Inside that folder, place two things:
- An empty file named
__init__.py— this tells Python to treat the folder as a package. Just create a blank file with that exact name. startup_script.py— the entry point (see below).
Your downloaded scripts (e.g. auto_style_geojson.py) go in the same folder alongside them.
Startup_scripts/
├── __init__.py ← empty file, required
├── startup_script.py ← the entry point
├── auto_style_geojson.py ← a downloaded startup script
├── auto_generate_ndvi.py ← another downloaded startup script
└── ...
Step 2 — Tell QGIS where the entry point is
- Open QGIS
- Go to Settings → Options → System → Environment
- Tick Use custom variables
- Add a new row:
| Apply | Variable | Value |
|---|---|---|
| Overwrite | PYQGIS_STARTUP | full path to your startup_script.py |
The value should be the full path — for example:
/Users/yourname/Documents/QGIS_scripts/Startup_scripts/startup_script.py
- Click OK and restart QGIS.
Step 3 — Register each script in startup_script.py
startup_script.py is the file that decides which scripts run on launch. Open it and you will see a delayed_start function with a block like this — one pair of lines per script:
def delayed_start():
import Startup_scripts.auto_style_geojson as auto_style_geojson
auto_style_geojson.run()
import Startup_scripts.auto_generate_ndvi as auto_generate_ndvi
auto_generate_ndvi.run()
# add more scripts below in the same pattern ...
When you download a new startup script, copy it into the Startup_scripts/ folder and add the same two lines for it — using the script’s filename (without .py) as the name:
import Startup_scripts.your_script_name as your_script_name
your_script_name.run()
Restart QGIS and it will run automatically from that point on.
To turn a script off without deleting it, put a # in front of both lines:
# import Startup_scripts.auto_generate_ndvi as auto_generate_ndvi
# auto_generate_ndvi.run()
What a startup script looks like
Each script you download follows this pattern — a single run() function that QGIS calls at launch. Here is auto_style_geojson.py as an example:
# auto_style_geojson.py
# Automatically styles any GeoJSON boundary layer with a transparent
# fill and black border whenever it is loaded into QGIS.
from qgis.core import QgsProject, QgsFillSymbol
def apply_transparent_border_style(layer):
symbol = QgsFillSymbol.createSimple({
'color': '255,255,255,0',
'outline_color': '0,0,0,255',
'outline_width': '1.0'
})
layer.renderer().setSymbol(symbol)
layer.triggerRepaint()
def on_layer_added(layer):
if layer.source().lower().endswith('.geojson'):
apply_transparent_border_style(layer)
def run():
QgsProject.instance().layersAdded.connect(
lambda layers: [on_layer_added(l) for l in layers]
)
You never need to edit these files. Just drop them in the folder and register them in startup_script.py.
Adding a new script
Each time you download a new startup script:
- Copy the
.pyfile into yourStartup_scripts/folder - Open
startup_script.pyand add the two import lines insidedelayed_start - Restart QGIS
That’s the full process — no other configuration needed.