{"library":"pygrib","title":"pygrib","description":"Pygrib is a Python module designed for reading and writing GRIB (General Regularly-distributed Information in Binary form) files, which is the World Meteorological Organization (WMO) standard format for weather data. It provides a high-level interface to the ECMWF ECCODES C library, supporting both GRIB edition 1 and edition 2. The library is currently at version 2.1.8 and sees active development with regular releases.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pygrib"],"cli":null},"imports":["import pygrib"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pygrib\nimport os\n\n# Create a dummy GRIB file for demonstration purposes\n# In a real scenario, you would have an actual GRIB file.\n# This example can't create a GRIB file from scratch due to pygrib's limitations,\n# so we simulate reading one.\n\n# For actual usage, replace 'sample.grib2' with your file path.\n# If you don't have one, consider downloading a small sample GRIB file from a meteorological data source.\n# Example: A minimalist GRIB file (not functional for this code but demonstrates intent)\n\n# For this example, assume 'sample.grib2' exists and contains at least one message.\n# Placeholder for a real GRIB file path\ngrib_file_path = os.environ.get('GRIB_SAMPLE_PATH', 'sample.grib2')\n\n# Create a dummy file if it doesn't exist for the example to run without FileNotFoundError\nif not os.path.exists(grib_file_path):\n    print(f\"Warning: '{grib_file_path}' not found. Cannot run quickstart without a GRIB file.\\n\" \\\n          \"Please set the GRIB_SAMPLE_PATH environment variable or create 'sample.grib2'.\")\n    # Optionally create a minimal (non-functional) placeholder to prevent immediate crash\n    with open(grib_file_path, 'wb') as f:\n        f.write(b'GRIB-DUMMY-FILE') # Not a valid GRIB file, but prevents FileNotFoundError\n\n\ntry:\n    grbs = pygrib.open(grib_file_path)\n\n    # Read the first message\n    # .read() returns a list of messages, so we take the first element.\n    grb = grbs.read(1)[0]\n\n    print(f\"GRIB Message 1: {grb}\")\n    print(f\"Short Name: {grb.shortName}\")\n    print(f\"Parameter Name: {grb.name}\")\n    print(f\"Units: {grb.units}\")\n    print(f\"Valid Date: {grb.validDate}\")\n\n    # Get data values (as a numpy array)\n    data = grb.values\n    print(f\"Data shape: {data.shape}\")\n    print(f\"Data min/max: {data.min()}/{data.max()}\")\n\n    # Get latitudes and longitudes\n    lats, lons = grb.latlons()\n    print(f\"Latitudes shape: {lats.shape}, Longitudes shape: {lons.shape}\")\n\n    grbs.close()\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    if 'not a GRIB file' in str(e):\n        print(\"This often means the GRIB_SAMPLE_PATH points to an invalid or empty file.\")\n    if os.path.exists(grib_file_path) and os.path.getsize(grib_file_path) < 100: # heuristic for dummy file\n        print(\"The quickstart created a dummy file; please provide a real GRIB file for full functionality.\")","lang":"python","description":"This quickstart demonstrates how to open a GRIB file, read a message, and extract key information such as data values, latitudes, and longitudes. Note that a valid GRIB file is required to run this example effectively. The example includes a placeholder for a GRIB file path and a warning if a dummy file is used.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"2.1.6","pypi_latest":"2.1.8","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":50,"avg_install_s":8.2,"avg_import_s":0.5,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pygrib","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pygrib","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":8.4,"import_time_s":0.37,"mem_mb":13.2,"disk_size":"251M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pygrib","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pygrib","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":8.1,"import_time_s":0.6,"mem_mb":14.4,"disk_size":"259M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pygrib","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pygrib","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":7.4,"import_time_s":0.55,"mem_mb":14.1,"disk_size":"247M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pygrib","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pygrib","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":7.4,"import_time_s":0.53,"mem_mb":14.3,"disk_size":"247M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pygrib","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pygrib","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":9.8,"import_time_s":0.45,"mem_mb":12.9,"disk_size":"261M"}]}}