Skip to content

notDEVANG/api-automation-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Automated Project

A Python CLI tool that fetches data from a REST API and saves to JSON with automation support.

API Used

JSONPlaceholder - https://jsonplaceholder.typicode.com

Features

  • Fetches data from JSONPlaceholder API
  • Saves data to JSON file
  • Handles network errors (connection, timeout, HTTP errors)
  • Handles empty response errors
  • Logging to both console and file
  • CLI arguments for flexible usage
  • Safe re-runs with timestamp option

Setup

python -m venv venv
venv\Scripts\activate  # Windows
pip install -r requirements.txt

CLI Usage

# Basic usage (fetches posts)
python main.py

# Fetch specific endpoint
python main.py users
python main.py comments
python main.py todos

# Limit results
python main.py posts --limit 5

# Custom output file
python main.py users -o users_data.json

# Safe re-runs (appends timestamp to filename)
python main.py posts --timestamp

# Verbose logging
python main.py posts -v

# Combined options
python main.py todos -l 10 -o my_todos.json -t -v

Available Endpoints

  • posts (default)
  • comments
  • albums
  • photos
  • todos
  • users

CLI Options

Option Description
endpoint API endpoint to fetch (default: posts)
-o, --output Output filename (default: data.json)
-l, --limit Limit number of results
-t, --timestamp Append timestamp to filename for safe re-runs
-v, --verbose Enable debug logging

Project Checklist

Core Features

  • Project exists
  • API used: JSONPlaceholder
  • Saves data to JSON
  • Handles network / empty-response errors
  • Logging added

Automation

  • API → file pipeline working
  • Script can be re-run without breaking (use --timestamp)

CLI Usage

  • Used command-line arguments
  • Script behavior changes based on CLI input

About

Python CLI tool for API automation with logging and error handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages