Create QGIS projects programmatically using Python
Project description
qgis-project
Create QGIS projects programmatically using Python.
from qgis_project import Project, RasterLayer, RasterStyleBW
proj = Project()
proj.add_layer("dem.tif") # raster, auto-detected
proj.add_layer("boundaries.geojson") # vector, auto-detected
proj.add_layer(RasterLayer("dem.tif", style=RasterStyleBW(vmin=0, vmax=3000)))
proj.save("output.qgz")
proj.open() # launch QGIS for visual inspection
Installation
Install the package:
pip install qgis-project
QGIS is not on PyPI and must be available separately. The recommended approach is a dedicated conda environment:
conda env create -f environment_platform_independent.yml
conda activate qgis-env-pi
pip install qgis-project
Or install QGIS from conda-forge into an existing environment:
conda install -c conda-forge qgis
pip install qgis-project
Usage
Basic project
from qgis_project import Project
proj = Project()
proj.add_layer("dem.tif")
proj.add_layer("roads.geojson")
proj.save("my_project.qgz")
proj.exit()
Layer groups
proj.add_layer(RasterLayer("dem.tif", group="terrain"))
proj.add_layer(RasterLayer("slope.tif", group=["terrain", "derived"]))
Raster styling
from qgis_project import RasterLayer, RasterStyleBW
layer = RasterLayer(
file="dem.tif",
name="Elevation",
group="terrain",
style=RasterStyleBW(vmin=0, vmax=3000),
)
proj.add_layer(layer)
Open in QGIS
proj.open("output.qgz") # saves and launches QGIS
proj.print_layer_tree() # inspect the layer tree in the terminal
Development
Install with dev dependencies:
pip install -e ".[dev]"
Run unit tests (no QGIS required):
pytest -m "not qgis"
Run integration tests (QGIS environment required):
pytest -m qgis
Run the manual visual test:
python scripts/manual_test.py
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 qgis_project-0.3.2.tar.gz.
File metadata
- Download URL: qgis_project-0.3.2.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d93e13af367eef9d88785adab487b8fdd4cd29f9fe58ee77e61ed7a61460792
|
|
| MD5 |
ede29b1bec81208ef0e4f66708f0e4b6
|
|
| BLAKE2b-256 |
d7aa0c19463a86c2b54df10c10272232c826d63ed81e165f19cbdac11cee180c
|
Provenance
The following attestation bundles were made for qgis_project-0.3.2.tar.gz:
Publisher:
publish.yml on ColinMoldenhauer/qgis-project
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qgis_project-0.3.2.tar.gz -
Subject digest:
5d93e13af367eef9d88785adab487b8fdd4cd29f9fe58ee77e61ed7a61460792 - Sigstore transparency entry: 1708390866
- Sigstore integration time:
-
Permalink:
ColinMoldenhauer/qgis-project@b99319442efb0a110e704c9c1b3836e667b608dc -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/ColinMoldenhauer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b99319442efb0a110e704c9c1b3836e667b608dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file qgis_project-0.3.2-py3-none-any.whl.
File metadata
- Download URL: qgis_project-0.3.2-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3237843f5c809bd22a6734f13ddc54e95bbb8d3266ccab5c3d3f2d839e1844b
|
|
| MD5 |
8b551aff4f8393bacd19e91857eca7b8
|
|
| BLAKE2b-256 |
63e1c174a36a0f2bd70c53b96d57dc8303f1c4a26c0e8c73608a6fa04969e61e
|
Provenance
The following attestation bundles were made for qgis_project-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on ColinMoldenhauer/qgis-project
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qgis_project-0.3.2-py3-none-any.whl -
Subject digest:
a3237843f5c809bd22a6734f13ddc54e95bbb8d3266ccab5c3d3f2d839e1844b - Sigstore transparency entry: 1708391116
- Sigstore integration time:
-
Permalink:
ColinMoldenhauer/qgis-project@b99319442efb0a110e704c9c1b3836e667b608dc -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/ColinMoldenhauer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b99319442efb0a110e704c9c1b3836e667b608dc -
Trigger Event:
push
-
Statement type: