pyfdb.pyfdb_type#

Attributes#

MarsSelection

Selection part of a MARS request.

MarsIdentifier

This is the representation of a MARS identifier

Classes#

UserInputMapper

Selection mapper for creating MARS selections.

DataHandle

DataHandle class for lazy reading from a data source.

ControlIdentifier

Specify which functionality of the FDB should be addressed, e.g. RETRIEVE or LIST.

ControlAction

Specify which action should be executed, e.g. DISABLE or ENABLE.

URI

Class describing a unique resource identifier.

Module Contents#

MarsSelection#

Selection part of a MARS request.

This is a key-value map, with the data types allowed below

MarsIdentifier#

This is the representation of a MARS identifier

This is a key-value List, mapping MARS keys to a string resembling a singluar value, see ecmwf/datacube-spec.

class UserInputMapper#

Selection mapper for creating MARS selections.

This class helps to create syntactically correctly structured MARS selections. If strict_mode is activated there will be checks whether keys have been set already.

classmethod map_selection_to_internal(selection: MarsSelection) pyfdb._internal.pyfdb_internal.InternalMarsSelection#
classmethod map_selection_to_external(selection: pyfdb._internal.pyfdb_internal.InternalMarsSelection) MarsSelection#
classmethod map_identifier_to_internal(identifier: MarsIdentifier) pyfdb._internal.pyfdb_internal.InternalMarsIdentifier#
class DataHandle(dataHandle: pyfdb._internal._DataHandle, *, _internal=False)#

DataHandle class for lazy reading from a data source.

Parameters:

None

Note

This class can’t be instantiated / is only returned from the underlying FDB calls

Return type:

DataHandle class

Examples

>>> request = {
>>>     "type": "an",
>>>     "class": "ea",
>>>     "domain": "g",
>>>     "expver": "0001",
>>>     "stream": "oper",
>>>     "date": "20200101",
>>>     "levtype": "sfc",
>>>     "step": "0",
>>>     "param": ["167", "165", "166"],
>>>     "time": "1800",
>>> }
>>> data_handle = fdb.retrieve(request)
>>> data_handle.open()
>>> data_handle.read(4) == b"GRIB"
>>> data_handle.close()
>>> # OR
>>> with fdb.retrieve(request) as data_handle:
>>>     data_handle.read(4) == b"GRIB"
dataHandle: pyfdb._internal._DataHandle#
opened = False#
__enter__() DataHandle#
__exit__(exc_type, exc_value, exc_traceback)#
open() None#

Open the DataHandle object for reading.

Parameters:

None

Return type:

None

Examples

>>> data_handle = fdb.retrieve(request)
>>> data_handle.open()
>>> data_handle.read(4) == b"GRIB"
>>> data_handle.close()
close() None#

Close the DataHandle object after reading.

Parameters:

None

Return type:

None

Examples

>>> data_handle = fdb.retrieve(request)
>>> data_handle.open()
>>> data_handle.read(4) == b"GRIB"
>>> data_handle.close()
size() int#

Return the size of a data handle in bytes.

Parameters:

None

Return type:

int describing the size of the datahandle in bytes.

Examples

>>> with fdb.retrieve(selection) as data_handle:
>>>     data_handle.size() # Returns the size of the datahandle in bytes
read(len: int = -1) bytes#

Read a given amount of bytes from the DataHandle. This method copies the data from the underlying memory.

Parameters:

len (int) – Number of bytes to read. Defaults to -1, which reads the entire buffer. If the requested size exceeds the available data, the result is zero-padded to match the requested size.

Return type:

bytes object resembling the read data.

Raises:

RuntimeError

Examples

>>> with fdb.retrieve(request) as data_handle
>>>     data_handle.read(4) == b"GRIB"
>>>     #or
>>>     data_handle.read(-1) # Read the entire file
readinto(buffer: memoryview) int#

Read a given amount of bytes from the DataHandle into a memoryview. This is a zero-copy method.

Parameters:

buffer (memoryview) – Memory view for the buffer in which the bytes should be read

Return type:

int size of bytes which have been read

Raises:

RuntimeError

Examples

>>> dst_read_into = io.BytesIO(b"")
>>> with fdb.retrieve(selection) as data_handle:
>>>     assert data_handle
>>>     shutil.copyfileobj(data_handle, dst_read_into)
>>>     # Reset position in file
>>>     dst_read_into.seek(0)
readall(buffer_size: int = 1024) bytes#

Read all bytes from the DataHandle into memory. This method copies the data from the underlying memory.

Parameters:

buffer_size (int) – The size of the buffer which is used for reading

Note

There is no need to open the DataHandle before. This is handled by the function. The default chunk size is 1024 bytes.

Return type:

bytes object resembling the read data

Examples

>>> data_handle = fdb.retrieve(request)
>>> data_handle.readall() # Returns all content of a datahandle b"GRIB..."
__repr__() str#
class ControlIdentifier#

Bases: enum.IntFlag

Specify which functionality of the FDB should be addressed, e.g. RETRIEVE or LIST.

Values#

  • NONE

  • LIST

  • RETRIEVE

  • ARCHIVE

  • WIPE

  • UNIQUEROOT

Initialize self. See help(type(self)) for accurate signature.

NONE = 0#
LIST#
RETRIEVE#
ARCHIVE#
WIPE#
UNIQUEROOT#
classmethod _from_raw(en: pyfdb._internal._ControlIdentifier)#
_to_raw()#
__repr__() str#

Return repr(self).

__str__() str#

Return str(self).

class ControlAction#

Bases: enum.IntEnum

Specify which action should be executed, e.g. DISABLE or ENABLE.

Values#

  • NONE

  • DISABLE

  • ENABLE

Initialize self. See help(type(self)) for accurate signature.

NONE = 0#
DISABLE#
ENABLE#
classmethod _from_raw(en: pyfdb._internal._ControlAction)#
_to_raw()#
__repr__() str#

Return repr(self).

__str__() str#

Return str(self).

class URI(uri: str | pathlib.Path, scheme: str = '', allow_fragments=True)#

Class describing a unique resource identifier.

Parameters:

None

Examples

>>> uri = URI("scheme://user:secretpass@example.com:8443/path/to/resource?query=search&sort=asc#section-2")
_uri: urllib.parse.SplitResult#
__eq__(value: object, /) bool#
__ne__(value: object, /) bool#
_to_internal()#
netloc() str#
scheme() str#
username() str | None#
password() str | None#
hostname() str | None#
port() int | None#
path() str#
query() str#
fragment() str#
__repr__() str#