Skip to main content

gribkit

CI Release PyPI Python versions License: MIT OpenSSF Scorecard Renovate uv Ruff Checked with mypy

A small, typed Python library for GRIB2 partial downloads. Instead of fetching a whole 500 MB forecast file, read its inventory, pick the messages you need, download only their byte ranges and crop them to your region.

  • Read NCEP .idx inventories (parse_idx) as published next to GFS, GEFS and other NCEP products, including sub-messages (12.1, 12.2) that share a byte range.
  • Select messages by VAR:LEVEL with an optional regular expression on the forecast field (MessageSpec, select, missing_specs).
  • Merge byte ranges into as few HTTP requests as possible, optionally bridging small gaps (merge_ranges, ByteRange.extract).
  • Parse GRIB2 message headers without ecCodes (parse_head, find_boundary) and generate .idx lines in the style of wgrib2 -s, so you can build an inventory for archives that do not publish one.
  • Split and validate a byte stream into complete GRIB2 messages (iter_messages).
  • Crop regular_ll messages to a bounding box with ecCodes (crop, crop_message, BBox), also across the prime meridian, keeping the packing type and precision of the source.

Installation

pip install gribkit
# or
uv add gribkit

gribkit supports Python 3.12 to 3.15. It depends on eccodes, eccodeslib and numpy. On Python 3.15, eccodeslib 2.50.0.34 or newer is needed, the first release with cp315 wheels.

Only crop, crop_message and describe use ecCodes. Reading .idx files, merging ranges and parsing headers is pure Python.

Example: a GFS partial download from AWS

Download 2 m temperature and 10 m wind from a GFS 0.25° forecast on the NOAA GFS Open Data bucket and crop it to Central Europe:

import urllib.request

from gribkit import BBox, MessageSpec, crop, merge_ranges, parse_idx, select

url = (
    "https://noaa-gfs-bdp-pds.s3.amazonaws.com/"
    "gfs.20261101/00/atmos/gfs.t00z.pgrb2.0p25.f006"
)

with urllib.request.urlopen(url + ".idx") as resp:
    entries = parse_idx(resp.read().decode())

specs = [
    MessageSpec("TMP", "2 m above ground"),
    MessageSpec("UGRD", "10 m above ground"),
    MessageSpec("VGRD", "10 m above ground"),
]
wanted = select(entries, specs)

data = b""
for rng in merge_ranges(wanted, max_gap=64 * 1024):
    req = urllib.request.Request(url, headers={"Range": rng.header})
    with urllib.request.urlopen(req) as resp:
        if resp.status != 206:
            raise RuntimeError(f"expected 206 Partial Content, got {resp.status}")
        data += rng.extract(resp.read())  # checks the length, drops bridged gaps

europe = crop(data, BBox(north=56.0, south=46.0, west=5.0, east=16.0))

One request per range

The S3 endpoints of AWS and Google Cloud answer multi-range requests (Range: bytes=a-b,c-d) with the whole file and status 200. Request each ByteRange from merge_ranges separately, and check for 206 Partial Content and the expected length (ByteRange.extract raises ValueError on a length mismatch). Use max_gap to trade a few wasted bytes for fewer requests.

The length of the last message in an .idx file is unknown unless you pass the file size (parse_idx(text, total_size=...)); without it, its range is open-ended (bytes=<offset>-).

Development

gribkit uses uv, Ruff, mypy (strict) and pytest.

uv sync
uv run pytest
uv run pre-commit install          # once, sets up the Git hook
uv run pre-commit run --all-files

See CONTRIBUTING.md for commit conventions and the release process.

Releases

Every commit on main is released: the version is calculated from the Conventional Commit message (feat: bumps the minor version, ! the major version, everything else the patch version), tagged, published as a GitHub Release and uploaded to PyPI with Trusted Publishing. The release notes live on GitHub, see CHANGELOG.md.

Origin

gribkit was written as part of PredictionDB, where it loads GFS and GEFS forecasts, and moved to this repository with its Git history to be useful on its own.

License

gribkit is licensed under the MIT License.

The NCEP parameter table src/gribkit/ncep_parameters.json (GRIB2 Code Table 4.2 with wgrib2-style short names) is derived from grib2io 2.8.2, Copyright (c) 2021 NOAA / National Weather Service, MIT License. See NOTICE.

Metadata

Release files for gribkit 0.3.0

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

Source distribution (sdist)

Source distribution for gribkit 0.3.0
File Size Uploaded Provenance Actions
gribkit-0.3.0.tar.gz 57.4 kB With provenance Details for gribkit-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 83.1 kB

Release files / gribkit-0.3.0.tar.gz

Download URL gribkit-0.3.0.tar.gz
Size 57.4 kB
Tags Source
SHA-256 checksum
How to use checksums
677a9c5796131c413cc7957f8988fe053083c9b6dfbadb404821ce41e74b4d7f
BLAKE2b-256 checksum
How to use checksums
e433a1901b2add27e79ad757cc6d8c17883f68eb0cb2826e04718eceea577880
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / gribkit-0.3.0-py3-none-any.whl

Download URL gribkit-0.3.0-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4b918205bad06181c11d586f90e61c9a1ffcec223643f351acd98c0b0155d0d
BLAKE2b-256 checksum
How to use checksums
c0c4ce1a371ded546262487b45ad1ff9ad968465981911ebafeb382461ad5981
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for gribkit 0.3.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gribkit-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

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