Skip to main content

H2GIS Python

A DB-API 2.0 driver for the H2GIS spatial database, with an API aligned on psycopg 3. H2GIS runs embedded in your Python process through a native library compiled with GraalVM (no JVM, no server).

import h2gis
from h2gis.rows import dict_row

with h2gis.connect("/data/my_db", row_factory=dict_row) as conn:
    conn.execute("CREATE TABLE IF NOT EXISTS PLACE_NAMES(ID SERIAL, NOM VARCHAR, "
                 "THE_GEOM GEOMETRY(POINT, 4326))")
    conn.execute("INSERT INTO PLACE_NAMES VALUES (%s, %s, ST_SetSRID(ST_MakePoint(%s, %s), 4326))",
                 [1, "Nantes", -1.55, 47.22])
    for row in conn.execute("SELECT * FROM PLACE_NAMES WHERE NOM = %s", ["Nantes"]):
        print(row["ID"], row["THE_GEOM"])          # a Shapely geometry

    # GeoPandas, CRS taken from the SRID
    gdf = h2gis.read_gdf(conn, "SELECT * FROM PLACE_NAMES")
    h2gis.to_h2gis(gdf, "PLACE_NAMES_COPY", conn, if_exists="replace")

    with conn.transaction():                         # nested blocks = savepoints
        conn.execute("DELETE FROM PLACE_NAMES WHERE ID = %s", [1])
        raise h2gis.Rollback                          # undo this block only
# committed on success, rolled back on error, then closed

Documentation

Installation

pip install h2gis               # driver + Shapely
pip install "h2gis[geopandas]"  # + pandas and GeoPandas
conda install -c orbisgis -c conda-forge h2gis   # with conda

Requirements: Python 3.9+ on Linux x86-64 (glibc 2.34+), Windows x86-64 or macOS on Apple silicon. Each platform wheel ships the native H2GIS library (C API 2, H2GIS 2.2.6+); set H2GIS_LIB_PATH or pass lib_path= to connect() to use another one.

Tests

pip install -e ".[test]"
pytest test/

From a clone, h2gis uses the native library of native/, downloaded once from a release of H2GIS: python tools/update_native.py --download --current-platform. test/test_unit.py needs no native library; test/test_integration.py runs against the libraries listed in H2GIS_TEST_LIBS, or the default one, and is skipped when none is found. Building the wheels and releasing: see DEPLOY.md.

Demo script

import sys
import time

import matplotlib.pyplot as plt

import h2gis

DATA = "../uhi_lcz/Angers"
db_path = sys.argv[1] if len(sys.argv) > 1 else "/tmp/gisdb"
data_dir = sys.argv[2] if len(sys.argv) > 2 else DATA

# Open (or create) the database; committed and closed at the end of the block
with h2gis.connect(db_path) as conn:
    # Import the GeoJSON files (true: replace the tables if they exist)
    conn.execute("CALL GeoJsonRead(%s, 'BUILDING', true)", [f"{data_dir}/building.geojson"])
    conn.execute("CALL GeoJsonRead(%s, 'ROAD', true)", [f"{data_dir}/road.geojson"])
    print("Data loaded")

    start_time = time.time()

    # Tables straight to GeoDataFrames (GeoClimate data is in Lambert 93)
    gdf_building = h2gis.read_gdf(conn, "SELECT THE_GEOM, HEIGHT_WALL FROM BUILDING",
                                  crs="EPSG:2154")
    gdf_road = h2gis.read_gdf(conn, "SELECT THE_GEOM FROM ROAD WHERE WIDTH >= %s", [10],
                              crs="EPSG:2154")
    print("Dataframes created")

# Plot
bins = [0, 5, 10, 20, 50, 100, 200]
fig, ax = plt.subplots(1, 1)
gdf_building.plot(column="HEIGHT_WALL", legend=True, ax=ax, scheme="UserDefined",
                  classification_kwds={"bins": bins})
gdf_road.plot(ax=ax, color="black")
ax.set_title("Building height (m) from GeoClimate")

elapsed_time = time.time() - start_time
print(f"Time : {elapsed_time:.2f} seconds")

plt.show()

License

LGPL 3.0. H2GIS-python is developed by the GEODATICS team, Lab-STICC - CNRS.

Metadata

Release files for h2gis 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h2gis 2.2.0
File Size Uploaded Provenance Actions
h2gis-2.2.0.tar.gz 55.1 kB With provenance Details for h2gis-2.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for h2gis 2.2.0
File Interpreter ABI Platform Actions
h2gis-2.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for h2gis-2.2.0-py3-none-win_amd64.whl
h2gis-2.2.0-py3-none-manylinux_2_34_x86_64.whl Python 3 none Linux glibc 2.34+ x86-64 Details for h2gis-2.2.0-py3-none-manylinux_2_34_x86_64.whl
h2gis-2.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for h2gis-2.2.0-py3-none-macosx_11_0_arm64.whl

Total release size: 69.0 MB

Release files / h2gis-2.2.0.tar.gz

Download URL h2gis-2.2.0.tar.gz
Size 55.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3ec76b56768014a4c3b9972d45a1134487248d0e812e74b30b646f6e5fbe8fca
BLAKE2b-256 checksum
How to use checksums
4569b80d1e6dc7e7b1c8f6807093600842eeb90d50a1f963b114ccef97d1058e
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 20, 2026.

Transparency log

Release files / h2gis-2.2.0-py3-none-win_amd64.whl

Download URL h2gis-2.2.0-py3-none-win_amd64.whl
Size 22.9 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
cd5c5c29535e3b05237a44dd965f45344f6501ec3caaf31569fc66899510da37
BLAKE2b-256 checksum
How to use checksums
3a8fbf2ee2730617fb7fe18eaf873ef1eb8d37d9502ce2e1f9a3da02d6b826b0
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 20, 2026.

Transparency log

Release files / h2gis-2.2.0-py3-none-manylinux_2_34_x86_64.whl

Download URL h2gis-2.2.0-py3-none-manylinux_2_34_x86_64.whl
Size 23.8 MB
Tags Linux glibc 2.34+ x86-64 Python 3
SHA-256 checksum
How to use checksums
accce6247bcd21865984cc8bf701fc038cd05a3144573eb3f48916e7fe4ec4f3
BLAKE2b-256 checksum
How to use checksums
341ed679660b35162b741e6d595b85894fa269125d19a59dc49deb0f67f9f574
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 20, 2026.

Transparency log

Release files / h2gis-2.2.0-py3-none-macosx_11_0_arm64.whl

Download URL h2gis-2.2.0-py3-none-macosx_11_0_arm64.whl
Size 22.2 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9593151dbaa9dda6218f6da6575d79eabcb31820b46f322d7be2ae8343261f46
BLAKE2b-256 checksum
How to use checksums
0ae3bcdfc0d15a1773fe663e36a8cbaae8dfd1cab57f0647b9bffc491de2aaa5
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 20, 2026.

Transparency log

Security for h2gis 2.2.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

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for h2gis-2.2.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 20, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page