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(asset_as: nasa.enums.FileTypes | None = None) 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.

Parameters:

asset_as (Optional[FileTypes]) – If given and the url is partial it will build a url with thay specific file extension. The returned file reflect the file extension where possible. If given and url isn’t partial then its ignored.

Raises:

ValueErrorasset_as was not a FileTypes member.

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.

await read(asset_as: nasa.enums.FileTypes | None = None) 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.

Parameters:

asset_as (Optional[FileTypes]) – If given and the url is partial it will build a url with thay specific file extension. The returned file reflect the file extension where possible. If given and url isn’t partial then its ignored.

Raises:

ValueErrorasset_as was not a FileTypes member.

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]

await save(file: BufferedIOBase, *, seek_at_end: bool = True) int[source]#
await 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]