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.1.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.1.0
File Size Uploaded Provenance Actions
h2gis-2.1.0.tar.gz 55.0 kB With provenance Details for h2gis-2.1.0.tar.gz

Built distributions (wheels)

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

Total release size: 69.0 MB

Release files / h2gis-2.1.0.tar.gz

Download URL h2gis-2.1.0.tar.gz
Size 55.0 kB
Tags Source
SHA-256 checksum
How to use checksums
66e8be22f7802f3993f25de84a4f8cc55ce0ddcb6a56819e2b6dcb1747746bd3
BLAKE2b-256 checksum
How to use checksums
ed1e8c8f6c51a9c014bffedf6bfc44e8a4057d4cd475ed2baa954762abe0b67f
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 11, 2026.

Transparency log

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

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

Transparency log

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

Download URL h2gis-2.1.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
4a9ed567430955e93750be869c0d9a96d4091f13264bb91edda1ca2bfb541d3a
BLAKE2b-256 checksum
How to use checksums
14817985b6b8d55d169d68f83909b664870f9b6b2fe7ffbdee44bf17f22926e4
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 11, 2026.

Transparency log

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

Download URL h2gis-2.1.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
02b56060ab2e8c437809916f6acb65c0b4d79524edd06e8bf229715624d91711
BLAKE2b-256 checksum
How to use checksums
879ea8ca87cdd9077d8f4107f588f4c5c84d4217e9c278aee4c5479fe49a0485
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 11, 2026.

Transparency log

Security for h2gis 2.1.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.1.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 11, 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