NasaAsyncClient#
- class nasa.NasaAsyncClient[source]#
Bases:
_BaseClientAn asynchronous client to make request to the NASA Api.
Note
This class can also be used as context manager.
from nasa import NasaAsyncClient async def main(): async with NasaAsyncClient(token="token") as client: image = await client.get_astronomy_picture()
This will handle automatically the
HTTPClientclosure. For more information see NasaAsyncClientWarning
You need to manually close the session linked to the this client using
close().New in version 0.0.1.
- Parameters:
token (Optional[
str]) – The token that should be used to connect to the NASA Api.
- await close()[source]#
Closes the
HTTPClientsession.Caution
An
HTTPClientsession cannot be re-opened.
- property http_client: AsyncHTTPClient#
The
HTTPClientlinked to theNasaAsyncClientobject.- Type:
HTTPClient
- await get_astronomy_picture(date: datetime.datetime | str | None = None) AstronomyPicture[source]#
Fetch an
AstronomyPictureof a given date. Ifdateis not provided returns the todays’ astronomy picture.- Parameters:
date (Optional[Union[
datetime.datetime,str]]) – If not provided defaults to todays’ date.- Raises:
ValueError – The
datedoesn’t follows theYYYY-mm-dddate format.- Returns:
An astronomy picture.
- Return type:
- await get_range_astronomy_pictures(start_date: datetime.datetime | str, end_date: datetime.datetime | str | None = None) list[AstronomyPicture][source]#
Fetch multiple images with a given date range and return a
listofAstronomyPicture.- Parameters:
start_date (Union[
datetime.datetime,str]) – The start date. If provided as string it must follow theYYYY-mm-dddate format.end_date (Optional[Union[
datetime.datetime,str]]) – The end date. If provided as string it must follow theYYYY-mm-dddate format. If not provided defaults to todays’ date.
- Returns:
A list of astronomy pictures for the required date range.
- Return type:
List[
AstronomyPicture]
- async for ... in get_gen_astronomy_pictures(start_date: datetime.datetime | str, end_date: datetime.datetime | str | None = None) AsyncGenerator[AstronomyPicture, None][source]#
Fetch multiple images with a given date range and return an asynchronous
generatorofAstronomyPicture.- Parameters:
start_date (Union[
datetime.datetime,str]) – The start date. If provided as string it must follow theYYYY-mm-dddate format.end_date (Optional[Union[
datetime.datetime,str]]) – The end date. If provided as string it must follow theYYYY-mm-dddate format. If not provided defaults to todays’ date.
- Yields:
- await get_rand_astronomy_pictures(count: int = 1) list[AstronomyPicture][source]#
Fetch a random number of astronomy pictures.
- Parameters:
count (
int) – The number of random astronomy pictures to fetch. Must be between 1 and 100 (both inclusive).- Returns:
A list of random astronomy pictures.
- Return type:
List[
AstronomyPicture]
- await get_epic_natural_available_dates() AvailableDates[source]#
Get all the natural available dates.
You can use this to check if a request with a given date will return something or not.
Note
The dates are not converted to
datetime.datetimeobjects to save time and memory.See also
New in version 0.0.1.
- Return type:
AvailableDatesa dict containing all the natural available dates as single list.
- await get_epic_enhanced_available_dates() AvailableDates[source]#
Get all the enhanced available dates.
You can use this to check if a request with a given date will return something or not.
Note
The dates are not converted to
datetime.datetimeobjects to save time and memory.See also
New in version 0.0.1.
- Return type:
AvailableDatesa dict containing all the enhanced available dates as single list.
- await get_epic_images(date: datetime.datetime | None = None, *, image_type: EpicImageType = EpicImageType.natural, image_as: nasa.enums.FileTypes | None = None) list[EpicImage][source]#
Fetch earth images from the EPIC endpoint.
New in version 0.0.1.
- Parameters:
date (Optional[
datetime.datetime]) – If not provided fetchs the defaultEpicImages returned by the Nasa API.image_type (
EpicImageType) – Defaults toEpicImageType.natural.image_as (Optional[
FileTypes]) – The file extension of the image. This can be a png, a jpg or a thumbs.
- Raises:
ValueError – An invalid “image_type” was passed. This needs to be a
EpicImageTypemember.- Return type:
list[
EpicImage] Returns the requested epic images.