This project was developed to offer a complete service for querying, managing, and exporting ZIP codes, using Python, FastAPI, and MongoDB.
Develop a system that:
- ZIP Code Lookup: Allows searching for ZIP codes using the ViaCEP API.
- Storage: Saves query results in a MongoDB database.
- Export: Provides the option to export data in JSON or CSV formats.
- CRUD Operations: Implements CRUD operations (Create, Read, Update, and Delete) to manage stored data.
-
ZIP Code Lookup π
- Search ZIP codes by state and specific ZIP code.
- Utilizes the ViaCEP API to fetch data.
- Includes validation to ensure integrity and handle errors effectively.
-
Storage in MongoDB ποΈ
- Saves query data in MongoDB.
- Prevents duplication by verifying records before saving.
-
Data Export π€
- Stored data can be exported as:
- JSON: Structured for integration or API usage.
- CSV: For data analysis or spreadsheet manipulation.
- Stored data can be exported as:
-
CRUD Operations π§
- Create: Manually add a ZIP code record.
- Read: List all stored ZIP codes.
- Update: Update data for a specific ZIP code.
- Delete: Remove unwanted records.
- Python π: Main programming language.
- FastAPI β‘: Framework for API development.
- MongoDB π: NoSQL database for storage.
- ViaCEP API π‘: Service for ZIP code lookup.
- Postman π¬: Tool for endpoint testing and validation.
- pymongo: MongoDB connection.
- csv, json: Data manipulation and export.
- requests: External API consumption.
Clone the repository:
git clone https://github.com/your-username/zip-code-lookup.git
cd zip-code-lookup
Install dependencies:
pip install -r requirements.txt
Configure MongoDB:
Ensure MongoDB is installed and running on the default port.
Start the service:
python zip_code_lookup.py
- POST /create/: Creates a new ZIP code record.
- GET /read/: Lists all stored ZIP code records.
- PUT /update/{zip_code}/: Updates data for a specific ZIP code.
- DELETE /delete/{zip_code}/: Deletes a ZIP code record.
-
Export to JSON:
python zip_code_lookup.py --export json
-
Export to CSV:
python zip_code_lookup.py --export csv
zip_code_lookup.py
: Main script implementing the service.queries.json
: Example export in JSON format.queries.csv
: Example export in CSV format.