AstronomyPicture#

class nasa.AstronomyPicture[source]#

Bases: object

Represents an apod image object returned by the NASA Api.

New in version 0.0.1.

copyright#

The copyright of the linked file.

Type:

Optional[str]

date#

The date back when the file was the astronomy picture of the day.

Type:

datetime.datetime

explanation#

A short description about the file.

Type:

str

hdurl#

The high quality url to the file.

Type:

Optional[str]

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]

service_version#

The version of the api.

Type:

str

title#

The title of the file.

Type:

str

url#

The url to the file.

Type:

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 NasaSyncClient you’ll get a SyncAsset viceversa with a NasaAsyncClient you’ll get an AsyncAsset.

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_asset can be None if the bytes of the asset aren’t cached yet. You must handle that case yourself as shown above.

Type:

Union[SyncAsset, AsyncAsset]

property is_video: bool#

Whether the url lead to a video or not.

Type:

bool

property is_image: bool#

Whether the url lead to an image or not.

Type:

bool