<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Abaki12</title>
    <description>The latest articles on Forem by Abaki12 (@abaki12).</description>
    <link>https://forem.com/abaki12</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F750374%2F86f4bd52-d955-465a-9cbe-34d5a429aeb2.png</url>
      <title>Forem: Abaki12</title>
      <link>https://forem.com/abaki12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abaki12"/>
    <language>en</language>
    <item>
      <title>Getting Started with Fast API and Docker</title>
      <dc:creator>Abaki12</dc:creator>
      <pubDate>Thu, 11 Nov 2021 12:33:05 +0000</pubDate>
      <link>https://forem.com/abaki12/getting-started-with-fast-api-and-docker-1nb3</link>
      <guid>https://forem.com/abaki12/getting-started-with-fast-api-and-docker-1nb3</guid>
      <description>&lt;h2&gt;
  
  
  Fast API
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Fast API&lt;/strong&gt; is a web framework for building APIs with Python 3.6+ based on standard Python type hints. It is one of the fastest python frameworks available and very easy to learn and use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation of fastapi on windows
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; pip install fastapi
 pip install uvicorn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Installation on MacOS and Linux
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; %pip install fastapi
 %pip install uvicorn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  An Example
&lt;/h3&gt;
&lt;h3&gt;
  
  
  Create a python file and save as myapp.py with:
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; from fastapi importFastAPI
 app=FastAPI()
 @app.get("/")
 async def greetings():
     return "Helloo my viewer. Really proud of you!!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Then run the server with the command:
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; uvicorn myapp:app --reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  The server is open when the following info shows up:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   INFO:     Uvicorn running on http://127.0.0.1:8000 (Press 
   CTRL+C to quit)
   INFO:     Started reloader process [28720]
   INFO:     Started server process [28722]
   INFO:     Waiting for application startup.
   INFO:     Application startup complete.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then open your browser at &lt;a href="http://127.0.0.1:8000"&gt;http://127.0.0.1:8000&lt;/a&gt;&lt;br&gt;
You will see the JSON response as:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"Helloo my viewer. Really proud of you!!"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;To see the automatic interactive API documentation add '/docs' to your url i.e (&lt;a href="http://127.0.0.1.8000/docs):"&gt;http://127.0.0.1.8000/docs):&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xrwyyTeF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syfhvyyv5pasmg3i8wcw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xrwyyTeF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syfhvyyv5pasmg3i8wcw.PNG" alt="Image description" width="880" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Docker&lt;/strong&gt; is an open source platform for building ,deploying and managing containerized applications.&lt;br&gt;
&lt;strong&gt;Docker file&lt;/strong&gt; is a text document that contains all the commands a user could call on the command line to assemble an image&lt;br&gt;
&lt;strong&gt;Docker image&lt;/strong&gt; is a read-only, inert template that comes with instructions for deploying containers.&lt;br&gt;
&lt;strong&gt;Docker container&lt;/strong&gt; is a virtualized runtime environment that provides isolation capabilities for separating the execution of applications from the underpinning system.&lt;/p&gt;

&lt;p&gt;In Python requirements.txt file is a type of file that usually stores information about all the libraries, modules and packages in itself that are used while developing a particular project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating a requirements.txt file:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Docker python application:
&lt;/h3&gt;
&lt;h4&gt;
  
  
  we need to create a directory
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; cmd docker-python-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Then enter into the directory and create a Dockerfile with:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM python:3.6
COPY . /src  
CMD ["python", "/src/index.py"] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Then create a python file(This python file(index.py) will be executed in the docker container.) with:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   print("Hello Docker!!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  creating a docker image for the python application:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ docker build -t python-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Then run docker with:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker run python-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Hope this was useful, please feel free to leave your comments below.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>docker</category>
      <category>fastapi</category>
    </item>
  </channel>
</rss>
