APOD
One of the open APIs provided by NASA. A good example of what this API can do is the Astronomy Picture of the Day website, wich gives you a new image/photograph of the universe every day. Also, each image has a brief explanation written by a professional astronomer, acording to the website. I know, this is amazing.
SyncApod
- class nasawrapper.apod.SyncApod(api_key: str)
This class uses synchronous programming syntax to make requests to the
APOD
API and returns the API response.Parameters
api_key (str) - The API key.
- property allowed_keys
Returns the allowed keys in a dict.
- property api_key
Returns the API key.
- property base_url
Returns the base URL.
Returns the allowed keys in a dict.
- get_apod(options: Dict[str, Union[str, int, bool, datetime.datetime]]) Union[nasawrapper.apod.ApodResponse, List[nasawrapper.apod.ApodResponse]]
Validate the provided options by checking their types and values. Here’s a list of the allowed keys and an example of how to call the method correctly:
Allowed Keys
Key
Type
Function
date
Search for a specific date. Can not be used with ‘start_date’.
start_date
The start of a date range.
end_date
The end of a date range. Can not be used without ‘start_date’ and can not be before Jun 16, 1995.
count
If specified, returns
count
randomly images. Can not be used with ‘date’, ‘start_date’ or ‘end_date’.thumbs
If the APOD is a video, return the URL of the video. Default is
False
.Examples
Getting asteroids from a range
from nasawrapper import SyncApod from datetime import datetime, timedelta apod = SyncApod("DEMO_KEY") result = apod.get_apod({ "start_date": datetime.now() - timedelta(days=1), "end_date": datetime.now(), "thumbs": True }) print(result)
Getting asteroids from specific date
from nasawrapper import SyncApod from datetime import datetime, timedelta apod = SyncApod("DEMO_KEY") result = apod.get_apod({ "date": datetime(year=2010, month=3, day=2) }) print(result)
- get_random() nasawrapper.apod.ApodResponse
Returns a random picture of APOD API. You can manually do this by typing:
from nasawrapper import SyncApod apod = SyncApod("DEMO_KEY") result = apod.get_apod({ "count": 1 }) print(result) # random picture
But it’s not recommended, since there’s a specific method for this.
- get_today_apod() nasawrapper.apod.ApodResponse
Returns today’s APOD. You can also clone this method manually by typing:
from nasawrapper import SyncApod from datetime import datetime apod = SyncApod("DEMO_KEY") result = apod.get_apod({ "date": datetime.now() }) print(result)
But, for the same reasons as
SyncApod.get_random
, it’s not recommended to do that.
AsyncApod
- class nasawrapper.apod.AsyncApod(api_key: str)
This class uses asynchronous programming syntax to make requests to the APOD API and returns the API response.
Parameters
api_key (str) - The API key.
- property allowed_keys
Returns the allowed keys in a dict.
- property api_key
Returns the API key.
- property base_url
Returns the base URL.
Returns the allowed keys in a dict.
- async get_apod(options: Dict[str, Union[str, int, bool, datetime.datetime]]) Union[nasawrapper.apod.ApodResponse, List[nasawrapper.apod.ApodResponse]]
This function is a coroutine.
Same thing as
SyncApod.get_apod
, but with asynchronous syntax.Example
from nasawrapper import AsyncApod from datetime import datetime import asyncio async def main(): apod = AsyncApod("DEMO_KEY") result = await apod.get_apod({ "date": datetime(2010, 2, 3) }) print(result) loop = asyncio.get_event_loop() loop.run_until_complete(main())
- async get_random() nasawrapper.apod.ApodResponse
This function is a coroutine.
Same thing as
SyncApod.get_random
but with asynchronous syntax.Example
from nasawrapper import AsyncApod import asyncio async def main(): apod = AsyncApod("DEMO_KEY") result = await apod.get_random() print(result) loop = asyncio.get_event_loop() loop.run_until_complete(main())
- async get_today_apod() nasawrapper.apod.ApodResponse
This function is a coroutine.
Same this as
SyncApod.get_today_apod
but with asynchronous syntax.Example
from nasawrapper import AsyncApod import asyncio async def main(): apod = AsyncApod("DEMO_KEY") result = await apod.get_today_apod() print(result) loop = asyncio.get_event_loop() loop.run_until_complete(main())
ApodQueryBuilder
- class nasawrapper.apod.ApodQueryBuilder(api_key: str, options={})
If you want to build a query using methods, this wrapper provides exactly what you want.
This class will build a query with the information provided by the methods.
Examples
Getting 2 random pictures
from nasawrapper import ApodQueryBuilder builder = ApodQueryBuilder("DEMO_KEY") result = builder.set_count(2).get_apod() print(result)
Getting picture from specific date
from nasawrapper import ApodQueryBuilder from datetime import datetime builder = ApodQueryBuilder("DEMO_KEY") result = builder.set_date(datetime(2010, 2, 3)) print(result)
- property api_key
Returns the API key.
- get_apod() Union[nasawrapper.apod.ApodResponse, List[nasawrapper.apod.ApodResponse]]
Make the request with the provided information.
- property options
Returns the options in dict format.
- set_date(date: datetime.datetime)
Add ‘date’ field to the options
- set_end_date(end_date: datetime.datetime)
Add ‘end_date’ field to the options
- set_start_date(start_date: datetime.datetime)
Add ‘start_date’ field to the options