NasaAsyncClient#

class nasa.NasaAsyncClient[source]#

Bases: _BaseClient

An 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 HTTPClient closure.

See also

To manually close the session use close().

New in version 0.0.1.

Parameters:

token (Optional[str]) – The token that should be used to connect to the NASA Api.

async close()[source]#

Closes the HTTPClient session.

Caution

An HTTPClient session cannot be re-opened.

property http_client: AsyncHTTPClient#

The HTTPClient linked to the NasaAsyncClient object.

Type:

HTTPClient

async get_astronomy_picture(date: datetime.datetime | str | None = None) AstronomyPicture[source]#

Fetch an AstronomyPicture of a given date. If date is not provided returns the todays’ astronomy picture.

Parameters:

date (Optional[Union[datetime.datetime, str]]) – If not provided defaults to todays’ date.

Raises:

ValueError – The date doesn’t follows the YYYY-mm-dd date format.

Returns:

An astronomy picture.

Return type:

AstronomyPicture

async 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 list of AstronomyPicture.

Parameters:
  • start_date (Union[datetime.datetime, str]) – The start date. If provided as string it must follow the YYYY-mm-dd date format.

  • end_date (Optional[Union[datetime.datetime, str]]) – The end date. If provided as string it must follow the YYYY-mm-dd date format. If not provided defaults to todays’ date.

Returns:

A list of astronomy pictures for the required date range.

Return type:

List[AstronomyPicture]

async 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 generator of AstronomyPicture.

Parameters:
  • start_date (Union[datetime.datetime, str]) – The start date. If provided as string it must follow the YYYY-mm-dd date format.

  • end_date (Optional[Union[datetime.datetime, str]]) – The end date. If provided as string it must follow the YYYY-mm-dd date format. If not provided defaults to todays’ date.

Yields:

AstronomyPicture

async 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]