Skip to content

Latest commit

 

History

History
59 lines (33 loc) · 2.67 KB

File metadata and controls

59 lines (33 loc) · 2.67 KB

Getting started with Launch Library 2

Introduction

The Launch Library 2 API (LL2 for short) enables you to request space related data such as launches, astronauts, etc. A full list of features can be found here.

To get you started with the API, this tutorial contains some introduction information together with code examples. For more detailed documentation on all the endpoints, please refer to the documentation.

Since the production API ll has rate limits, the development API lldev will be used in this tutorial, however this should only by used for development.

Quickstart

To query data, endpoint URLs are used. Filters and search terms can be added to these.

Querying the upcoming launch endpoint: https://lldev.thespacedevs.com/2.3.0/launches/upcoming/

Adding filters is done by adding them to the base url.

Examples

Querying & filtering past launches in Python

Filtering

Here two filters are added, a minimum and maximum date and time to get the launches between the two.

The time frame of the minimum and maximum are a month ago and now. The filtered variable is net, which represents the launch datetime.

To filter net we add two underscores __ and the filter terms gte (greater-than-or-equal) and lte (less-than-or-equal). Combining these two filters is done using the ampersand symbol &.

Before adding these filters a question mark ? is added after the base url to indicate the start of parameters. Then the filter parameter name is given with an equals sign = with the value following it.

# Time frame: now - 31 days ago
now = datetime.now()
month_ago = now - timedelta(days=31)
# Adding the time frame to the filters
net_filters = f'net__gte={month_ago.isoformat()}&net__lte={now.isoformat()}'

Setting response mode

# Set mode to detailed to include all related objects
mode = 'mode=detailed'

Limiting

# Limit returned results to just 2 per query
limit = 'limit=2'

Ordering

# Ordering the results by ascending T-0 (NET)
ordering = 'ordering=net'

Assembling query URL

# Assemble the query URL
query_url = launch_base_url + '?' + '&'.join(
(filters, mode, limit, ordering)
)
print(f'query URL: {query_url}')

Paginating through all the results

# Paginating through all the results
next_url = results['next']
while next_url:
# Requesting next data
next_results = get_results(next_url)
# Checking if it was succesful
if not results:
# Quitting the program as an example
# use your own error handling here
quit()
# Printing next results
print(next_results)
# Adding to the original results dictionary
results['results'] += next_results['results']
# Updating the next URL
next_url = next_results['next']