AstronomyPicture#
- class nasa.AstronomyPicture[source]#
Bases:
objectRepresents an apod image object returned by the NASA Api.
New in version 0.0.1.
- date#
The date back when the file was the astronomy picture of the day.
- Type:
- media_type#
The type of media of the file. This can be either
"image"or"video".Todo
Transform this attribute in an enum member or flag.
- Type:
Optional[
str]
- image#
The file represented as a python object. This is useful if you’re trying to fetch the bytes of the file or to save the file.
Note
The type of asset depends on what type of client you’re using. With a
NasaSyncClientyou’ll get aSyncAssetviceversa with aNasaAsyncClientyou’ll get anAsyncAsset.Example
client = NasaAsyncClient(token="...") image: AstronomyPicture = await client.get_astronomy_picture() # this will save the image with the "title" as # its name await image.save(image.title)
Example
apod_obj: AstronomyPicture = await client.get_astronomy_picture() # if "bytes_asset" is None then our bytes aren't cached so we fetch the file # this example assumes that you're using the NasaAsyncClient image_bytes = apod_obj.bytes_asset or await apod_obj.image.read()
Caution
AsyncAsset.bytes_assetcan beNoneif the bytes of the asset aren’t cached yet. You must handle that case yourself as shown above.- Type:
Union[
SyncAsset,AsyncAsset]