This is a cli tool to search for Star Wars characters to find information about their height, mass and also about their homeworld details using the SWAPI (star wars API).
- Character Search
- Gets and print information about a Star Wars character the user searched.
- It has attributes such as height, mass, and birth year of the character.
- Homeworld Details
- Prints the character's homeworld name, population, and orbital - rotation.
- Calculates the time on the homeworld's character relates to Earth years and days and prints an ratio.
Install the requirements.txt at my git repository :)
Clone the repository and follow the commands to run the script :)
###for the character search###
python main.py search 'luke sky'
###for the homeworld details search of that character###
python main.py search'luke sky' --world
-
def get_all_chars():
Gets all the characters from the SWAPI. Converts the data response into JSON and extract all the info.
-
def get_char_details(char_url):
Gets the properties of a character or a planet from the URL.
-
def search_char_name(results, name):
Searches for a specific character by name from the list of fetched characters.
-
Main
Uses argparse to handle CLI commands and flags. Prints character and homeworld information based on the user's input.
As part of expanding this project and improving my backend development skills, I plan to reimplement and enhance this CLI tool using Golang.
The objectives are:
- Recreate the current Python CLI functionality using Go.
- Use packages like
flagorcobrafor command-line argument parsing. - Maintain similar commands:
- Character search
- Homeworld details (
--worldflag equivalent)
- Use Go’s
net/httppackage to fetch data from the SWAPI. - Handle API responses efficiently and explore concurrency where useful.
- Define Go structs for:
- Characters
- Planets (homeworld data)
- Practice unmarshalling JSON responses into typed structs.
- Optimize API calls (e.g., caching results or reducing redundant requests).
- Use goroutines to fetch character and homeworld data in parallel.
- Implement robust error handling using Go’s explicit error system.
- Handle edge cases such as:
- Character not found
- API errors or downtime
- Invalid input
- Organize the project into packages (e.g.,
api,models,cli). - Improve code readability and maintainability.
- Compile the Go program into a standalone binary.
- Allow users to run the tool without installing dependencies.
- Write unit tests for:
- API calls
- Search functionality
- Use Go’s built-in
testingpackage.

