Python app using Flask to process customer and purchase data from CSV files, format it to JSON, and send it to an external REST API. Includes a CLI for automation.
/python_app/
├── app/
│ ├── __init__.py # Initialisation de l'application Flask
│ ├── routes.py # Routes API
│ ├── utils/
│ │ ├── __init__.py # Initialisation du package utils
│ │ ├── logger.py # Configuration des logs
│ │ ├── csv_parser.py # Lecture et traitement des fichiers CSV
│ │ ├── json_formatter.py # Formatage des données pour l'API
│ │ ├── api_client.py # Envoi des données à l'API
├── run.py # Point d'entrée de l'application Flask
├── cli.py # Interface CLI
├── requirements.txt # Dépendances Python
├── static/
│ ├── customers.csv # Exemple de fichier clients
│ ├── purchases.csv # Exemple de fichier achats
└── logs/
└── (Fichiers de logs générés automatiquement)
- CSV Processing: Parses
customers.csvandpurchases.csv, formats data for the API. - Flask API: Endpoints to process and send data.
- CLI: Automates CSV processing and data sending.
- Logging: Generates unique log files for each execution.
- Python 3.9
- Pip
- Clone the repo:
git clone <REPO_URL> cd python_app
- (Optional) Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Start Flask App:
python run.py
- Use CLI:
python cli.py --customers-file static/customers.csv --purchases-file static/purchases.csv --api-url https://myhostname.com/v1/customers
- Use Postman or curl to test the API.
- Ensure
customers.csvandpurchases.csvare correctly formatted. - Validate data sending with a tool like httpbin.org:
python cli.py --customers-file static/customers.csv --purchases-file static/purchases.csv --api-url https://httpbin.org/put
Author: Ahmed Nasri