This project is a web application built with FastAPI and Celery, designed to retrieve and store IP data from the ipdata.co API into a MySQL database.
explanation.mp4
- Fetches detailed information about an IP address from ipdata.co.
- Stores the fetched data in a MySQL database using Peewee ORM.
- Provides endpoints to create tasks for fetching IP data and to check the status of a task.
- Allows retrieval of saved IP data using task IDs.
Before running the application, ensure you have the following installed:
- Python 3.x
- pip (Python package manager)
- MySQL server
- RabbitMQ server (or another Celery-compatible message broker)
-
Clone this repository:
git clone https://github.com/yourusername/ip-data-retrieval.git
-
Navigate to the project directory:
cd ip-data-retrieval
-
Install dependencies:
pip install -r app/requirements.txt
-
Set up your MySQL database. Create a new database and update the database configuration in
app/config/database.py
with your database credentials. -
Sign up for a free account on
ipdata.co
to obtain an API key. Replace'YOUR_API_KEY'
inapp/tasks.py
with your actual API key.
-
Start the Celery worker:
celery -A app.config.celery worker --loglevel=info
-
Start the FastAPI application:
python3 main.py
-
Once the application is running, you can interact with it using HTTP requests. Refer to the API documentation for available endpoints and their usage.
POST /api/v1/signup
: Register a new user account.POST /api/v1/auth
: Authenticate user credentials and obtain access tokens.POST /api/v1/refresh
: Refresh access tokens using a valid refresh token.
GET /api/v1/user
: Retrieve user details (requires authentication).
POST /api/v1/task
: Create a new task to fetch IP data for a given IP address. Returns the task ID.GET /api/v1/status/{task_id}
: Check the status of a task and retrieve the fetched IP data if the task is completed.
For running tests, you can use the following command:
python3 -m unittest discover -s app/tests -p 'test_*.py'