Skip to main content

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

Note: All QGIS imports are lazy — import qgis_project works without QGIS installed. Errors only surface when a QGIS-backed method is actually called.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qgis_project-0.0.2.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qgis_project-0.0.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file qgis_project-0.0.2.tar.gz.

File metadata

  • Download URL: qgis_project-0.0.2.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qgis_project-0.0.2.tar.gz
Algorithm Hash digest
SHA256 be3ee14aeac461acedff061333ea933e73c75dfbf6148c2921e4b0db4e1c1c6a
MD5 00d0cce469f82f0c8f6044d5322661ac
BLAKE2b-256 c1c032ee1931672ccf1195f0ffb0ae071f6b44c35b196d0be19b32eeb7ae90f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for qgis_project-0.0.2.tar.gz:

Publisher: publish.yml on ColinMoldenhauer/qgis-project

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qgis_project-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: qgis_project-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qgis_project-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b19ad14ccf973984457267538e5a9fcf589288cb2507fc62d072112124557247
MD5 b745fd17586d81fbb7966a14e1fb63e0
BLAKE2b-256 022264745363768590b03df0d36b03c08b8fbe60df7a31432c5925f8e4d59c48

See more details on using hashes here.

Provenance

The following attestation bundles were made for qgis_project-0.0.2-py3-none-any.whl:

Publisher: publish.yml on ColinMoldenhauer/qgis-project

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page