StarPy | Introduction

This is a python library and CLI for the Star Wars API (swapi.co).

This project is running on Python 3.6.7 but you can try in other versions as well.

Below you can find how to install it, the basic usage, CLI examples, how to test the project and the classes and its methods.

Installation

$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt

Basic Usage

import starpy

# Instance of the object
s = starpy.GetStars()

s.starships_speed_by_person(11)
# Returns: [[{'transport_id': '59', 'Max. Speed': '1050'}],
#           [{'transport_id': '65', 'Max. Speed': '1500'}],
#           [{'transport_id': '39', 'Max. Speed': '1100'}]]

s.fastest_person_with_v()
# Returns:  [{'Name': 'Zam Wesell', 'Max. Speed': 800, 'Vehicle name': 'Koro-2 Exodrive airspeeder'}]

s.name_and_max_speed_v()
# Returns: [[{'Name': 'Zam Wesell', 'Max. Speed': 800, 'Vehicle name': 'Koro-2 Exodrive airspeeder'}],
#             [{'Name': 'Anakin Skywalker', 'Max. Speed': 720, 'Vehicle name': 'XJ-6 airspeeder'}],
#             [{'Name': 'Luke Skywalker', 'Max. Speed': 650, 'Vehicle name': 'Snowspeeder'}]]

s.name_and_max_speed_s()
# Returns: [[{'Name': 'Padmé Amidala', 'Max. Speed': 8000, 'Starship name': 'H-type Nubian yacht'}],
#           [{'Name': 'Obi-Wan Kenobi', 'Max. Speed': 1500, 'Starship name': 'Jedi Interceptor'}],
#           [{'Name': 'Arvel Crynyd', 'Max. Speed': 1300, 'Starship name': 'A-wing'}]]

s.find_fastest_s()
# Returns: {10: 8000, 14: 1500, 5: 1300}

s.id_fastest_pilots_s()
# Returns: ['35', '10', '29']

s.id_fastest_pilots_v()
# Returns:  ['70', '11', '1']

s.pilot_names_s()
# Returns: ['Padmé Amidala', 'Obi-Wan Kenobi', 'Arvel Crynyd']

s.pilot_names_v()
# Returns: ['Zam Wesell', 'Anakin Skywalker', 'Luke Skywalker']

s.vehicles_speed_by_person(1)
# Returns: [[{'transport_id': '14', 'Max. Speed': '650'}],
#           [{'transport_id': '30', 'Max. Speed': '360'}]]

Command Line Interface (CLI)

From the command line, you can run:

$ python start.py command arg

python start.py fastest-person-with-s
--> Returns the fastest person driving a starship

python start.py vehicles-speed-by-person 1
--> Returns Luke's vehicles and its max. speed

start.py fastest-person-with-s
start.py fastest-person-with-v
start.py find-fastest-s
start.py find-fastest-v
start.py find-pilots-from-s
start.py find-pilots-from-v
start.py find-slowest-s
start.py find-slowest-v
start.py get-person-by-id <id>
start.py get-starships-by-id <id>
start.py get-vehicles-by-id <id>
start.py id-fastest-pilot-s
start.py id-fastest-pilot-v
start.py id-fastest-pilots-s
start.py id-fastest-pilots-v
start.py name-and-max-speed-s
start.py name-and-max-speed-v
start.py pilot-names-s
start.py pilot-names-v
start.py starships-speed-by-person <id>
start.py vehicles-speed-by-person <id>

Tests

You can run tests with unittests by running:

$ python3 -m unittest tests/test_api.py

Classes

GetStars class inherits methods and variables from StarPyMae Class

class starpy.api.GetStars[source]

Inherits methods and variables from StarPyMae Class

fastest_person_with_s()[source]

Returns fastest person’s name, its transport’s name and its max.

speed reached driving StarShips

fastest_person_with_v()[source]

Returns fastest person’s name, its transport’s name and its max.

speed reached driving Vehicles

find_fastest_s()[source]

Finds the fastest star ships with at least one pilot associated to it

find_fastest_v()[source]

Finds the fastest vehicles with at least one pilot associated to it

find_pilots_from_s()[source]

Finds star ship pilots

find_pilots_from_v()[source]

Finds vehicle pilots

find_slowest_s()[source]

Finds the slowest star ships with at least one pilot associated to it

find_slowest_v()[source]

Finds the slowest vehicles with at least one pilot associated to it

get_person_by_id(rid)[source]

Gets data from person’s id passed as argument

:param rid :type int

get_starships_by_id(rid)[source]

Gets star ship from id passed as argument to the rid parameter

:param rid :type: int :return:

get_vehicles_by_id(rid)[source]

Gets vehicles data from its id passed as argument to rid parameter

:param rid :type int

id_fastest_pilot_s()[source]

Returns id of fastest pilot driving StarShips.

id_fastest_pilot_v()[source]

Returns id of fastest pilot driving Vehicles.

id_fastest_pilots_s()[source]

Returns id’s list of fastest pilots driving StarShips.

id_fastest_pilots_v()[source]

Returns id’s list of fastest pilots driving Vehicles.

l(data)[source]

Auxiliary method

name_and_max_speed_s()[source]

Returns pilots name and its StarShips max. speed

name_and_max_speed_v()[source]

Returns pilots name and its Vehicles max. speed

pilot_names_s()[source]

Returns the fastest pilot names driving StarShips

pilot_names_v()[source]

Returns the fastest pilot names driving Vehicles

starships_speed_by_person(idpeople)[source]

Returns StarShips speed by passing person’s id as an argument

vehicles_speed_by_person(idpeople)[source]

Returns Vehicles speed by passing person’s id as an argument

class starpy.api.StarPyMae[source]

Main Class

Description: Makes the api call for data manipulation.

Indices and tables