<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rishabhojha on Medium]]></title>
        <description><![CDATA[Stories by Rishabhojha on Medium]]></description>
        <link>https://medium.com/@rishabhojha11?source=rss-aac8a455d16b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PS4VxjV0Deap9QE2oW6PHQ.jpeg</url>
            <title>Stories by Rishabhojha on Medium</title>
            <link>https://medium.com/@rishabhojha11?source=rss-aac8a455d16b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:04:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rishabhojha11/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[Django Project Setup for Production] (Part — 3) “config” package and “common” app]]></title>
            <link>https://medium.com/@rishabhojha11/django-project-setup-for-production-part-3-config-package-and-common-app-89e451d90476?source=rss-aac8a455d16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/89e451d90476</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[production]]></category>
            <dc:creator><![CDATA[Rishabhojha]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 17:51:40 GMT</pubDate>
            <atom:updated>2022-08-14T17:54:35.956Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Django Project Setup for Production] (Part — 3) “config” package and “common” app</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KFU020TqAmRfLHXz" /><figcaption>Photo by <a href="https://unsplash.com/@max_duz?utm_source=medium&amp;utm_medium=referral">Max Duzij</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>This is the 3rd blog in the series <em>“Django Project Setup for Production”</em>. In this blog we will go over the “config” package and the “common” app of the “DjangoProduction” project; you can clone this project from GitHub repository:</p><p><a href="https://github.com/PythonBitsYT/DjangoProduction">GitHub - PythonBitsYT/DjangoProduction</a></p><p>If the above clickable card does not work please use repository link: <a href="https://github.com/PythonBitsYT/DjangoProduction">https://github.com/PythonBitsYT/DjangoProduction</a></p><p>If you would like to setup a new Django Production ready project from scratch, or want to learn more about the “DjangoProduction” project design please refer the first article in this series — [Django Project Setup for Production] (Part — 1) New Project Setup:</p><p><a href="https://medium.com/@rishabhojha11/django-project-setup-for-production-part-1-new-project-setup-c656f0aff6cd">https://medium.com/@rishabhojha11/c656f0aff6cd</a></p><p>If you are interested in learning about the structure of “settings” package in detail and how the environment variables are used to decide which project configurations to use for execution please refer to the second article in this series — [Django Project Setup for Production] (Part — 2) The “settings” package:</p><p><a href="https://medium.com/@rishabhojha11/549e7935bbd0">https://medium.com/@rishabhojha11/549e7935bbd0</a></p><h3>The “config” package</h3><pre>config<br>├── __init__.py<br>├── asgi.py<br>├── settings<br>│   ├── __init__.py<br>│   ├── core_dev.py<br>│   ├── core_prod.py<br>│   ├── core_uat.py<br>│   ├── django.py<br>│   ├── env_vars.py<br>│   └── setup.py<br>├── settings_enums.py<br>├── static_storage_backends.py<br>├── storage_media_backends.py<br>├── urls.py<br>└── wsgi.py</pre><p>If you are familiar with default Django application structure which is created using “django-admin startproject” command then you can easily identify the similarities it has with the config package — and you are right. We have just moved the contents of default app (djangoprod in this case) to another package created inside it named “config”.</p><p>The main objective of this change was to provide another layer of abstraction so that if required we can put all the apps of our project inside “djangoprod” package and ship it as installable. (<em>Ignore this part if it sounds confusing</em>)</p><h3>The “common” app</h3><p>When building a large application you find yourself repeating the same code logic on multiple places. This is most common with enumerations, date and time utilities, random utilities, object conversion utilities.</p><p>To reduce this code duplicity we have created the common application in our project:</p><pre>common<br>├── __init__.py<br>├── admin.py<br>├── apps.py<br>├── enums<br>│   ├── __init__.py<br>│   ├── env_enums.py<br>│   └── generic_enums.py<br>├── exceptions<br>│   ├── __init__.py<br>│   └── custom_api_exception.py<br>├── generic_serializers<br>│   ├── __init__.py<br>├── generic_view_mixins<br>│   ├── __init__.py<br>│   └── custom_api_view.py<br>├── migrations<br>│   ├── __init__.py<br>├── model_queries<br>│   ├── __init__.py<br>├── models<br>│   ├── __init__.py<br>├── scripts<br>│   ├── __init__.py<br>├── security<br>│   └── set_client_ip.py<br>└── utilities<br>    ├── __init__.py<br>    ├── struct_obj.py<br>    └── utils<br>        ├── __init__.py<br>        ├── date_util.py<br>        ├── generic_util.py<br>        ├── random_util.py<br>        └── validation_util.py</pre><p>Let us go over each package under common app in brief:</p><h3>“enums” package</h3><ul><li>This package is used for creating global enums that will be used by multiple apps</li><li>We can create multiple enum python files under this package to support a wider namespace</li></ul><h3>“exceptions” package</h3><ul><li>This package is used for creating global exceptions that will be used across the project by various apps</li><li>“custom_api_exception.py” is a sample exception we have created</li></ul><h3>“generic_serializers” package</h3><ul><li>It is very common to come across validation requirements where we need to validate the same type of data in multiple apps</li><li>In such situations rather than creating multiple serializers makes more sense to define the common serializers under global context of common app</li></ul><h3>“generic_view_mixins” package</h3><pre>generic_view_mixins<br>├── __init__.py<br>└── custom_api_view.py</pre><ul><li>Similar to serializers, we can put any common view processing logic in this package by creating mixin classes to abstract the functionality</li><li>Notice the “customer_api_view.py” module — it inherits from APIView of DRF and is used to abstract away the logic of serializing the request data</li></ul><h3>“migrations” package</h3><ul><li>A Django default package</li></ul><h3>“models” package</h3><ul><li>This package holds definition of any abstract model that is to be used by the project</li><li>It helps by reducing the code duplicity in model creation</li></ul><h3>“model_queries” package</h3><ul><li>This package is for abstracting all the model related operation at one place</li><li>All modules under this package should consists of CURD model operations using OOPs design. These model classes should be imported and used instead of directly performing actions on the models</li></ul><h3>“scripts” package</h3><ul><li>A package to abstract away all the CRON type of python scripts</li></ul><h3>“security” package</h3><ul><li>This package consists of all the modules to be used for adding additional security to the project APIs</li><li>Such as — identifying the IP of requesting client, security from DDoS attacks, etc.</li></ul><h3>“utilities” package</h3><ul><li>Under utilities package we abstract all the common functions, classes, methods that will be used by multiple applications</li></ul><pre>utilities<br>├── __init__.py<br>├── struct_obj.py<br>└── utils<br>    ├── __init__.py<br>    ├── date_util.py<br>    ├── generic_util.py<br>    ├── random_util.py<br>    └── validation_util.py</pre><ul><li>“struct_obj.py” is a very useful utility that we use for converting a python dictionary to an object</li><li>“utils” package under utilities consists of date, validation, etc. related utilities that can be used across apps</li></ul><p>All the above packages help us to maximise the code re-usability by abstracting away the most commonly used features under “common” app. This behaviour can be extended even further as per your project requirements.</p><p>The purpose of this series was to give you a platform to start your django project setup journey. Please feel free to reach out to me on medium or linkedin for any questions, help, suggestions, or just to say ‘Hi’. Thank you for reading.</p><h3>References:</h3><p>[Django Project Setup for Production] (Part — 1) New Project Setup: <a href="https://medium.com/@rishabhojha11/django-project-setup-for-production-part-1-new-project-setup-c656f0aff6cd">https://medium.com/@rishabhojha11/c656f0aff6cd</a></p><p>[Django Project Setup for Production] (Part — 2) The “settings” package: <a href="https://medium.com/@rishabhojha11/549e7935bbd0">https://medium.com/@rishabhojha11/549e7935bbd0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89e451d90476" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Django Project Setup for Production] (Part — 2) The “settings” package]]></title>
            <link>https://medium.com/@rishabhojha11/django-project-setup-for-production-part-2-the-settings-package-549e7935bbd0?source=rss-aac8a455d16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/549e7935bbd0</guid>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[production]]></category>
            <dc:creator><![CDATA[Rishabhojha]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 17:50:30 GMT</pubDate>
            <atom:updated>2022-08-14T17:53:24.500Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Django Project Setup for Production] (Part — 2) The “settings” package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*peCq5Y7SzkrwbdtK" /><figcaption>Photo by <a href="https://unsplash.com/@carlevarino?utm_source=medium&amp;utm_medium=referral">Cesar Carlevarino Aragon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>This is the 2nd blog in the series <em>“Django Project Setup for Production”</em>. In this blog we will go over the “settings” package of the “DjangoProduction” project; you can clone this project from GitHub repository:</p><p><a href="https://github.com/PythonBitsYT/DjangoProduction">GitHub - PythonBitsYT/DjangoProduction</a></p><p>If the above clickable card does not work please use repository link: <a href="https://github.com/PythonBitsYT/DjangoProduction">https://github.com/PythonBitsYT/DjangoProduction</a></p><p>If you would like to setup a new Django Production ready project from scratch, or want to learn more about the “DjangoProduction” project design please refer the first article in this series — [Django Project Setup for Production] (Part — 1) New Project Setup:</p><p><a href="https://medium.com/@rishabhojha11/django-project-setup-for-production-part-1-new-project-setup-c656f0aff6cd">https://medium.com/@rishabhojha11/c656f0aff6cd</a></p><h3>Multiple requirements file</h3><pre>djangoprod<br>├── requirements_dev.txt<br>├── requirements_prod.txt<br>└── requirements_test.txt</pre><ul><li>We can have different versions of requirements installed in different environments</li><li>This feature comes in handy while building large applications</li></ul><h3>Having multiple settings files (Existing Approach)</h3><p>In Django we can have multiple settings file, and can choose which one to use while running the application using command:</p><pre>python manage.py runserver --settings=basic_app.settings</pre><p>If the above command looks familiar to you then you are most probably aware about the code duplicity and maintenance issues if causes for the development teams. It is a common practice to have different settings files for different environments, example:</p><pre>basic_app<br>├── __init__.py<br>├── asgi.py<br>├── settings_dev.py<br>├── settings_uat.py<br>├── settings_prod.py<br>├── urls.py<br>└── wsgi.py</pre><p>Having multiple settings file goes against the DRY (Do not Repeat Yourself) principle of clean and maintainable code. As, you have to copy the project configurations, database configuration, log configurations, app configurations, etc. in all the settings files. This also leaves room for bugs when you miss copying appropriate configurations to the settings file of the higher environment while deployment.</p><h3>Making “settings” a package (Suggested Approach)</h3><p>A better way to manage the configurations for multiple environments without breaking the DRY principle is to configure settings at run time. To achieve this we have setup settings as a package in “DjangoProduction” project with multiple files in it, each dealing with a specific feature of settings configuration:</p><pre>settings<br>├── __init__.py<br>├── core_dev.py<br>├── core_prod.py<br>├── core_uat.py<br>├── django.py<br>├── env_vars.py<br>└── setup.py</pre><p>Let us go over each file under settings package in brief:</p><h4>setup.py</h4><pre>from pathlib import Path<br>import environ<br>import sys<br>import os</pre><pre># Setup paths for the project<br>ROOT_DIR  = Path(__file__).resolve().parent.parent.parent.parent.parent<br>BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent<br>sys.path.append(BASE_DIR)</pre><pre># Setup ENV for the project<br>ENV = environ.Env(<br>    # set casting, default value<br>    DEBUG=(bool, False)<br>)<br># Take environment variables from .env file<br>environ.Env.read_env(env_file=os.path.join(ROOT_DIR, &#39;.env&#39;)) # reading .env file</pre><ul><li>This file consists of the root configurations used all across the settings package</li><li>We set the “ROOT_DIR” and “BASE_DIR” paths in this file</li><li>The ENV variable is initialised in this file to read the “.env” file from ROOT_DIR</li></ul><h4>env_vars.py</h4><ul><li>This file consists of all the settings env variables that will be used in the project</li><li>We generally initialise the AWS, Database, and Cache related variables in this file</li></ul><h4>django.py</h4><ul><li>This file consists of the configurations related to admin, timezone, applications, password validators, and middleware that are common across project environments</li><li>Some settings here, for example, INSTALLED_APPS can be appended/overridden in core_&lt;env&gt;.py file as and when required</li></ul><h4>core_dev/core_uat/core_prod.py</h4><ul><li>These are the environment related files where the project environment specific configurations such as — Logging, Database, and Cache configurations live.</li><li>Which file to execute is based on the environment and is selected at runtime using environment variables. <em>(more details on this below under __init__.py configuration details)</em></li></ul><h4>__init__.py</h4><pre>from .setup import ENV</pre><pre>if ENV(&quot;ENVIRONMENT&quot;)==&quot;PROD&quot;:<br>    from .core_prod import *<br>elif ENV(&quot;ENVIRONMENT&quot;)==&quot;UAT&quot;:<br>    from .core_uat import *<br>else:<br>    from .core_dev import *</pre><ul><li>This file acts as a driver code in deciding which “core_&lt;env&gt;” configurations to initialise based on the “ENVIRONMENT” variable defined in “.env” file in ROOT_DIR</li></ul><p>By creating settings as a package rather than file, and using “django-environ” package-distribution we can select the appropriate settings (configurations) at run time with the help of .env file.</p><h4>.env</h4><pre># Django Related<br>DEBUG=&quot;Value for Django Debug&quot;<br>ENVIRONMENT=&quot;Execution environment&quot;<br>LOG_DIR_PATH=&quot;Path to log file folder/package&quot;</pre><pre># DB Related<br>DATABASE_URL=&quot;DB connection URL&quot;<br>DATABASE_READ_REPLICA_1_URL=&quot;DB read replica connection URL&quot;</pre><pre># AWS Related<br>AWS_ACCESS_KEY_ID=&quot;AWS user access key ID&quot;<br>AWS_SECRET_ACCESS_KEY=&quot;AWS user access secret key&quot;<br>AWS_STORAGE_BUCKET_NAME=&quot;AWS storage bucket name&quot;<br>AWS_STORAGE_BUCKET_REGION=&quot;AWS storage bucket region&quot;<br>AWS_STATIC_STORAGE_BUCKET_NAME=&quot;AWS static storage bucket name&quot;</pre><ul><li>Above is an example .env file.</li><li>You can plug in the values for all the keys above and save it under ROOT_DIR of your project <em>(which is as per our settings the parent directory of the project)</em></li></ul><p>With the above setup you will be able to run “DjangoProduction” project for any environment using basic runserver command:</p><pre>python manage.py runserver </pre><p>In next part of this series we will go over “config” package under which the “settings” package reside and the “common” application with its advantages and dis-advantages.</p><p>[Django Project Setup for Production] (Part — 1) New Project Setup: <a href="https://medium.com/@rishabhojha11/django-project-setup-for-production-part-1-new-project-setup-c656f0aff6cd">https://medium.com/@rishabhojha11/c656f0aff6cd</a></p><p>[Django Project Setup for Production] (Part — 3) “config” package and “common” app: <a href="https://medium.com/@rishabhojha11/django-project-setup-for-production-part-3-config-package-and-common-app-89e451d90476">https://medium.com/@rishabhojha11/89e451d90476</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=549e7935bbd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Django Project Setup for Production] (Part — 1) New Project Setup]]></title>
            <link>https://medium.com/@rishabhojha11/django-project-setup-for-production-part-1-new-project-setup-c656f0aff6cd?source=rss-aac8a455d16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c656f0aff6cd</guid>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[production]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rishabhojha]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 17:46:10 GMT</pubDate>
            <atom:updated>2022-08-14T17:51:34.500Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Django Project Setup for Production] (Part — 1) New Project Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rd_zY1Oh4H6-5uVT" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Django is gaining popularity around the globe as a fast-paced batteries included web-framework as it provides a pack of features for developers to quickly build production ready applications quickly.</p><p>Instagram, NatGeo, Mozilla, Spotify, Pinterest, and BitBucket are examples of some of the Big-Tech companies that are already using Django in their production environments. Also, with the release of Django 4 and the multitude of features it provides, the number of organisations using Django is bound to grow and with it the need to setup new Django production ready projects.</p><h3><strong>Problems with new Django project setups</strong></h3><p>Setting up a new Django project could be difficult due to all the initial configurations and settings involved. Also, there is not clearly defined set of rules to identify which settings to enable and what could be the advantages/disadvantages of using those features. Moreover, the default project structure provided by Django using the “startproject” command is not easy to extend, and might cause maintenance issues later on.</p><p>Addressing the above issues and many more I have crated a boilerplate of Django production ready project with the intent to reduce the development time in setting up a new project from scratch. You can clone it from the GitHub repository:</p><p><a href="https://github.com/PythonBitsYT/DjangoProduction">GitHub - PythonBitsYT/DjangoProduction</a></p><p>If the above clickable card does not work please use repository link: <a href="https://github.com/PythonBitsYT/DjangoProduction">https://github.com/PythonBitsYT/DjangoProduction</a></p><h3><strong>DjangoProduction project structure</strong></h3><p>Let us go over the “DjangoProduction” project structure and highlight some of the key differences from the default Django project structure:</p><ul><li>“settings” is not a python file, rather it is a directory</li></ul><pre>settings<br>├── __init__.py<br>├── core_dev.py<br>├── core_prod.py<br>├── core_uat.py<br>├── django.py<br>├── env_vars.py<br>└── setup.py</pre><ul><li>“settings” directory is itself inside “config” directory, which is a lot similar to what you get in the default app with “django-admin startproject”command</li></ul><pre>config<br>├── __init__.py<br>├── asgi.py<br>├── settings<br>│   ├── __init__.py<br>│   ├── core_dev.py<br>│   ├── core_prod.py<br>│   ├── core_uat.py<br>│   ├── django.py<br>│   ├── env_vars.py<br>│   └── setup.py<br>├── settings_enums.py<br>├── static_storage_backends.py<br>├── storage_media_backends.py<br>├── urls.py<br>└── wsgi.py</pre><ul><li>There are multiple “requirements” file for test, dev, and prod environments</li></ul><pre>djangoprod<br>├── requirements_dev.txt<br>├── requirements_prod.txt<br>└── requirements_test.txt</pre><ul><li>There is an app named “common” which consists of project code (serialisers, views, enums, utilities) which are common across all apps and can be reused</li></ul><pre>djangoprod<br>├── common<br>│   ├── __init__.py<br>│   ├── admin.py<br>│   ├── apps.py<br>│   ├── enums<br>│   │   ├── __init__.py<br>│   │   ├── env_enums.py<br>│   │   └── generic_enums.py<br>│   ├── exceptions<br>│   │   ├── __init__.py<br>│   ├── generic_serializers<br>│   │   ├── __init__.py<br>│   ├── generic_view_mixins<br>│   │   ├── __init__.py<br>│   │   └── custom_api_view.py<br>│   ├── migrations<br>│   │   ├── __init__.py<br>│   ├── model_queries<br>│   │   ├── __init__.py<br>│   ├── models<br>│   │   ├── __init__.py<br>│   ├── scripts<br>│   │   ├── __init__.py<br>│   ├── security<br>│   │   └── set_client_ip.py<br>│   └── utilities<br>│       ├── __init__.py<br>│       ├── struct_obj.py<br>│       └── utils<br>│           ├── date_util.py<br>│           ├── generic_util.py<br>│           ├── random_util.py<br>│           └── validation_util.py</pre><p>We will go over each of these differences in upcoming parts of this article. We will also take a deep dive into the settings module configurations, and how this structure accommodates multiple deployment environments — DEV, UAT, and PROD better.</p><p>[Django Project Setup for Production] (Part — 2) The “settings” package: <a href="https://medium.com/@rishabhojha11/549e7935bbd0">https://medium.com/@rishabhojha11/549e7935bbd0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c656f0aff6cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Choosing Stable Python Version]]></title>
            <link>https://medium.com/@rishabhojha11/the-art-of-choosing-stable-python-version-70a7c755467b?source=rss-aac8a455d16b------2</link>
            <guid isPermaLink="false">https://medium.com/p/70a7c755467b</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[production]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Rishabhojha]]></dc:creator>
            <pubDate>Tue, 10 May 2022 03:08:29 GMT</pubDate>
            <atom:updated>2022-05-10T03:08:29.534Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c5O3fhEt3qMAUg81" /><figcaption>Photo by <a href="https://unsplash.com/@ralexnder?utm_source=medium&amp;utm_medium=referral">Alex Chumak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the most common problem that developers face is selecting the correct stable python version for building a new application. The google searches on this topic are futile as the appropriate python version to use depends on your use-case.</p><p>In this article we will discuss some of the best ways to identify a python version that best suits your requirements.</p><h3><strong>Python versioning scheme</strong></h3><p>Before we begin it is important to understand how python version releases are named.</p><p>Major.Minor.Patch, is the versioning scheme used for naming python releases. It is called Semantic Versioning. So, for python version 3.9.2– 3 is Major release, 9 is Minor release, and 2 is Patch release.</p><h3><strong>Identify Requirements</strong></h3><p>Now, let us begin by answering the following questions. Also, make sure to discuss them with your team(if you are working with one):</p><ol><li>Which is the latest (non-beta/non-research) python version?</li><li>Are we developing a web-based, mobile-based, or desktop-based application?</li><li>How long do we expect to maintain this application?</li><li>What are the python packages that we require? Which version of these python packages do we require?</li></ol><p>Above are the basic questions to get you started, you might want to add a few more questions to this list based on your use case.</p><h3><strong>Select Python Release</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OicfpBuZou9cWmlT6XJSw.png" /><figcaption>Python Active Release</figcaption></figure><p>To check the latest python release go to official python release website <a href="https://www.python.org/downloads/">https://www.python.org/downloads</a>/ and check the active python releases table.</p><p>It is best to follow the Goldilocks Principle when choosing a python version for your project.</p><p><strong>Avoid Latest Releases</strong></p><p>Although, most of the latest python releases are duly stable. It is best to avoid them for two main reasons:</p><ol><li>There might be a small bug hiding somewhere in the release which can leave developers scratching their heads when the application is the near go-live.</li><li>Some python packages may not be compatible with latest releases.</li></ol><p><strong>Avoid Very Old Releases</strong></p><p>If you do not have a very strong reason to go for python 2.7 in 2022. Do not use it.</p><p>Also, if you need to build an application that will need maintenance for many years to come, it is advisable to not use python 3.7 as it will reach its end-of-life in 2023. By the time you are done with development, you will find yourself reworking on the upgrade to some other latest python release.</p><p><strong>Somewhere in between</strong></p><p>If you are very confused a good rule of thumb to follow is to select a python version which is one less than the latest major release. This version is generally stable as it has been used by thousands of developers around the globe, and is probably used by many organisations in their production application.</p><p>For example, if the latest python major release is 3.10, it is best to choose python 3.9 for building your application. As by this time python 3.9 is significantly more stable than the latest releases. Plus, probably most of the python package have been tested against it, and issues resolved.</p><h3>Bugs in Release</h3><p>Read the change log on official python website for the python version you are planing to use. Example, change log of python version 3.8.12 <a href="https://docs.python.org/release/3.8.12/whatsnew/changelog.html#changelog">https://docs.python.org/release/3.8.12/whatsnew/changelog.html#changelog</a></p><p>It is very important that you read the change log document for the python version that you are selecting. Also, it is strongly advised to read the change log of python patch(3.8.X) release for at-least two patch release before and after the python patch you are planing to use.</p><p>This is important as it gives you the idea of bugs that have been fixed in the version you have selected, or if any bugs have been introduced that are fixed in later versions.</p><p>For example, in python version 3.8.10 imports were failing in some cases due to python trying to make imports absolute, which was fixed in python version 3.8.11. <em>You can read more about it in the change log for python </em><a href="https://docs.python.org/release/3.8.11/whatsnew/changelog.html#changelog"><em>3.8.11</em></a></p><h3><strong>Dependencies</strong></h3><p>A lot of developers tend to skip over this part of the process in selecting the correct python version for their use-case. As it is difficult to gauge which packages/frameworks might be used by the project before development.</p><p>It is recommended to have at least a basic list of the most important python packages and frameworks that will be used during development.</p><p>If you are trying to develop a python web-based application using Django. It is best to identify which Django version will suit your requirements before rushing to identify the python version. This is because some Django versions are only available for latest python releases.</p><p>For instance, Django 4 requires python version 3.8+. Older python releases are not supported. So, if you want to use Django 4, it does not make sense to do analysis of the python versions before 3.8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*k_fFQabmKWxLfzX4SlcXXQ.png" /><figcaption>Django 4.0 release notes</figcaption></figure><h3><strong>Conclusion</strong></h3><p>There is no fixed metrics that can be used to identify an appropriate python version for you. The “correct” python version might be different for different use case.</p><p>The objective of this document is to give out a few ideas to help you get started with your journey in the Art Of Choosing Stable Python Version.</p><h3><strong>References</strong></h3><ul><li><a href="https://semver.org/">https://semver.org/</a></li><li><a href="https://docs.python.org/release/3.8.12/whatsnew/changelog.html#changelog">https://docs.python.org/release/3.8.12/whatsnew/changelog.html#changelog</a></li><li><a href="https://docs.djangoproject.com/en/4.0/releases/4.0/">https://docs.djangoproject.com/en/4.0/releases/4.0/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70a7c755467b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>