Skip to main content

plpygis

plpygis is a pure Python module with no dependencies that can convert geometries between Well-known binary (WKB/EWKB), Well-known Text (WKT/EWKT) and GeoJSON representations. plpygis is mainly intended for use in PostgreSQL PL/Python functions to augment PostGIS's native capabilities.

Basic usage

plpygis implements several subclasses of the Geometry class, such as Point, LineString, MultiPolygon and so on:

>>> from plpygis import Point
>>> p = Point((-124.005, 49.005), srid=4326)
>>> print(p.ewkb)
0101000020e6100000b81e85eb51005fc0713d0ad7a3804840
>>> print(p.geojson)
{'type': 'Point', 'coordinates': [-124.005, 49.005]}
>>> p.z = 1
>>> print(p.wkt)
POINT Z (-124.005 49.005 1)

Usage with PostGIS

plpygis is designed to provide an easy way to implement PL/Python functions that accept geometry arguments or return geometry results. The following example will take a PostGIS geometry(Point) and use an external service to create a geometry(PointZ).

CREATE OR REPLACE FUNCTION add_elevation(geom geometry(POINT))
  RETURNS geometry(POINTZ)
AS $$
  from plpygis import Geometry
  from requests import get
  p = Geometry(geom)

  response = get(f'https://api.open-meteo.com/v1/elevation?longitude={p.x}&latitude={p.y}')
  if response.status_code == 200:
      content = response.json()
      p.z = content['elevation'][0]
      return p
  else:
      return None
$$ LANGUAGE plpython3u;

The Geometry() constructor will convert a PostGIS geometry that has been passed as a parameter to the PL/Python function into one of its plpygis subclasses. A Geometry that is returned from the PL/Python function will automatically be converted back to a PostGIS geometry.

The function above can be called as part of an SQL query:

SELECT
    name,
    add_elevation(geom)
FROM
    city;

Documentation

Full plpygis documentation is available at http://plpygis.readthedocs.io/.

Continuous Integration Documentation Status

Metadata

Release files for plpygis 0.6.1

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

Source distribution (sdist)

Source distribution for plpygis 0.6.1
File Size Uploaded Provenance Actions
plpygis-0.6.1.tar.gz 34.5 kB Without provenance Details for plpygis-0.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plpygis 0.6.1
File Interpreter ABI Platform Actions
plpygis-0.6.1-py3-none-any.whl Python 3 none any Details for plpygis-0.6.1-py3-none-any.whl

Total release size: 60.0 kB

Release files / plpygis-0.6.1.tar.gz

Download URL plpygis-0.6.1.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
30a119b3d5a60e285a7a66ee95b65a5efcc0d569b2d02d3183e736bbad7f748b
BLAKE2b-256 checksum
How to use checksums
15b058b5ee5caffff4fec4445443d5076012ec911f4e9e694172050adc5305d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / plpygis-0.6.1-py3-none-any.whl

Download URL plpygis-0.6.1-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79bccb916ab6768d15af505ec9d2a2f894735c5c8eef18ba7dc9fa46a697ec08
BLAKE2b-256 checksum
How to use checksums
54ff5135eb38650e5a39612d13734379c37d1caceb59404cc1461813c0406cdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for plpygis 0.6.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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