GithubHelp home page GithubHelp logo

dkbollaram2020 / python-rest-apis-with-flask-docker-mongodb-and-aws Goto Github PK

View Code? Open in Web Editor NEW

This project forked from duozhanggithub/python-rest-apis-with-flask-docker-mongodb-and-aws

1.0 1.0 0.0 4.29 MB

Useful knowledge for deploying machine learning models

Home Page: https://www.udemy.com/python-rest-apis-with-flask-docker-mongodb-and-aws-devops/learn/v4/content

Python 91.97% Dockerfile 3.23% Jupyter Notebook 4.80%

python-rest-apis-with-flask-docker-mongodb-and-aws's Introduction

Python-REST-APIs-with-Flask-Docker-MongoDB-and-AWS

Used ubuntu for demo, so summarize some of the common Linux commands here

ls: list files in a directory

cd: change directory

cat: show the content of file, or merge several files

sudo: allows users to run programs with the security privileges of another user, by default the superuser

apt: Advanced Package Tool, handle the installation and removal of software on Debian, Ubuntu, and related Linux distributions

apt install, apt update, apt remove...

mkdir xxx: make a directory called xxx

cp: copy, sudo cp ../app.py . cope app.py into a directory

touch: create or modify a file

How to dockerizing an application:

Code (refer to Dockerizing application demo https://github.com/duozhanggithub/Python-REST-APIs-with-Flask-Docker-MongoDB-and-AWS/tree/master/Dockerizing%20application%20demo)

  1. Docker file (with detailed explanations)

#download python 3 from docker hub FROM python:3 #download not only python 3, but also ubuntu operating system

#Tell the image(ubuntu OS with python 3 installed), the working directory is /usr/src/app WORKDIR /usr/src/app

#copy requirements.txt from local machine (the directory include the docker file) #to current working directory /usr/src/app COPY requirements.txt .

#install libraries listed in the requirements.txt on the Ubuntu machine RUN pip install --no-cache-dir -r requirements.txt

#copy all the files from local machine to the ubuntu COPY . .

#run python app.py CMD ["python", "app.py"]

  1. Docker compose file:

#wpecify docker compose version version: '3'

#services provided services: #specify the service of web web: #web is a services, you can build this services from the directory ./web #wehre the docker file located, it means in this direc you must have a docker file build: ./web # ports: "5000: 5000"

  1. Run the docker compose file:

sudo docker-compose build

sudo docker-compoase up

MongoDB

MongoDB server > Database > Collections > Documents

alt text

Database is a physical container for collections where each database gets its own set of files of the file system.

Collection is a group of Mongo documents and it's equivalent of an RDBMS table. Collections do not enforce schema.

Document is a set of key value pairs and the documents have dynamic schema. Very similar to JSON

alt text

Relational database has a typical schema design that shows a number of tables and the relationships between these tables while in MongoDB there is no concept of relationship.

Create or switch to the database: use mydb

Write documents into db: db.movie.insert({"name":"xyz"})

Delete database: db.dropDatabase()

Create a collection: db.createColelction(name, options), options is a documents, and optional

Drop collection: db.collection.drop(), db.COLLECTION_NAME.drop()

Insert document into collection: db.COLLECTION_NAME.insert(document)

Query documents: df.COLLECTION_NAME.find().pretty(), the pretty function make the query easy to read

More queries:

alt text

alt text

We can also use $AND, $OR etc.

Update: db.COLLECTION_NAME.update(SECTION_CRITERIA, UPDATED_DATA), set 'multi' parameter to 'True' if we want to update multiple documents

Deleting documents: db.COLLECTION_NAME.remove(DELETION_CRITERIA)

Projection: selecting only the necessary data rather than selecting the whole data of the document. Need to set a list of fields with value 1 or 0 and this is used to show the fields while 0 is used to hide the field.

Limiting records: db.COLLECTION_NAME.find().limit(NUMBER)

Sorting: db.COLLECTION_NAME.find().sort({KEY: 1}), 1 is ascending

Use MongoDB in web application

Code (https://github.com/duozhanggithub/Python-REST-APIs-with-Flask-Docker-MongoDB-and-AWS/tree/master/MongoDB-Building-a-Simple-Application-to-Keep-Track-of-Number-of-Users)

Links in the dockerfile, connect the web services with db services

pymongo

python-rest-apis-with-flask-docker-mongodb-and-aws's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.