gpkglite

Read, write and validate OGC GeoPackage (.gpkg) files in pure Python without GDAL: features, attributes, RTree spatial index, GeoJSON/CSV conversion and a validator, standard library only.

Version 0.1.2 · Python >=3.9 · MIT licence
pip install gpkglite
PyPISourceIssuesChangelogCite (DOI)

gpkglite

PyPI version Python versions pipeline status License: MIT DOI Downloads

Read, write and validate OGC GeoPackage files in pure Python. No GDAL, no compiled dependencies, standard library only (sqlite3, struct, json).

GeoPackage (.gpkg) is the OGC standard container for vector data: an SQLite database with a few well-defined tables and a binary geometry encoding. Reading or writing one usually means installing GDAL (via fiona, pyogrio, geopandas or osgeo). That is heavy, or impossible, in:

gpkglite is a small, typed, dependency-free implementation of the parts of OGC 12-128r18 (GeoPackage 1.3.1) that vector workflows need. Files it writes open in GDAL/OGR, QGIS, geopandas/pyogrio and fiona, and it reads files written by them.

Installation

pip install gpkglite            # standard library only
pip install "gpkglite[geo]"     # + shapely / geopandas interop helpers

Quick start

import gpkglite

# write
with gpkglite.create("cities.gpkg") as gpkg:
    layer = gpkg.create_layer(
        "cities", "POINT", srs_id=4326,
        fields={"name": "TEXT", "population": "INTEGER", "capital": "BOOLEAN"},
    )
    layer.insert({"type": "Point", "coordinates": [28.97, 41.01]},
                 {"name": "Istanbul", "population": 15_600_000, "capital": False})
    layer.insert({"type": "Point", "coordinates": [32.85, 39.93]},
                 {"name": "Ankara", "population": 5_700_000, "capital": True})

# read
with gpkglite.open("cities.gpkg") as gpkg:
    for info in gpkg.layers():
        print(info.name, info.geometry_type, info.srs_id, info.bounds)

    cities = gpkg["cities"]
    print(cities.fields)            # {'name': 'TEXT', 'population': 'INTEGER', 'capital': 'BOOLEAN'}
    print(cities.crs.authority)     # 'EPSG:4326'
    for feature in cities.features(where="population > ?", params=[10_000_000]):
        print(feature["properties"]["name"], feature["geometry"]["coordinates"])

# check it
report = gpkglite.validate("cities.gpkg")
print(report)                      # cities.gpkg: valid GeoPackage 1.3.1 (0 errors, ...)

Features

Reading

Geometry encoding

Geometries are plain dictionaries. Positions have 2, 3 or 4 numbers; a measured geometry carries "dims": "XYM" (or "XYZM") so it can be told apart from XYZ:

{"type": "LineString", "coordinates": [[0, 0, 12.5], [10, 0, 13.0]]}             # XYZ
{"type": "Point", "coordinates": [1, 2, 0.75], "dims": "XYM"}                     # XYM

Any object with __geo_interface__ (shapely, geojson, ...) is accepted as input.

Writing

Validation

gpkglite.validate(path) returns a ValidationReport (report.ok, report.errors, report.warnings, report.as_dict()), with requirement numbers from the specification:

Conversion helpers

gpkglite.from_geojson("roads.geojson", "out.gpkg")                 # layer "roads"
gpkglite.from_csv("stations.csv", "out.gpkg", x="lon", y="lat")    # POINT layer
doc = gpkglite.to_geojson("out.gpkg", "roads", "roads.geojson")
text = gpkglite.to_csv("out.gpkg", "stations", geometry="xy")

# with the [geo] extra
gdf = gpkglite.to_geodataframe("out.gpkg", "roads")
gpkglite.from_geodataframe(gdf.to_crs(32635), "out.gpkg", "roads_utm")

from_geojson infers the schema and geometry type (mixing Polygon and MultiPolygon gives a MULTIPOLYGON layer) and honours the legacy crs member.

Command line

gpkglite info data.gpkg                 # layers, schema, CRS, extent, extensions (--json)
gpkglite dump data.gpkg --layer roads --format geojson
gpkglite dump data.gpkg -l roads -f csv --where "type = 'primary'" --bbox 29,41,29.1,41.1
gpkglite dump data.gpkg -l roads -f jsonl --limit 100 --offset 200 -o page3.jsonl
gpkglite validate data.gpkg             # exit status 1 when invalid (--json)
gpkglite from-geojson in.geojson -o out.gpkg [--layer name] [--srs-id 3857]
gpkglite from-csv points.csv -o out.gpkg -x lon -y lat

Interoperability

The test-suite cross-checks with GDAL:

Scope and limitations

Development

git clone https://gitlab.com/geophilo1/gpkglite_sdk.git
cd gpkglite_sdk
pip install -e ".[dev,geo]"
pytest --cov=gpkglite
ruff check . && ruff format --check src tests && mypy src

Set GPKGLITE_OGRINFO (path to ogrinfo) and GPKGLITE_VALIDATE_GPKG (command that runs GDAL's validate_gpkg.py) to enable the optional GDAL cross-validation tests.

A runnable examples/quickstart.py creates, queries and validates a small GeoPackage.

Related Geophilo SDKs

License

MIT, see LICENSE. Citation metadata is in CITATION.cff.

Academic citation

@software{eminoglu_gpkglite,
  author  = {Eminoğlu, Yusuf},
  title   = {gpkglite},
  year    = {2026},
  version = {0.1.2},
  doi     = {10.5281/zenodo.24063423},
  url     = {https://doi.org/10.5281/zenodo.24063423}
}

See also CITATION.cff.

Other Geophilo SDKs