<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flask</title>
	<atom:link href="https://renanmf.com/category/flask/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Software development, machine learning</description>
	<lastBuildDate>Thu, 10 Jun 2021 15:07:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://renanmf.com/wp-content/uploads/2020/03/cropped-android-chrome-512x512-2-32x32.png</url>
	<title>Flask</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Why Python for Web Development</title>
		<link>https://renanmf.com/why-python-for-web-development/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Thu, 10 Jun 2021 14:50:34 +0000</pubDate>
				<category><![CDATA[FastAPI]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[fastapi]]></category>
		<category><![CDATA[flask]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=3525</guid>

					<description><![CDATA[<p>The options to develop web apps these days are so many that it would take tens of thousands of words to list and describe each one of them. Languages like Java, JavaScript, C#, and Python are amongst the most famous for the purpose of developing web apps. In this article, I will discuss some of [&#8230;]</p>
<p>The content <a href="https://renanmf.com/why-python-for-web-development/">Why Python for Web Development</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The options to develop web apps these days are so many that it would take tens of thousands of words to list and describe each one of them.</p>
<p>Languages like Java, JavaScript, C#, and Python are amongst the most famous for the purpose of developing web apps.</p>
<p>In this article, I will discuss some of the benefits of using Python, specifically, for the development of web apps.</p>
<h2>Easy to learn</h2>
<p>Python is one of the easiest languages to learn.</p>
<p>If you are an experienced developer, you can learn enough Python in a week to be dangerous and do a lot.</p>
<p>If you are a complete newbie, Python is a great first language, with a clear syntax, and allows you to get started as quickly as one can be.</p>
<p>In any case, if you want a hand in starting out with Python, try my free <a href="https://renanmf.com/the-python-guide-for-beginners/">Python Guide For Beginners</a> to get you up to speed as fast as possible.</p>
<p>This image from <a href="https://xkcd.com/353/">xkcd</a> exemplifies this better than I ever could:</p>
<p><img decoding="async" src="https://renanmf.com/wp-content/uploads/2021/06/python_flying.png" alt="" /></p>
<h2>Ecosystem</h2>
<p>Libraries for everything.</p>
<p>Python has a library for every use case.</p>
<p>From web scraping and simple scripting tasks to machine learning.</p>
<p>The plethora of tools you can find in the Python ecosystem is so big that you can jump many levels of the heavy lifting in your app idea by just importing some super useful libraries.</p>
<p>There is no advantage in reinventing the wheel, the same way there is no benefit in rewriting code that has already been coded.</p>
<p>Especially considering how the most used libraries are battle-tested in levels a single developer could never do.</p>
<h2>Frameworks</h2>
<p>Python has lots of frameworks for web development.</p>
<p>By far, the most famous are <a href="https://www.djangoproject.com/">Django</a> and <a href="https://flask.palletsprojects.com/en/2.0.x/">Flask</a>, and as a recent new contender we have <a href="https://fastapi.tiangolo.com/">FastAPI</a>.</p>
<h3>Django</h3>
<p>Django is an interesting choice when you don&#8217;t want to think too much about all the pieces you are going to use.</p>
<p>Django has “Batteries Included”, which means a very good ORM, Authentication, Admin panel, template engine, and many other features most web apps use.</p>
<p>And if you need a REST API, <a href="https://renanmf.com/django-rest-framework-api-few-minutes/">Django REST Framework</a> is an easy-to-install plugin that makes full use of Django&#8217;s built-in structures.</p>
<h3>Flask</h3>
<p>Flask is minimalistic, known as a micro framework, it gives you the bare minimum to start coding.</p>
<p>For most things, you will need to add a plugin and integrate it into Flask.</p>
<p>SQLAlchemy for ORM for instance is a must if you don&#8217;t want to work with raw SQL (which I personally prefer).</p>
<p>On the other hand, Flask is good for those who want full control of their web app and choose the freedom to use whatever they want.</p>
<p>With its version 2.0, Flask now has full support for Async and WebSockets.</p>
<h3>FastAPI</h3>
<p>I have been using FastAPI for some time now and I have been really enjoying it.</p>
<p>It is very similar to Flask in the sense that is very lean and simple to get started.</p>
<p>At the same time, it comes with full support for Async right from the start and a variety of tools to develop APIs easily, like the auto-generation of documentation with Swagger.</p>
<p>And if you want to develop a standard web app, you can just make use of Jinja 2, the same way Flask does.</p>
<h2>Developer Time &gt; Execution Time</h2>
<p>When developing a new project, the time it takes to develop a new feature is the single most expensive item.</p>
<p>This is because the longer it takes to develop something, the more Developer Time it will take.</p>
<p>Being able to prototype something really fast is a huge advantage these days and Python and its ecosystem and frameworks are great tools to achieve things quickly.</p>
<p>This is the counterargument for people who say &quot;Python is slow&quot;.</p>
<p>Slow for what?</p>
<p>Many languages are faster in execution time, but, as I said in the title <strong>&quot;Developer Time &gt; Execution Time&quot;</strong>.</p>
<p>Another thing to notice is that I/O operations are by far the slowest thing in an app, so good caching strategies ( by using <a href="https://redis.io/">Redis</a> for example) and a better database design will give you better ROI than switching languages in many situations.</p>
<p>And finally, think in terms of Pareto&#8217;s 80/20, roughly 80% of consequences come from 20% of the causes</p>
<p>I remember in college when studying in this class of Computer Architecture and there was this chapter about optimization.</p>
<p>In one of the examples, there was a program written in C++, which is an extremely fast language for most purposes.</p>
<p>There was a small part of this program responsible for a huge part of the performance problems, simply because it was heavily used, more than other parts of the code.</p>
<p>What did they do?</p>
<p>They rewrote that single part in pure Assembly.</p>
<p>By Pareto&#8217;s logic, this small implementation was responsible for a good boost in performance.</p>
<p>For Python, you can follow the same logic.</p>
<p>In most cases, pure Python is more than enough and gives you the extra speed in development time.</p>
<p>When performance is a must, there are tons of Python libraries that are simply wrappers around C++ or C that are very performatic, which is the case for <a href="https://pandas.pydata.org/">Pandas</a> and <a href="https://www.tensorflow.org/">Tensorflow</a>.</p>
<p>And, if you have a specific use case, you can always implement the solution yourself in any other language and simply call it from Python.</p>
<p>There are many ways to do that, either by direct calls or by using another intermediate system like a message broker (Kafka for instance) to make the communication between systems even more transparent.</p>
<p>The content <a href="https://renanmf.com/why-python-for-web-development/">Why Python for Web Development</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Create an API in Python real quick with Flask</title>
		<link>https://renanmf.com/create-api-python-quick-flask/</link>
		
		<dc:creator><![CDATA[Renan Moura]]></dc:creator>
		<pubDate>Fri, 29 May 2020 09:49:54 +0000</pubDate>
				<category><![CDATA[Flask]]></category>
		<category><![CDATA[flask]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://renanmf.com/?p=1733</guid>

					<description><![CDATA[<p>Flask is a micro web framework written in Python. Being a microframework, it does not require particular tools or libraries. You can install it using pip. In my system I have pip pointing to Python 2 and pip3 pointing to Python 3, and since I&#8217;m going to use Python 3, I will install it with [&#8230;]</p>
<p>The content <a href="https://renanmf.com/create-api-python-quick-flask/">Create an API in Python real quick with Flask</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Flask is a micro web framework written in Python.</p>
<p>Being a microframework, it does not require particular tools or libraries.</p>
<p>You can install it using <code>pip</code>.</p>
<p>In my system I have <code>pip</code> pointing to Python 2 and <code>pip3</code> pointing to Python 3, and since I&#8217;m going to use Python 3, I will install it with <code>pip3</code>.</p>
<pre><code>pip3 install flask</code></pre>
<p>If Python 3 is your default Python, just do:</p>
<pre><code>pip install flask</code></pre>
<p>To code a quick API with Flask, the code below is all you need.</p>
<p>First import Flask and instantiate an <code>app</code> object giving it a name.</p>
<p>Then define a route for the first endpoint, in this case it goes to the root, no extra context.</p>
<p>The first <code>@app</code> part matches the name of the object <code>app</code> instantiated, than use <code>route(&#039;/&#039;)</code> indicating the route.</p>
<p>Right below it you can write a function that will be called when you access the route defined.</p>
<p>In this case, the function returns a simple phrase &quot;My first API.&quot;.</p>
<p>Finally you run your app using <code>app.run()</code>.</p>
<pre><code class="language-python">from flask import Flask

app = Flask(&#039;my_app&#039;)

@app.route(&#039;/&#039;)
def home():
    return &quot;My first API.&quot;

app.run()</code></pre>
<p>Save the code above in a file named <code>main.py</code>.</p>
<p>To run it just execute the code in a terminal:</p>
<pre><code>python3 main.py</code></pre>
<p>If Python 3 is your default Python, just do:</p>
<pre><code>python main.py</code></pre>
<p>You should see an output similar to this saying a development server is running on <code>http://127.0.0.1:5000/</code>.</p>
<pre><code> * Serving Flask app &quot;my_app&quot; (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [15/May/2020 08:47:47] &quot;GET / HTTP/1.1&quot; 200 -</code></pre>
<p>If you open <code>http://127.0.0.1:5000/</code> in your browser you should see the phrase &#8216;My first API.&#8217;.</p>
<p>Notice that the names given are arbitrary and to call the instance of Flask as <code>app</code> is a mere convention.</p>
<p>I could change everything to banana and it would still work.</p>
<pre><code class="language-python">from flask import Flask

banana = Flask(&#039;banana&#039;)

@banana.route(&#039;/&#039;)
def home():
    return &quot;My first API.&quot;

banana.run()</code></pre>
<p>I also recommend reading this post to see how to create an API using a different framework: <a href="https://renanmf.com/django-rest-framework-api-few-minutes/">Django REST Framework: API in a few minutes in Python</a>.</p>
<p>The content <a href="https://renanmf.com/create-api-python-quick-flask/">Create an API in Python real quick with Flask</a> is from <a href="https://renanmf.com">Renan Moura - Software Engineering</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
