https://github.com/apfirebolt/myntra_ecommerce_api_in_django
An API created in Django with clothing store data from Mynta.com website
https://github.com/apfirebolt/myntra_ecommerce_api_in_django
api backend-api django django-rest-framework drf-spectacular myntra myntra-clone python swagger-api swagger-docs
Last synced: about 2 months ago
JSON representation
An API created in Django with clothing store data from Mynta.com website
- Host: GitHub
- URL: https://github.com/apfirebolt/myntra_ecommerce_api_in_django
- Owner: Apfirebolt
- License: mit
- Created: 2023-11-16T06:48:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-12T20:16:10.000Z (about 2 years ago)
- Last Synced: 2024-04-13T03:58:09.217Z (about 2 years ago)
- Topics: api, backend-api, django, django-rest-framework, drf-spectacular, myntra, myntra-clone, python, swagger-api, swagger-docs
- Language: Python
- Homepage:
- Size: 8.06 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README




# Ecommerce API created using Myntra dataset
This is an Ecommerce API which I created using a dataset with data taken from https://myntra.com which is one of the most popular online clothing stores in India.
http://localhost:8000/api-docs/
The API docs can be viewed using the above link. Swagger is used to generate API docs under the hood using a package called 'drf_spectacular'.
## Getting Started
* Create a new virtual environment and install packages specified in the requirements.txt file.
* Hook in your database of choice, make necessary database changes in the settings.py file inside the project folder. Obviously, some familiarity with Django folder structures is required for this. By default this project uses MySQL as database.
* Make migrations when you're done with the database settings and migrate.
* Run python manage.py runserver, and the application should be running on port 8000 by default.
## Built With
* [Python Django](https://www.djangoproject.com/)
* [Django Rest Framework](https://www.django-rest-framework.org/)
* [Swagger Docs](https://swagger.io/)
## Features
Application has around 10K entries for clothing related products coming from a dataset I retrieved from Kaggle.com
For feeding the data into the database, Management commands are used.
```
python manage.py populate
python manage.py clear
```
Populate command reads the csv file and creates an item model for each row saving it in the database. Clear command is as the name suggests clears the database in case required in any case.
The initial data was kind of large so I had to condense it by only picking the first 10k entries from the csv file. It was done using the pandas library.
```
import pandas as pd
def condense_data():
# Read data from csv file
df = pd.read_csv('data/myntra.csv')
# Read only first 5k enties and save it in a new csv file
df = df.head(5000)
df.to_csv('data/myntra_condensed.csv')
condense_data()
```
## Updates
React frontend to be added in future.
- Cached response using Redis, it decreased response time for subsequent requests from 33 ms to 5 ms approximately.
### Added Support for MySQL
Install pymysql library
```
pip install pymysql
```
Import it in settings.py file
```
import os
from pathlib import Path
import pymysql
pymysql.install_as_MySQLdb()
...
```
Database configuration
```
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myntra',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost', # Or the IP Address where your MySQL server is hosted
'PORT': '3306', # Default MySQL port
}
}
```
Run Migrations and populate data from the dataset.
```
python manage.py migrate
python manage.py populate
```
Taking Database Back-up
```
python manage.py db_backup [--filename ] [--database ]
python manage.py db_backup --filename myntra_backup.sql --database myntra
```
## API Throttling
API throttling is a concept of limiting the user access to a specific number based on the privileges of the user. In this application we allow logged in users to 10 requests/min and anonymous users to 5 req/min.
```
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAUL_THROTTLE_CLASSES': [
'rest_framework.throttling.AnonRateThrottle',
'rest_framework.throttling.UserRateThrottle',
],
'DEFAULT_THROTTLE_RATES': {
'anon': '5/min',
'user': '10/min',
},
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 50,
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}
```
## Authors
* **Amit Prafulla (APFirebolt)** - (http://apgiiit.com/)
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
```
docker-compose run --rm web python manage.py populate
docker-compose build --no-cache
docker run -d \
-p 5173:5432 \
--name my-postgres \
-e POSTGRES_DB=myntra \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=pass123 \
postgres:latest
docker-compose up
```
```
docker-compose down -v
```
## Screenshots
## Screenshots
Swagger Documentation

REST FRAEMWORK view of the items page.
