<?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: Evan E. Baird</title>
    <description>The latest articles on Forem by Evan E. Baird (@mrcartoonster).</description>
    <link>https://forem.com/mrcartoonster</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%2F348488%2F89291790-109a-4254-a76b-04675d0fa67e.jpeg</url>
      <title>Forem: Evan E. Baird</title>
      <link>https://forem.com/mrcartoonster</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mrcartoonster"/>
    <language>en</language>
    <item>
      <title>FastAPI &amp; DO Deploy</title>
      <dc:creator>Evan E. Baird</dc:creator>
      <pubDate>Sat, 09 Jan 2021 23:35:54 +0000</pubDate>
      <link>https://forem.com/mrcartoonster/fastapi-do-deploy-1h10</link>
      <guid>https://forem.com/mrcartoonster/fastapi-do-deploy-1h10</guid>
      <description>&lt;p&gt;Here's a quickstart on deploying a FastAPI app to DigitalOcean's App Platform. FastAPI is a microframework in the same vain as Flask. Because of the similarities we'll be following the &lt;a href="https://github.com/digitalocean/sample-flask/blob/main/README.md"&gt;Flask Quickstart&lt;/a&gt; that DigialOcean provides. You'll first need a &lt;a href="https://m.do.co/c/beef14f5483f"&gt;DigitalOcean&lt;/a&gt; account and logged in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;gunicorn.conf.py&lt;/code&gt; &amp;amp; &lt;code&gt;Procfile&lt;/code&gt; files
&lt;/h2&gt;

&lt;p&gt;The main key to deploying your FastAPI app is setting up the &lt;code&gt;gunicorn.conf.py&lt;/code&gt; file and a &lt;code&gt;Procfile&lt;/code&gt;. Your &lt;code&gt;gunicorn.conf.py&lt;/code&gt; file will look like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# -*- coding: utf-8 -*-
&lt;/span&gt;&lt;span class="s"&gt;"""
Gunicorn with Uvicorn config to launch in Digital Ocean's App Platform.
"""&lt;/span&gt;
&lt;span class="n"&gt;bind&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.0.0.0:8080"&lt;/span&gt;
&lt;span class="n"&gt;workers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="c1"&gt;# Uvicorn's Gunicorn worker class
&lt;/span&gt;&lt;span class="n"&gt;worker_class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"uvicorn.workers.UvicornWorker"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we're following &lt;a href="https://docs.gunicorn.org/en/stable/configure.html"&gt;Gunicorn Configuration&lt;/a&gt; basic settings. The settings here are binding the FastAPI app to port &lt;code&gt;"8080"&lt;/code&gt;, setting 2 workers, you can add more workers or less, and the most important part is &lt;code&gt;uvicorn&lt;/code&gt;'s &lt;code&gt;gunicorn&lt;/code&gt; &lt;a href="https://www.uvicorn.org/deployment/#gunicorn"&gt;worker class&lt;/a&gt;. FastAPI is an async framework so we can't use a WSGI server but must use an ASGI server to serve an asynchronous web framework like FastAPI. Nicely &lt;code&gt;uvicorn&lt;/code&gt; supplys a worker class to help &lt;code&gt;gunicorn&lt;/code&gt; serve an async framework like FastAPI. The next file then is the &lt;code&gt;Procfile&lt;/code&gt; which will look like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: gunicorn --worker-tmp-dir /dev/shm --config gunicorn.conf.py src.main:app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have those two files you can now just follow the steps below and your FastAPI will deploy!&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Visit &lt;a href="https://cloud.digitalocean.com/apps"&gt;https://cloud.digitalocean.com/apps&lt;/a&gt; (if you're not logged in, you may see an error message. Visit &lt;a href="https://cloud.digitalocean.com/login"&gt;https://cloud.digitalocean.com/login&lt;/a&gt; directly and authenticate, then try again)&lt;/li&gt;
&lt;li&gt;Click "Launch App" or "Create App"&lt;/li&gt;
&lt;li&gt;Choose GitHub and authenticate with your GitHub credentials.&lt;/li&gt;
&lt;li&gt;Under Repository, choose this repository (e.g. /sample-flask) and click Next.&lt;/li&gt;
&lt;li&gt;On the next screen you will be prompted for the name of your app, which region you wish to deploy to, which branch you want deployments to a spin-off of and whether or not you wish to auto-deploy the app every time an update is made to this branch. Fill this out according to how you want your app to function and click Next.&lt;/li&gt;
&lt;li&gt;Modify the Run Command setting to point to your application. For this example, my project is named &lt;code&gt;mysite&lt;/code&gt;. So the modified command would be &lt;code&gt;gunicorn --worker-tmp-dir /dev/shm --config gunicorn.conf.py src.main:app&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;There is no need to modify the Build Command section&lt;/li&gt;
&lt;li&gt;Confirm your Plan settings and how many containers you want to launch and click Launch Basic/Pro App.&lt;/li&gt;
&lt;li&gt;You should see a "Building..." progress indicator. And you can click "Deployments"→"Details" to see more details of the build.&lt;/li&gt;
&lt;li&gt;It can currently take 5-6 minutes to build this app, so please be patient. Live build logs are coming soon to provide much more feedback during deployments.&lt;/li&gt;
&lt;li&gt;Once the build completes successfully, click the "Live App" link in the header and you should see your running application in a new tab, displaying the home page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Hopefully this quickstart got you up and rolling. If you're unfamilier with &lt;a href="https://fastapi.tiangolo.com/"&gt;FastAPI&lt;/a&gt;, watch calmcode.io's &lt;a href="https://calmcode.io/fastapi/hello-world.html"&gt;video tutorial&lt;/a&gt; on FastAPI. If you're ready to make the switch from Flask to FastAPI, check out Testdriven.io's FastAPI &lt;a href="https://testdriven.io/courses/tdd-fastapi/?utm_source=mrcartoonster"&gt;course&lt;/a&gt;. If you want me to also write a post on how I built this app, Tweet me at &lt;a href="https://twitter.com/mrcartoonster"&gt;@mrcartoonster&lt;/a&gt; or leave a message below that you'd like a tutorial about this example app. &lt;/p&gt;

</description>
      <category>dohackathon</category>
      <category>fastapi</category>
      <category>python</category>
      <category>pytest</category>
    </item>
    <item>
      <title>FastAPI Deploy On DigitalOcean's App Platform</title>
      <dc:creator>Evan E. Baird</dc:creator>
      <pubDate>Sat, 09 Jan 2021 02:17:22 +0000</pubDate>
      <link>https://forem.com/mrcartoonster/placeholder-title-m6p</link>
      <guid>https://forem.com/mrcartoonster/placeholder-title-m6p</guid>
      <description>&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;I built a simple FastAPI app that will respond with random Yo' Mama! jokes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Category Submission:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Random Roulette&lt;/strong&gt;: Everybody's building a COVID19 app. COVID19 got&lt;br&gt;
nothing on a good Yo' Mama joke! Also, I can't program for crap so there's that as well. One day I'll build a COVID19 FastAPI app. That day ain't today.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Link
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://fastapi-d-oapp-tjgd2.ondigitalocean.app/"&gt;Yo' Mama!&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;This is a simple FastAPI app that dishes out Yo Mama Jokes in the same vein as dishing out affirmations like &lt;a href="https://twitter.com/annthurium"&gt;Tilde Thurium&lt;/a&gt;'s &lt;a href="https://www.affirmations.dev/"&gt;affirmations&lt;/a&gt; API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Source Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/mrcartoonster/fastapi_DOapp"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Permissive License
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/mrcartoonster/fastapi_DOapp/blob/DEV-4-blog-post/LICENSE"&gt;MIT&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Building this app to show how to deploy a FastAPI app&lt;br&gt;
to DigitalOcean's App Platform. DigitalOcean has examples of the major Python web frameworks, but not FastAPI. This post will fix that since I believe that DigitalOcean's App Platform is ideal for deploying FastAPI fast.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I built it
&lt;/h3&gt;

&lt;p&gt;Using &lt;a href="https://fastapi.tiangolo.com/"&gt;FastAPI&lt;/a&gt; web framework&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Resources/Info
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://fastapi.tiangolo.com/"&gt;FastAPI&lt;/a&gt;: The Official Documentation&lt;/li&gt;
&lt;li&gt;Calmcode.io &lt;a href="https://calmcode.io/fastapi/hello-world.html"&gt;FastAPI course&lt;/a&gt;:
Fastest quickstart in the world for FastAPI. Yes, even faster than FastAPI's
official docs. Narrated, written, and coded by
&lt;a href="https://twitter.com/fishnets88"&gt;@fishnets88&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;TestDriven.io &lt;a href="https://testdriven.io/courses/tdd-fastapi/?utm_source=mrcartoonster"&gt;FastAPI course&lt;/a&gt;: If you're an actual professional Developer/Programmer, I'm not. This course supports financially FastAPI library and will show you how to use FastAPI for its ultimate purpose. Serving ML models. I just use it for Yo Mama jokes and Bob's Burgers hamburger recipes. There's got to be somebody out there who needs that for their ML stuff... Right???&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dohackathon</category>
      <category>fastapi</category>
      <category>python</category>
      <category>pytest</category>
    </item>
  </channel>
</rss>
