Registry / database / plpygis

plpygis

JSON →
library0.6.1pypypi✓ verified 84d ago

plpygis provides Python tools for working with PostGIS geometries, enabling easy conversion between common formats like WKT, EWKT, WKB, EWKB, and GeoJSON. It focuses on parsing and generating these formats directly in Python, making it suitable for applications interacting with PostGIS. The current version is 0.6.1, and the library maintains an active release cadence with minor updates and bug fixes.

pip install plpygis
INSTALL
IMPORT
SIG · PLPYGIS
P
plpygis
databasepythonv0.6.1
Install
1.6s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.011s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Geometry
from plpygis.geometry import Geometry
Point
from plpygis.geometry import Point
LineString
from plpygis.geometry import LineString
Polygon
from plpygis.geometry import Polygon
from_wkt
from plpygis.wkt import from_wkt
from plpygis import from_wkt
WKT parsing functions are located in the `plpygis.wkt` submodule.
from_wkb
from plpygis.wkb import from_wkb
from plpygis import from_wkb
WKB parsing functions are located in the `plpygis.wkb` submodule.

This quickstart demonstrates creating Point and LineString geometries, converting them to WKT, EWKT, and GeoJSON, and parsing a geometry from an EWKT string using `from_wkt`. It also shows how to access basic geometry properties.

from plpygis import Point, LineString from plpygis.wkt import from_wkt # Create a Point geometry with an SRID point = Point(10, 20, srid=4326) print(f"Point WKT: {point.wkt}") print(f"Point EWKT: {point.ewkt}") print(f"Point WKB (hex): {point.wkb.hex()}") # Create a LineString from EWKT, specifying SRID during parsing line_ewkt = "SRID=4326;LINESTRING (30 10, 40 20)" line = from_wkt(line_ewkt, srid=4326) # srid is optional if present in EWKT, but good practice print(f"LineString GeoJSON: {line.geojson}") print(f"LineString length: {len(line)}") # Access properties print(f"First coordinate of line: {line.geometries[0]}")
Debug
Known issues
breakingThe `wkb` property (e.g., `Point().wkb`) now consistently returns a standard WKB (without SRID metadata). To get an EWKB (which includes SRID metadata), you must now use the `ewkb` property.
fix
Update existing code: change `geometry.wkb` to `geometry.ewkb` if you require SRID information embedded in the binary representation, or ensure your consuming system correctly handles standard WKB.
affects: >=0.5.0
breakingThe minimum required Python version has been increased to 3.9.
fix
Ensure your project or environment uses Python 3.9 or newer. Upgrade your Python interpreter if necessary.
affects: >=0.6.0
breakingFor closer adherence to the `__geo_interface__` convention, geometries now represent coordinates and coordinate sequences as tuples instead of lists.
fix
If your code directly manipulates the output of `__geo_interface__` and expects mutable lists, you will need to convert tuples to lists (e.g., `list(coords)`) or adapt your logic to work with immutable tuples.
affects: >=0.6.0
gotchaWhen generating WKTs, coordinates default to 6 decimal places of precision. This might lead to unexpected rounding for high-precision data.
fix
To configure the precision, set `plpygis.wkt.PRECISION` to your desired number of decimal places (e.g., `plpygis.wkt.PRECISION = 10`) or `None` for full precision before generating WKTs.
affects: >=0.5.5
gotchaWhen parsing LineString or Polygon geometries from WKT, `plpygis` now performs stricter checks to ensure the required number of coordinates are present, raising a `WktError` if not.
fix
Ensure that your WKT strings for LineString (at least 2 points) and Polygon (at least 3 points, first and last equal for rings) are valid. Handle `plpygis.exceptions.WktError` for malformed inputs.
affects: >=0.5.5
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'plpygis'
The `plpygis` library is not installed in the Python environment where the code is being executed, or the Python environment within PL/Python cannot find it.
fix
Install the library using pip: `pip install plpygis`. For PL/Python, ensure it's installed in the Python environment accessible by PostgreSQL.
plpygis.exceptions.DependencyError: Dependency 'Shapely' is not available.
The optional `Shapely` dependency, required for conversions to and from Shapely geometries, is either not installed or not accessible to `plpygis`, particularly when running within a PL/Python function.
fix
Install the Shapely library: `pip install shapely`. Also, ensure your `plpygis` version is compatible with your `shapely` version (e.g., `plpygis` 0.6.1 supports `shapely` 2.x).
plpygis.exceptions.WktError
The Well-Known Text (WKT) string provided to `plpygis` for parsing or conversion is malformed or does not adhere to WKT specifications.
fix
Review and correct the WKT string to ensure it is syntactically valid and represents a proper geometry. Example: `Geometry.from_wkt('POINT (10 20)')`
plpygis.exceptions.GeojsonError
The GeoJSON input (dictionary or string) provided to `plpygis` for parsing or conversion is malformed or does not conform to the GeoJSON specification.
fix
Ensure the GeoJSON input is a valid GeoJSON structure. Example: `Geometry.from_geojson({'type': 'Point', 'coordinates': [10.0, 20.0]})`
plpygis.exceptions.SridError
An error occurred related to the Spatial Reference Identifier (SRID) of a geometry, often due to inconsistent SRIDs within a multigeometry or invalid SRID assignment.
fix
Ensure that all component geometries within a collection have consistent SRIDs or no SRID if the collection is being assigned one. Verify SRID values are valid. Example: `Point((0, 0), srid=4326)`
Upgrade
Version history
0.6.1latest on PyPI · released Sep 30, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
plpygis — pip install plpygis · libregistry