Assets#

SyncAsset#

class nasa.SyncAsset[source]#

Bases: _BaseAsset

Represents an asset returned by the NASA Api as a python object.

Supported Operations

x == y

Checks if two Assets holds the same file.

x != y

Checks if two Assets don’t holds the same file.

New in version 0.0.1.

read() bytes[source]#

Fetch the file and return its bytes.

Note

This function doesn’t use the token. As a result requests made with this method won’t reduce your request counter.

Returns:

The bytes of the file.

Return type:

bytes

property bytes_asset: bytes#

The bytes of the asset if already cached otherwise None.

Hint

This property can be None if the Asset wasn’t previously fetched. You should check if bytes_asset is None and then fetch it. Check the example at AstronomyPicture.image.

Type:

Union[bytes, None]

save(file: str | bytes | os.PathLike[str], *, seek_at_end: bool = True) str[source]#
save(file: BufferedIOBase, *, seek_at_end: bool = True) int

Saves the Asset locally. If file is io.BufferedIOBase returns the numbers of bytes writed otherwise the name of the file or the path where it was saved.

Parameters:
Returns:

If file is io.BufferedIOBase the number of bytes written; otherwise the name of the file or the path where it was saved.

Return type:

Union[int, str]

AsyncAsset#

class nasa.AsyncAsset[source]#

Bases: _BaseAsset

Represents an asset returned by the NASA Api as a python object.

Supported Operations

x == y

Checks if two Assets holds the same file.

x != y

Checks if two Assets don’t holds the same file.

New in version 0.0.1.

async read() bytes[source]#

Fetch the file and return its bytes.

Note

This function doesn’t use the token. As a result requests made with this method won’t reduce your request counter.

Returns:

The bytes of the file.

Return type:

bytes

property bytes_asset: bytes | None#

the bytes of the asset if already cached otherwise None.

Hint

This property can be None if the Asset wasn’t previously fetched. You should check if bytes_asset is None and then fetch it. Check the example at AstronomyPicture.image.

Type:

Union[bytes, None]

async save(file: BufferedIOBase, *, seek_at_end: bool = True) int[source]#
async save(file: str | bytes | os.PathLike[str], *, seek_at_end: bool = True) Union[str, bytes, PathLike[str], PathLike[bytes]]

Saves the Asset locally. If file is io.BufferedIOBase returns the numbers of bytes writed otherwise the name of the file or the path where it was saved.

Parameters:
Returns:

If file is io.BufferedIOBase the number of bytes written; otherwise the name of the file or the path where it was saved.

Return type:

Union[int, str, bytes, os.PathLike]