{"library":"pyshp","title":"Pyshp: Pure Python ESRI Shapefile Reader/Writer","description":"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.","language":"python","status":"active","last_verified":"Wed May 20","install":{"commands":["pip install pyshp"],"cli":null},"imports":["import shapefile\nreader = shapefile.Reader('my_shapefile.shp')","import shapefile\nwriter = shapefile.Writer('new_shapefile.shp')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import shapefile\nimport os\n\n# Create a dummy shapefile for reading example\noutput_dir = 'temp_shapefile_dir'\nos.makedirs(output_dir, exist_ok=True)\n\nw = shapefile.Writer(os.path.join(output_dir, 'test_points.shp'))\nw.field('name', 'C')\nw.point(1, 1)\nw.record('Point A')\nw.point(2, 2)\nw.record('Point B')\nw.close()\n\n# Reading a shapefile\n# You specify the base filename of the shapefile or any of its component files.\n# Using a context manager is recommended for automatic file closing.\nwith shapefile.Reader(os.path.join(output_dir, 'test_points.shp')) as sf:\n    print(f\"Shape type: {sf.shapeTypeName}\")\n    print(f\"Number of shapes: {len(sf.shapes())}\")\n    for shapeRec in sf.iterShapeRecords():\n        print(f\"Geometry: {shapeRec.shape.points}, Record: {shapeRec.record}\")\n\n# Writing a new shapefile\nwith shapefile.Writer(os.path.join(output_dir, 'new_polygon.shp')) as w:\n    w.shapeType = shapefile.POLYGON\n    w.field(\"Name\", \"C\")\n    w.field(\"Area\", \"N\")\n    \n    # Add a polygon\n    w.poly([[[0,0],[0,10],[10,10],[10,0],[0,0]]])\n    w.record(\"Square\", 100)\n\n    # Add another polygon with a hole\n    w.poly([\n        [[20,20],[20,30],[30,30],[30,20],[20,20]], # Outer ring\n        [[22,22],[22,28],[28,28],[28,22],[22,22]]  # Inner ring (hole)\n    ])\n    w.record(\"Donut\", 56)\n\nprint(f\"Shapefile '{os.path.join(output_dir, 'new_polygon.shp')}' created successfully.\")\n\n# Clean up (optional)\n# for ext in ['.shp', '.shx', '.dbf', '.prj']: # .prj might not be created by default\n#     if os.path.exists(os.path.join(output_dir, 'new_polygon' + ext)):\n#         os.remove(os.path.join(output_dir, 'new_polygon' + ext))\n#     if os.path.exists(os.path.join(output_dir, 'test_points' + ext)):\n#         os.remove(os.path.join(output_dir, 'test_points' + ext))\n# os.rmdir(output_dir)","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-20","installed_version":"3.0.7","pypi_latest":"3.0.7","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.6,"avg_import_s":0.36,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.29,"mem_mb":7.2,"disk_size":"18.1M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.33,"mem_mb":7.2,"disk_size":"18.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.2,"mem_mb":7.2,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.24,"mem_mb":7.2,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.41,"mem_mb":8.5,"disk_size":"20.0M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.47,"mem_mb":8.5,"disk_size":"20.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.35,"mem_mb":8.5,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":8.5,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.39,"mem_mb":8.3,"disk_size":"11.8M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.45,"mem_mb":8.3,"disk_size":"11.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.37,"mem_mb":8.3,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.47,"mem_mb":8.3,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.41,"mem_mb":8.5,"disk_size":"11.6M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":8.5,"disk_size":"11.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.38,"mem_mb":8.5,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.49,"mem_mb":8.5,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.28,"mem_mb":6.8,"disk_size":"17.6M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.31,"mem_mb":6.8,"disk_size":"17.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.21,"mem_mb":6.8,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyshp","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.27,"mem_mb":6.8,"disk_size":"18M"}]}}