gribkit
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
.idxinventories (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:LEVELwith 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.idxlines in the style ofwgrib2 -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_llmessages 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.14. It depends on eccodes, eccodeslib and numpy.
Why not Python 3.15? The ecCodes Python bindings need the binary
eccodeslibwheel (otherwise they fail with "Cannot find the ecCodes library").eccodeslibandeckitlibare currently only published for CPython 3.11 to 3.14 (ecmwf/eccodes#629). gribkit will add 3.15 once those wheels exist.
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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gribkit-0.2.0.tar.gz | 57.5 kB | With provenance | Details for gribkit-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gribkit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for gribkit-0.2.0-py3-none-any.whl |
Total release size: 83.3 kB
Release files / gribkit-0.2.0.tar.gz
| Download URL | gribkit-0.2.0.tar.gz |
|---|---|
| Size | 57.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5605320f8fb7a711f43db024b84d27adc08f5b8e124189d6b33e0517812a997b
|
|
BLAKE2b-256 checksum How to use checksums |
44c826b98dbb5ca3676091e90357aa2e05b0db8fa82566f6c74e92d10819b7e0
|
| 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 1, 2026.
Transparency logRelease files / gribkit-0.2.0-py3-none-any.whl
| Download URL | gribkit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0854f5bb37bcebef5a209caea208d61f788c45a8e185b0085eb0ba4ffc609ff3
|
|
BLAKE2b-256 checksum How to use checksums |
dbecaad620ad6459b76d17e23298257f278c342a39da9e8d210444d4e36cbbfc
|
| 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 1, 2026.
Transparency logSecurity for gribkit 0.2.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.
Attestation for gribkit-0.2.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 1, 2026.
Transparency logA 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.