{"id":6773,"library":"plpygis","title":"plpygis: Python tools for PostGIS","description":"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.","status":"active","version":"0.6.1","language":"en","source_language":"en","source_url":"https://github.com/bosth/plpygis","tags":["geospatial","postgis","geometry","wkt","wkb","gis","ewkt","ewkb"],"install":[{"cmd":"pip install plpygis","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Geometry","correct":"from plpygis.geometry import Geometry"},{"symbol":"Point","correct":"from plpygis.geometry import Point"},{"symbol":"LineString","correct":"from plpygis.geometry import LineString"},{"symbol":"Polygon","correct":"from plpygis.geometry import Polygon"},{"note":"WKT parsing functions are located in the `plpygis.wkt` submodule.","wrong":"from plpygis import from_wkt","symbol":"from_wkt","correct":"from plpygis.wkt import from_wkt"},{"note":"WKB parsing functions are located in the `plpygis.wkb` submodule.","wrong":"from plpygis import from_wkb","symbol":"from_wkb","correct":"from plpygis.wkb import from_wkb"}],"quickstart":{"code":"from plpygis import Point, LineString\nfrom plpygis.wkt import from_wkt\n\n# Create a Point geometry with an SRID\npoint = Point(10, 20, srid=4326)\nprint(f\"Point WKT: {point.wkt}\")\nprint(f\"Point EWKT: {point.ewkt}\")\nprint(f\"Point WKB (hex): {point.wkb.hex()}\")\n\n# Create a LineString from EWKT, specifying SRID during parsing\nline_ewkt = \"SRID=4326;LINESTRING (30 10, 40 20)\"\nline = from_wkt(line_ewkt, srid=4326) # srid is optional if present in EWKT, but good practice\nprint(f\"LineString GeoJSON: {line.geojson}\")\nprint(f\"LineString length: {len(line)}\")\n\n# Access properties\nprint(f\"First coordinate of line: {line.geometries[0]}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Ensure your project or environment uses Python 3.9 or newer. Upgrade your Python interpreter if necessary.","message":"The minimum required Python version has been increased to 3.9.","severity":"breaking","affected_versions":">=0.6.0"},{"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.","message":"For closer adherence to the `__geo_interface__` convention, geometries now represent coordinates and coordinate sequences as tuples instead of lists.","severity":"breaking","affected_versions":">=0.6.0"},{"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.","message":"When generating WKTs, coordinates default to 6 decimal places of precision. This might lead to unexpected rounding for high-precision data.","severity":"gotcha","affected_versions":">=0.5.5"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=0.5.5"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}