Skip to content

Changed version to v4, added and tested some endpoints according to v4 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# Visual studio code project settings
.vscode/
2 changes: 1 addition & 1 deletion spacex_py/_helpers/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _get(endpoint, method="", query={}):
tuple
returns the response body and headers
"""
request_url = "https://api.spacexdata.com/v2/{end}/{meth}".format(
request_url = "https://api.spacexdata.com/v4/{end}/{meth}".format(
end=endpoint, meth=method)
res = requests.get(request_url, params=query)

Expand Down
33 changes: 7 additions & 26 deletions spacex_py/capsules.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
from ._helpers._api import _get

def get_capsules(method=""):
"""Gets all capsules
"""Gets all capsules from the API.

Gets capsules from the API
This function retrieves all capsules available from the SpaceX API.

Parameters
----------
method : str (optional)
the method used for the request
method : str, optional
The method used for the request.

Returns
-------
list
a list of capsules
"""
return _get("capsules", method)

def get_capsule_parts(method="", **query):
"""Gets all capsule parts based on query strings

Gets all capsule parts based on query strings
from the API

Parameters
----------
method : str (optional)
the method used for the request
query : keyword args
keyword args based on the API query strings
list
A list of capsules.

Returns
-------
list
a list of the capsule parts
"""
return _get("parts/caps", method, query)
return _get("capsules", method)
19 changes: 10 additions & 9 deletions spacex_py/cores.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
def get_cores(method="", **query):
"""Gets all core parts based on query strings

Gets all core parts based on query strings
from the API
This function retrieves all core parts from the SpaceX API
based on the provided query strings.

Parameters
----------
method : str (optional)
the method used for the request
query : keyword args
keyword args based on the API query strings
method : str, optional
The HTTP method used for the request. Defaults to an empty string.
query : keyword arguments
Additional query parameters to be included in the request.

Returns
-------
list
a list of the core parts
list
A list of core parts retrieved from the API.

"""
return _get("parts/cores", method, query)
return _get("cores", method, query)
43 changes: 43 additions & 0 deletions spacex_py/crew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from ._helpers._api import _get

def get_crew_info(method = "", **query):
"""Gets information on SpaceX crew members.

This function retrieves information on the crew members of SpaceX
from the SpaceX API.

Returns
-------
dict
A dictionary containing information about the crew members. Each crew member
is represented as a dictionary with the following keys:

- 'name': The name of the crew member.
- 'agency': The agency or organization the crew member belongs to.
- 'status': The current status of the crew member.
- 'image': The URL of the image representing the crew member.
- 'wikipedia': The URL of the Wikipedia page for the crew member.
- 'launches': A list of launch IDs associated with the crew member.

Raises
------
requests.exceptions.RequestException
If there is an error while making the API request.

Returns
-------
dict
A dictionary containing information about the crew members.

Examples
--------
>>> crew_info = get_crew_info()
>>> print(crew_info['name'])
'Elon Musk'
>>> print(crew_info['agency'])
'SpaceX'
>>> print(crew_info['status'])
'active'
"""

return _get("crew", method, query)
42 changes: 42 additions & 0 deletions spacex_py/dragons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ._helpers._api import _get

def get_dragon_info(methods = '', **query):
"""Gets information on SpaceX Dragon spacecraft.

This function retrieves information on the SpaceX Dragon spacecraft
from the SpaceX API.

Returns
-------
dict
A dictionary containing information on the SpaceX Dragon spacecraft.

The dictionary has the following keys:
- 'name': The name of the Dragon spacecraft.
- 'type': The type of the Dragon spacecraft.
- 'active': A boolean indicating whether the Dragon spacecraft is active.
- 'crew_capacity': The maximum number of crew members the Dragon spacecraft can carry.
- 'sidewall_angle_deg': The sidewall angle of the Dragon spacecraft in degrees.
- 'diameter': The diameter of the Dragon spacecraft in meters.
- 'heat_shield': Information about the heat shield of the Dragon spacecraft.
- 'thrusters': Information about the thrusters of the Dragon spacecraft.
- 'launch_payload_mass': The maximum payload mass the Dragon spacecraft can carry to orbit.
- 'launch_payload_vol': The maximum payload volume the Dragon spacecraft can carry to orbit.
- 'return_payload_mass': The maximum payload mass the Dragon spacecraft can return from orbit.
- 'return_payload_vol': The maximum payload volume the Dragon spacecraft can return from orbit.
- 'pressurized_capsule': Information about the pressurized capsule of the Dragon spacecraft.
- 'trunk': Information about the trunk of the Dragon spacecraft.
- 'height_w_trunk': The height of the Dragon spacecraft with trunk in meters.
- 'flickr_images': A list of URLs to Flickr images of the Dragon spacecraft.

Raises
------
requests.exceptions.RequestException
If an error occurs while making the API request.

Returns
-------
dict
A dictionary containing information on the SpaceX Dragon spacecraft.
"""
return _get("dragons", methods, query)
17 changes: 9 additions & 8 deletions spacex_py/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_company_info():
dict
a dict of the company information
"""
return _get("info")
return _get("company")

def get_company_history_info():
"""Gets company history and milestones
Expand All @@ -24,17 +24,18 @@ def get_company_history_info():
list
a list of the company's historical events and milestones
"""
return _get("info/history")
return _get("history")

def get_roadster_info():
"""Gets information and orbital data for Starman Roadster
"""Gets information and orbital data for Starman Roadster.

Gets information and orbital data for Starman Roadster
from the API (Updated every 10 minutes)
This function retrieves information and orbital data for the Starman Roadster
from the SpaceX API. The API is updated every 10 minutes.

Returns
-------
dict
a dict of the Starman Roadster's information and orbital data
dict
A dictionary containing the Starman Roadster's information and orbital data.

"""
return _get("info/roadster")
return _get("roadster")
18 changes: 9 additions & 9 deletions spacex_py/launches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
def get_launches(method="", **query):
"""Gets launches based on query strings

Gets launches based on query strings from
the API
This function retrieves launches from the SpaceX API based on query strings.

Parameters
----------
method : str (optional)
the method used for the request
query : keyword args
keyword args based on the API query strings
method : str, optional
The method used for the request.
query : keyword arguments
Keyword arguments based on the API query strings.

Returns
-------
list
a list of the launches
list
A list of the launches.

"""
return _get("launches", method, query)

Expand All @@ -33,7 +33,7 @@ def get_past_launches(**query):
list
a list of previous launches
"""
return _get("launches", "", query)
return _get("launches", "past", query)

def get_latest_launch(**query):
"""Gets the latest launch
Expand Down
15 changes: 8 additions & 7 deletions spacex_py/launchpads.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from ._helpers._api import _get

def get_launchpads(method=""):
"""Gets information related to launchpads used for SpaceX flights
"""
Gets information related to launchpads used for SpaceX flights.

Gets information related to launchpads
from the API
This function retrieves information related to launchpads from the SpaceX API.

Parameters
----------
method : str (optional)
the method used for the request
method : str, optional
The method used for the request.

Returns
-------
list
a list of the launchpads
list
A list of the launchpads.

"""
return _get("launchpads", method)
47 changes: 47 additions & 0 deletions spacex_py/payload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from ._helpers._api import _get

def get_payload_info(method = "", **query):
"""Gets information on SpaceX payloads.

This function retrieves information on Space Exploration Technologies Corp
payloads from the API.

Returns
-------
dict
A dictionary containing information on SpaceX payloads.

Notes
-----
The returned dictionary has the following structure:
{
"payload_id": "string",
"norad_id": "string",
"reused": "boolean",
"customers": ["string"],
"nationality": "string",
"manufacturer": "string",
"payload_type": "string",
"payload_mass_kg": "float",
"payload_mass_lbs": "float",
"orbit": "string",
"orbit_params": {
"reference_system": "string",
"regime": "string",
"longitude": "float",
"semi_major_axis_km": "float",
"eccentricity": "float",
"periapsis_km": "float",
"apoapsis_km": "float",
"inclination_deg": "float",
"period_min": "float",
"lifespan_years": "float",
"epoch": "string",
"mean_motion": "float",
"raan": "float",
"arg_of_pericenter": "float",
"mean_anomaly": "float"
}
}
"""
return _get("payloads", method, query)
14 changes: 7 additions & 7 deletions spacex_py/rockets.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from ._helpers._api import _get

def get_rockets(method=""):
"""Gets information related to SpaceX rockets
"""Gets information related to SpaceX rockets.

Gets information related to rockets from
the API
This function retrieves information related to SpaceX rockets from the API.

Parameters
----------
method : str (optional)
the method used for the request
method : str, optional
The method used for the request.

Returns
-------
list
a list of the rockets
list
A list of the rockets.

"""
return _get("rockets", method)
22 changes: 22 additions & 0 deletions spacex_py/ships.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ._helpers._api import _get

def get_ship_info(method="", **query):
"""Gets information on SpaceX ships.

This function retrieves information on Space Exploration Technologies Corp
ships from the API.

Parameters
----------
method : str, optional
The HTTP method to use for the API request. Default is an empty string.
**query : dict
Additional query parameters to include in the API request.

Returns
-------
dict
A dictionary containing information on SpaceX ships.

"""
return _get("ships", method, query)
Loading