Simple project to fetch users from a public API and save them into a CSV file using FastAPI, Celery, and Redis.
- Fetches a list of users from GitHub public API https://api.github.com/users
- Saves the data to a CSV file (ID, Name, URL)
- Executes tasks asynchronously using Celery
- Redis as a message broker
- Runs all components in Docker containers
external_api_integration/
├── docker-compose.yml # Docker configuration
├── Dockerfile # Images for FastAPI, Celery and Redis
├── requirements.txt # Python dependencies
├── config.py # File configuration
├── app.py # FastAPI application
├── tasks.py # Celery tasks
├── README.md # This file
└── github_users/ # Folder for CSV files
git clone https://github.com/pflaumax/external_api_integration.git
cd external_api_integrationdocker compose up --buildFor runs after build, you can simply start containers in detached mode:
docker compose up -dOpen a browser and go to http://localhost:8000/check_status
And main page showing:
{"status":"OK"}Send a POST request to /fetch_users by:
curl -X POST http://localhost:8000/fetch_usersOr open http://localhost:8000/docs Fetch Users and use Try it out and Execute.
Curl query response with:
{"message":"GitHub users fetch task started","task_id":<task id>,"status":"Task added to queue"}After the task is completed, a CSV file will appear in the github_users/ folder named like github_users_20250910_130828.csv with time stamp and containing data:
ID,Name,URL
1,mojombo,https://github.com/mojombo
2,defunkt,https://github.com/defunkt
3,pjhyett,https://github.com/pjhyett
...GET /- Main pagePOST /fetch_users- Start the user fetching taskGET /check_status"- Check status that endpoint is workingGET /docs- Documentation Swagger UIGET/redoc- Documentation ReDoc
docker compose fastapi docker compose celery docker compose redisdocker compose down- Data validation - add pydantic models for validation
- Advanced logging - structured logging with different log levels
- Monitoring - add flower for celery task monitoring
- Testing - unit tests with pytest
- Database storage - store results in postgreSQL or mongoDB