Exoplanet API Reference¶
This page provides a breakdown of the aionasa Exoplanet module.
Exoplanet API request structure:¶
See the exoplanet API documentation for in-depth information about the REST API, including table schema and query syntax.
A basic query will generally be made up of a few common parts:
Base URL (Required):
https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI
- Table to query (Required):
?table=exoplanets
exoplanets
: Confirmed planets.compositepars
: Composite planet data.exomultpars
: Extended planet data.aliastable
: Confirmed planet aliases.microlensing
: Confirmed planets discovered using microlensing.Other tables: (see documentation)
- Table to query (Required):
Output format:
&format=ascii
Other query params: (see documentation)
TODO: write up documentation for full set of query params and tables.</sup>
Note
Optionally install the pandas package to be able to output API data as a pandas DataFrame.
Client¶
- class aionasa.exoplanet.Exoplanet(api_key='DEMO_KEY', session=None)¶
Client for NASA Exoplanet Archive API.
- ..note::
Requests to this API do not seem to be subject to api.nasa.gov rate limits.
- await query(table, **query)¶
Query the database.
- Parameters
table – The table to query. This is required.
query – Other query parameters to be included in the request.
- Returns
The data returned by the API.
- Return type
str
- await query_aliastable(objname, **query)¶
Query the database’s alias table.
Shorthand for ?table=aliastable&objname=OBJNAME&…
- Parameters
objname – The name of the object to list aliases for.
query – Other query parameters to be included in the request.
- Returns
The alias table returned by the API.
- Return type
str
- await query_aliastable_df(objname, **query)¶
Query the database’s alias table. Format is requested as CSV and parsed to a pandas DataFrame before returning.
- ..note::
pandas
must be installed for this to work.
- Returns
The alias table returned by the API.
- Return type
DataFrame
- await query_aliastable_json(objname, **query)¶
Query the database’s alias table. Format is requested as JSON and parsed to a python list before returning.
- Returns
The alias table returned by the API.
- Return type
List[dict]
- await query_df(table, **query)¶
Query the database. Format is requested as CSV and parsed to a pandas DataFrame before returning.
- ..note::
pandas
must be installed for this to work.
- Returns
The parsed JSON data returned by the API.
- Return type
DataFrame
- await query_json(table, **query)¶
Query the database. Format is requested as JSON and parsed to a python list before returning.
- Returns
The parsed JSON data returned by the API.
- Return type
List[dict]
Example Code¶
This is a sample query from the Exoplanet API documentation:
https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&select=pl_hostname,ra,dec&order=dec&format=ascii
With curl, this could be done using the command:
curl "https://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&select=pl_hostname,ra,dec&order=dec&format=ascii"
With aionasa, it could be done using a python script:
import asyncio
from aionasa import Exoplanet
async def main():
async with Exoplanet() as exoplanet:
text = await exoplanet.query('exoplanets', select='pl_hostname,ra,dec', order='dec', format='ascii')
print(text)
if __name__ == "__main__":
asyncio.run(main())