Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ write the modified message to a new GRIB file:
>>> pygrib.open('test.grb').readline()
1:Surface pressure:Pa (instant):regular_gg:surface:level 0:fcst time 240 hrs:from 201001011200

you can also open an in-memory binary stream instead of on-disk file
by creating an io.BufferedReader instance from the binary string:

>>> import requests, io
>>> fileurl = ("https://www.ncei.noaa.gov/data/"
... "ncep-global-data-assimilation/access/historical/"
... "201910/20191002/gdas.t00z.pgrb2.1p00.anl")
>>> response = requests.get(fileurl)
>>> buffer_io = io.BufferedReader(io.BytesIO(response.content))
>>> grbs = pygrib.open(buffer_io)
>>> grb = grbs.select(shortName='gh',level=500)[0]
>>> print(grb)
181:Geopotential height:gpm (instant):regular_ll:isobaricInhPa:level 50000 Pa:fcst time 0 hrs:from 201910020000
>>> grbs.close()

Module docstrings
-----------------

Expand Down
13 changes: 13 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ def test():
>>> str(grb.packingType)
'grid_simple'
>>> grbs.close()

read binary stream from memory instead of a disk file
>>> import requests, io
>>> fileurl = ("https://www.ncei.noaa.gov/data/"
... "ncep-global-data-assimilation/access/historical/"
... "201910/20191002/gdas.t00z.pgrb2.1p00.anl")
>>> response = requests.get(fileurl)
>>> buffer_io = io.BufferedReader(io.BytesIO(response.content))
>>> grbs = pygrib.open(buffer_io)
>>> grb = grbs.select(shortName='gh',level=500)[0]
>>> print(grb)
181:Geopotential height:gpm (instant):regular_ll:isobaricInhPa:level 50000 Pa:fcst time 0 hrs:from 201910020000
>>> grbs.close()
"""

if __name__ == "__main__":
Expand Down