├── .gitignore
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py
├── spacex_py
├── __init__.py
├── _helpers
│ ├── __init__.py
│ └── _api.py
├── capsules.py
├── cores.py
├── info.py
├── launches.py
├── launchpads.py
└── rockets.py
└── tests
├── test_capsules.py
├── test_cores.py
├── test_info.py
├── test_launches.py
├── test_launchpads.py
└── test_rockets.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 | .pytest_cache/
49 |
50 | # Translations
51 | *.mo
52 | *.pot
53 |
54 | # Django stuff:
55 | *.log
56 | local_settings.py
57 | db.sqlite3
58 |
59 | # Flask stuff:
60 | instance/
61 | .webassets-cache
62 |
63 | # Scrapy stuff:
64 | .scrapy
65 |
66 | # Sphinx documentation
67 | docs/_build/
68 |
69 | # PyBuilder
70 | target/
71 |
72 | # Jupyter Notebook
73 | .ipynb_checkpoints
74 |
75 | # pyenv
76 | .python-version
77 |
78 | # celery beat schedule file
79 | celerybeat-schedule
80 |
81 | # SageMath parsed files
82 | *.sage.py
83 |
84 | # Environments
85 | .env
86 | .venv
87 | env/
88 | venv/
89 | ENV/
90 | env.bak/
91 | venv.bak/
92 |
93 | # Spyder project settings
94 | .spyderproject
95 | .spyproject
96 |
97 | # Rope project settings
98 | .ropeproject
99 |
100 | # mkdocs documentation
101 | /site
102 |
103 | # mypy
104 | .mypy_cache/
105 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | python:
3 | - "3.6"
4 | install:
5 | - pip install -r requirements.txt
6 | script:
7 | - pytest
8 | before_install:
9 | - "export PYTHONPATH=$PYTHONPATH:$(pwd)"
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at kaylum@hikaylum.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Kaylum Lally
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | SpaceX-PY
3 |
4 |
5 |
6 |
7 | [](https://travis-ci.org/TheDigitalTaste/digitalt-cli)
8 | [](https://github.com/HiKaylum/SpaceX-PY/issues)
9 | [](https://github.com/HiKaylum/SpaceX-PY/blob/master/LICENSE)
10 | [](https://github.com/HiKaylum/SpaceX-PY/stargazers)
11 |
12 |
13 |
14 | ## About
15 | Python wrapper for the unofficial SpaceX REST API. All information on such can be found [here](https://github.com/r-spacex/SpaceX-API). Used for retrieving information about:
16 |
17 | * Capsules
18 | * Cores
19 | * Launches
20 | * Launchpads
21 | * Rockets
22 | * Miscellaneous data
23 |
24 |
25 | ## Installation
26 | Command to install the package into your environment:
27 | ```BASH
28 | pip install spacex-py
29 | ```
30 |
31 | ## Usage
32 | Documentation for all queries can be found in their respective source files.
33 | This wrapper matches the [SpaceX API](https://github.com/r-spacex/SpaceX-API), allowing for ease uf use. Let's go through some examples:
34 |
35 | ```PYTHON
36 | from spacex_py import launches
37 |
38 | # Returns a tuple
39 | got_launches, header = launches.get_launches()
40 |
41 | # PyLint being a pain about header? use the following:
42 | got_launches, _ = launches.get_launches()
43 |
44 | # Prints a list of launches
45 | print(got_launches)
46 | ```
47 |
48 | Now let's get launches using a query:
49 |
50 | ```PYTHON
51 | from spacex_py import launches
52 |
53 | #Queries launches using the specific site id
54 | got_launches, _ = launches.get_launches(site_id="ksc_lc_39a")
55 |
56 | #Example query using multiple parameters
57 | got_launches, _ = launches.get_launches(site_id="ksc_lc_39a", payload_type='Satellite')
58 |
59 | #Prints a list of launches fitting the above parameters
60 | print(got_launches)
61 | ```
62 |
63 | ## License
64 | This project uses the [MIT License](https://opensource.org/licenses/MIT).
65 | More information can be found in [LICENSE](https://github.com/HiKaylum/SpaceX-PY/blob/master/LICENSE).
66 |
67 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | requests
2 | pytest
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import setuptools
2 |
3 | with open("README.md", "r") as fh:
4 | long_description = fh.read()
5 |
6 | setuptools.setup(
7 | name="spacex_py",
8 | version="1.0.0",
9 | author="Kaylum Lally",
10 | author_email="kaylum@hikaylum.me",
11 | description="Python wrapper for the SpaceX API",
12 | long_description=long_description,
13 | long_description_content_type="text/markdown",
14 | url="https://github.com/HiKaylum/SpaceX-PY",
15 | packages=setuptools.find_packages(),
16 | classifiers=[
17 | "Programming Language :: Python :: 3",
18 | "License :: OSI Approved :: MIT License",
19 | "Operating System :: OS Independent",
20 | ],
21 | install_requires=[
22 | "requests"
23 | ]
24 | )
--------------------------------------------------------------------------------
/spacex_py/__init__.py:
--------------------------------------------------------------------------------
1 | name = "spacex_py"
--------------------------------------------------------------------------------
/spacex_py/_helpers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HiKaylum/SpaceX-PY/57dc8f9b690ca0ba45a42af21d8ad9a0e8ec58bb/spacex_py/_helpers/__init__.py
--------------------------------------------------------------------------------
/spacex_py/_helpers/_api.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | def _get(endpoint, method="", query={}):
4 | """GET request to the SpaceX API
5 |
6 | Sends HTTP request to the SpaceX API given a
7 | set of parameters. Should only be used by the
8 | spacex_py module
9 |
10 | Parameters
11 | ----------
12 | endpoint : str
13 | The endpoint for the request
14 | method : str
15 | The method used for the request
16 | query : dict
17 | A dictionary representation of query string options
18 |
19 | Returns
20 | -------
21 | tuple
22 | returns the response body and headers
23 | """
24 | request_url = "https://api.spacexdata.com/v2/{end}/{meth}".format(
25 | end=endpoint, meth=method)
26 | res = requests.get(request_url, params=query)
27 |
28 | if not res.ok:
29 | res.raise_for_status()
30 |
31 | return res.json(), res.headers
32 |
--------------------------------------------------------------------------------
/spacex_py/capsules.py:
--------------------------------------------------------------------------------
1 | from ._helpers._api import _get
2 |
3 | def get_capsules(method=""):
4 | """Gets all capsules
5 |
6 | Gets capsules from the API
7 |
8 | Parameters
9 | ----------
10 | method : str (optional)
11 | the method used for the request
12 |
13 | Returns
14 | -------
15 | list
16 | a list of capsules
17 | """
18 | return _get("capsules", method)
19 |
20 | def get_capsule_parts(method="", **query):
21 | """Gets all capsule parts based on query strings
22 |
23 | Gets all capsule parts based on query strings
24 | from the API
25 |
26 | Parameters
27 | ----------
28 | method : str (optional)
29 | the method used for the request
30 | query : keyword args
31 | keyword args based on the API query strings
32 |
33 | Returns
34 | -------
35 | list
36 | a list of the capsule parts
37 | """
38 | return _get("parts/caps", method, query)
--------------------------------------------------------------------------------
/spacex_py/cores.py:
--------------------------------------------------------------------------------
1 | from ._helpers._api import _get
2 |
3 | def get_cores(method="", **query):
4 | """Gets all core parts based on query strings
5 |
6 | Gets all core parts based on query strings
7 | from the API
8 |
9 | Parameters
10 | ----------
11 | method : str (optional)
12 | the method used for the request
13 | query : keyword args
14 | keyword args based on the API query strings
15 |
16 | Returns
17 | -------
18 | list
19 | a list of the core parts
20 | """
21 | return _get("parts/cores", method, query)
--------------------------------------------------------------------------------
/spacex_py/info.py:
--------------------------------------------------------------------------------
1 | from ._helpers._api import _get
2 |
3 | def get_company_info():
4 | """Gets information on SpaceX
5 |
6 | Gets information on Space Exploration Technologies Corp
7 | from the API
8 |
9 | Returns
10 | -------
11 | dict
12 | a dict of the company information
13 | """
14 | return _get("info")
15 |
16 | def get_company_history_info():
17 | """Gets company history and milestones
18 |
19 | Gets company history and milestones from
20 | the API
21 |
22 | Returns
23 | -------
24 | list
25 | a list of the company's historical events and milestones
26 | """
27 | return _get("info/history")
28 |
29 | def get_roadster_info():
30 | """Gets information and orbital data for Starman Roadster
31 |
32 | Gets information and orbital data for Starman Roadster
33 | from the API (Updated every 10 minutes)
34 |
35 | Returns
36 | -------
37 | dict
38 | a dict of the Starman Roadster's information and orbital data
39 | """
40 | return _get("info/roadster")
--------------------------------------------------------------------------------
/spacex_py/launches.py:
--------------------------------------------------------------------------------
1 | from ._helpers._api import _get
2 |
3 | def get_launches(method="", **query):
4 | """Gets launches based on query strings
5 |
6 | Gets launches based on query strings from
7 | the API
8 |
9 | Parameters
10 | ----------
11 | method : str (optional)
12 | the method used for the request
13 | query : keyword args
14 | keyword args based on the API query strings
15 |
16 | Returns
17 | -------
18 | list
19 | a list of the launches
20 | """
21 | return _get("launches", method, query)
22 |
23 | def get_past_launches(**query):
24 | """Gets past launches
25 |
26 | Parameters
27 | ----------
28 | query : keyword args
29 | keyword args based on the API query strings
30 |
31 | Returns
32 | -------
33 | list
34 | a list of previous launches
35 | """
36 | return _get("launches", "", query)
37 |
38 | def get_latest_launch(**query):
39 | """Gets the latest launch
40 |
41 | Parameters
42 | ----------
43 | query : keyword args
44 | keyword args based on the API query strings
45 |
46 | Returns
47 | -------
48 | dict
49 | a dict containing latest launch data
50 | """
51 | return _get("launches", "latest", query)
52 |
53 | def get_next_launch(**query):
54 | """Gets the next launch
55 |
56 | Parameters
57 | ----------
58 | query : keyword args
59 | keyword args based on the API query strings
60 |
61 | Returns
62 | -------
63 | dict
64 | a dict containing next launch data
65 | """
66 | return _get("launches", "next", query)
67 |
68 | def get_upcoming_launches(**query):
69 | """Gets upcoming launches
70 |
71 | Parameters
72 | ----------
73 | query : keyword args
74 | keyword args based on the API query strings
75 |
76 | Retunrs
77 | -------
78 | list
79 | a list of the upcoming launches
80 | """
81 | return _get("launches", "upcoming", query)
--------------------------------------------------------------------------------
/spacex_py/launchpads.py:
--------------------------------------------------------------------------------
1 | from ._helpers._api import _get
2 |
3 | def get_launchpads(method=""):
4 | """Gets information related to launchpads used for SpaceX flights
5 |
6 | Gets information related to launchpads
7 | from the API
8 |
9 | Parameters
10 | ----------
11 | method : str (optional)
12 | the method used for the request
13 |
14 | Returns
15 | -------
16 | list
17 | a list of the launchpads
18 | """
19 | return _get("launchpads", method)
--------------------------------------------------------------------------------
/spacex_py/rockets.py:
--------------------------------------------------------------------------------
1 | from ._helpers._api import _get
2 |
3 | def get_rockets(method=""):
4 | """Gets information related to SpaceX rockets
5 |
6 | Gets information related to rockets from
7 | the API
8 |
9 | Parameters
10 | ----------
11 | method : str (optional)
12 | the method used for the request
13 |
14 | Returns
15 | -------
16 | list
17 | a list of the rockets
18 | """
19 | return _get("rockets", method)
--------------------------------------------------------------------------------
/tests/test_capsules.py:
--------------------------------------------------------------------------------
1 | from spacex_py import capsules
2 |
3 | def get_capsules():
4 | got_capsules, _ = capsules.get_capsules()
5 | return got_capsules
6 |
7 | def get_capsule_parts():
8 | got_capsule_parts, _ = capsules.get_capsule_parts()
9 | return got_capsule_parts
10 |
11 | def get_capsule_part_by_serial():
12 | got_capsule_part, _ = capsules.get_capsule_parts("C201")
13 | return got_capsule_part
14 |
15 | def get_capsule_part_by_query():
16 | got_capsule_parts, _ = capsules.get_capsule_parts(status="active")
17 | return got_capsule_parts
18 |
19 | def test_get_capsules():
20 | assert type(get_capsules()) is list
21 |
22 | def test_get_capsule_parts():
23 | assert type(get_capsule_parts()) is list
24 |
25 | def test_get_capsule_part_by_serial():
26 | assert type(get_capsule_part_by_serial()) is dict
27 |
28 | def test_get_capsule_part_by_query():
29 | assert type(get_capsule_part_by_query()) is list
--------------------------------------------------------------------------------
/tests/test_cores.py:
--------------------------------------------------------------------------------
1 | from spacex_py import cores
2 |
3 | def get_cores():
4 | got_cores, _ = cores.get_cores()
5 | return got_cores
6 |
7 | def get_core_by_method():
8 | got_core, _ = cores.get_cores("B1050")
9 | return got_core
10 |
11 | def get_cores_by_query():
12 | got_cores, _ = cores.get_cores(core_serial="B1050")
13 | return got_cores
14 |
15 | def test_get_cores():
16 | assert type(get_cores()) is list
17 |
18 | def test_get_core_by_mehtod():
19 | assert type(get_core_by_method()) is dict
20 |
21 | def test_get_cores_by_query():
22 | assert type(get_cores_by_query()) is list
--------------------------------------------------------------------------------
/tests/test_info.py:
--------------------------------------------------------------------------------
1 | from spacex_py import info
2 |
3 | def get_company_info():
4 | got_info, _ = info.get_company_info()
5 | return got_info
6 |
7 | def get_company_history_info():
8 | got_info, _ = info.get_company_history_info()
9 | return got_info
10 |
11 | def get_roadster_info():
12 | got_info, _ = info.get_roadster_info()
13 | return got_info
14 |
15 | def test_get_company_info():
16 | assert type(get_company_info()) is dict
17 |
18 | def test_get_company_history_info():
19 | assert type(get_company_history_info()) is list
20 |
21 | def test_get_roadster_info():
22 | assert type(get_roadster_info()) is dict
--------------------------------------------------------------------------------
/tests/test_launches.py:
--------------------------------------------------------------------------------
1 | from spacex_py import launches
2 |
3 | def get_launches():
4 | got_launches, _ = launches.get_launches()
5 | return got_launches
6 |
7 | def get_launches_by_query():
8 | got_launches, _ = launches.get_launches(site_id="ksc_lc_39a")
9 | return got_launches
10 |
11 | def get_past_launches():
12 | got_launches, _ = launches.get_past_launches()
13 | return got_launches
14 |
15 | def get_past_launches_by_query():
16 | got_launches, _ = launches.get_past_launches(site_id="ksc_lc_39a")
17 | return got_launches
18 |
19 | def get_latest_launch():
20 | got_launch, _ = launches.get_latest_launch()
21 | return got_launch
22 |
23 | def get_next_launch():
24 | got_launch, _ = launches.get_next_launch()
25 | return got_launch
26 |
27 | def get_upcoming_launches():
28 | got_launches, _ = launches.get_upcoming_launches()
29 | return got_launches
30 |
31 | def get_upcoming_launches_by_query():
32 | got_launches, _ = launches.get_upcoming_launches(site_id="ksc_lc_39a")
33 | return got_launches
34 |
35 | def test_get_launches():
36 | assert type(get_launches()) is list
37 |
38 | def test_get_launches_by_query():
39 | assert type(get_launches_by_query()) is list
40 |
41 | def test_get_past_launches():
42 | assert type(get_past_launches()) is list
43 |
44 | def test_get_past_launches_by_query():
45 | assert type(get_launches_by_query()) is list
46 |
47 | def test_get_latest_launch():
48 | assert type(get_latest_launch()) is dict
49 |
50 | def test_get_next_launch():
51 | assert type(get_next_launch()) is dict
52 |
53 | def test_get_upcoming_launches():
54 | assert type(get_upcoming_launches()) is list
55 |
56 | def test_get_upcoming_launches_by_query():
57 | assert type(get_past_launches_by_query()) is list
--------------------------------------------------------------------------------
/tests/test_launchpads.py:
--------------------------------------------------------------------------------
1 | from spacex_py import launchpads
2 |
3 | def get_launchpads():
4 | got_launchpads, _ = launchpads.get_launchpads()
5 | return got_launchpads
6 |
7 | def get_launchpad_by_method():
8 | got_launchpad, _ = launchpads.get_launchpads("ksc_lc_39a")
9 | return got_launchpad
10 |
11 | def test_get_launchpads():
12 | assert type(get_launchpads()) is list
13 |
14 | def test_get_launchpad_by_method():
15 | assert type(get_launchpad_by_method()) is dict
--------------------------------------------------------------------------------
/tests/test_rockets.py:
--------------------------------------------------------------------------------
1 | from spacex_py import rockets
2 |
3 | def get_rockets():
4 | got_rockets, _ = rockets.get_rockets()
5 | return got_rockets
6 |
7 | def get_rockets_by_method():
8 | got_rockets, _ = rockets.get_rockets("falcon1")
9 | return got_rockets
10 |
11 | def test_get_rockets():
12 | assert type(get_rockets()) is list
13 |
14 | def test_get_rockets_by_method():
15 | assert type(get_rockets_by_method()) is dict
--------------------------------------------------------------------------------