- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Core Tech
Requests and JSON APIs in Python
Build a Python command-line tool that downloads trail conditions as JSON, converts the payload into Python dictionaries and lists, and formats the data into a readable bulletin. Along the way, you will practice installing packages with pip, using the requests library, traversing nested JSON, and wiring the logic into a small CLI with automated tests.
Lab Info
Table of Contents
-
Challenge
Understand the project and starter structure
In this lab, you will turn a small Python starter project into a working command-line utility that retrieves JSON data from the web and converts it into a readable trail conditions bulletin. The project is intentionally scoped to core Python skills: calling a third-party package, decoding JSON into native data structures, navigating lists and dictionaries, and composing small functions into a simple end-to-end workflow. info> This lab experience was developed by the Pluralsight team using an internally developed AI tool. All sections were verified by human experts for accuracy prior to publications. However, content may still contain errors or inaccuracies, and we recommend independent verification.
To report a problem or provide feedback, click here. Feedback may be used to improve accuracy in accordance with our Privacy Policy. -
Challenge
Fetch and decode remote JSON data
This step builds the application's data-ingestion pipeline. You will create the function that performs the HTTP request, the function that validates and decodes the response body, and the function that extracts the nested trail list from the decoded payload.
-
Challenge
Normalize and filter the decoded trail data
This step transforms raw API records into dependable internal data. Once external JSON has been decoded, the values may still be inconsistent: names can include extra spaces, status text might use mixed casing, numbers can arrive as strings, and optional lists can be missing entirely.
-
Challenge
Format and assemble the bulletin output
This step turns processed data into a user-facing report. The program already knows how to fetch JSON, decode it, normalize trail records, filter visible items, and count alert labels.
-
Challenge
Add CLI options and graceful error handling
The reporting engine is now functional, but a useful tool also needs a clean entry point. This final step adds the command-line layer that lets users customize input and receive helpful feedback when network requests fail. ## Run the Application
You're ready to test the completed application!
First, start the sample API server in first Terminal tab:
python3 sample_server.pyLeave the server running, then in the second Terminal tab and run the application against the local server:
python3 -m trail_bulletin.cli --url http://localhost:8000/api/trailsIf everything is working correctly, the application downloads the trail data and displays a formatted bulletin that includes:
- A heading with the region, update time, and number of displayed trails
- One line for each visible trail
- An alert summary at the end of the report
To include both open and closed trails, run:
python3 -m trail_bulletin.cli --all --url http://localhost:8000/api/trailsIf the server is unavailable or the request fails, the application should display a message beginning with
Unable to download trail data:and exit with a status code of1.
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.