Pyshp (The Python Shapefile Library) is a pure Python library designed for reading and writing ESRI Shapefile format files. It allows developers to work with geospatial vector data without external dependencies. The library is currently in version 3.0.3 and maintains an active development and release cadence.
pip install pyshpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple shapefile, write point geometries and their attributes, then read them back. It also shows how to create a polygon shapefile with multiple parts (including a hole), setting the shape type and adding fields and records. Using context managers ensures files are properly closed.
Upgrade your Python environment to 3.9+ or use pyshp versions < 3.0.0.
Consult the official documentation for updated API usage, particularly when accessing field metadata or bounding box information, and ensure your code adapts to the new object types. Refactor any code that relied on `Writer` mutating `Shapes`.
Instead of `w.records.extend(r.records())`, iterate through `r.iterShapeRecords()` and add shapes and records individually: `for shaperec in r.iterShapeRecords(): w.record(*shaperec.record); w.shape(shaperec.shape)`.
If encountering unexpectedly empty records, check the source shapefile's DBF structure for invalid deleted flags. Consider re-exporting the shapefile from a more compliant GIS application or manually sanitizing the DBF if possible. You might need to filter null geometries manually if the shapefile contains them.
If you require static type checking for pyshp, install the optional `pyshp-stubs` package via `pip install 'pyshp[stubs]'`.