<?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 Sagar Hande on Medium]]></title>
        <description><![CDATA[Stories by Sagar Hande on Medium]]></description>
        <link>https://medium.com/@sagar.hande.work?source=rss-949bb924c97a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*P6E5lYfcrfI0PFBO</url>
            <title>Stories by Sagar Hande on Medium</title>
            <link>https://medium.com/@sagar.hande.work?source=rss-949bb924c97a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:09:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sagar.hande.work/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[Spark Architecture: explained with analogy]]></title>
            <link>https://medium.com/@sagar.hande.work/spark-architecture-explained-with-analogy-0ff087fd550e?source=rss-949bb924c97a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ff087fd550e</guid>
            <category><![CDATA[spark-architecture]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[pyspark]]></category>
            <dc:creator><![CDATA[Sagar Hande]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 18:31:21 GMT</pubDate>
            <atom:updated>2025-09-16T18:31:21.196Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s break down Apache Spark’s architecture in the simplest way possible, using a relatable analogy.</p><h3>The Big Picture Analogy: A Construction Project</h3><p>Imagine you are a <strong>general contractor</strong> (the boss) who has been hired to build a house. You have a giant pile of bricks (your <strong>Big Data</strong>) that need to be sorted and laid.</p><p>You can’t do it alone, so you need a team.</p><h3>1. The Key Characters (Spark Components)</h3><p>In our construction project, here’s who does what:</p><ul><li><strong>You, The Boss (The Driver Program):</strong> This is the main program (your Python, Scala, or Java code) that defines the tasks. You tell everyone what to do. You run it on your <strong>laptop</strong> (or a dedicated edge node).</li><li><strong>The Foreman (The Cluster Manager):</strong> You’re a busy boss, so you hire a <strong>foreman</strong> to handle the workers for you. The foreman doesn’t do the work but is responsible for hiring and managing the labourers. In Spark, common “foremen” are:</li><li><strong>Standalone Cluster Manager:</strong> Spark’s own simple foreman.</li><li><strong>YARN:</strong> The foreman used by Hadoop.</li><li><strong>Kubernetes:</strong> A modern, popular foreman.</li><li><strong>The Construction Workers (The Executors):</strong> These are the <strong>machines</strong> (or JVMs) that actually do the work. Each worker has their own set of tools (memory and CPU cores). They are hired by the foreman on your behalf. Their jobs are to:</li><li>Perform computations (sort bricks, lay bricks).</li><li>Store data in memory or on disc <em>while the job is running</em>.</li><li><strong>The Blueprint (The Directed Acyclic Graph — DAG):</strong> You don’t just yell, “Build a house!” You have a step-by-step plan:1) Lay foundation, 2) Build walls, 3) Add roof. Spark is smart. It looks at your entire code and creates an optimised execution plan (the DAG) <em>before</em> telling the workers what to do. This makes it incredibly fast.</li></ul><h3>2. The End-to-End Process: Building the House (Processing Data)</h3><p>Let’s say your task is to count how many times the word “Spark” appears in a giant set of books (10,000 books).</p><p><strong>Step 1: You Give The Order (Submit the Job)</strong> You write a simple script. You run this script from your laptop. Your laptop becomes the <strong>driver.</strong></p><p><strong>Step 2: Hiring the Crew (Cluster Acquisition)</strong> The <strong>driver</strong> program talks to the <strong>cluster manager</strong> (the foreman) and says, “I need 4 workers for a job.” The foreman finds 4 free machines in the cluster and assigns them as <strong>executors.</strong></p><p><strong>Step 3: Explaining The Plan (Creating the DAG)</strong> The driver doesn’t send the data yet. It first creates the optimised plan (the DAG):</p><ol><li><strong>Read</strong> the books from the storage (e.g., HDFS, S3).</li><li><strong>Split</strong> each book into lines, and each line into words (a transformation called flatMap).</li><li><strong>Filter</strong> the words to only keep the word “Spark”.</li><li><strong>Count</strong> how many times “Spark” appears (an action called count).</li><li><strong>Print</strong> the result.</li></ol><p><strong>Step 4: Delegating The Work (Task Execution)</strong> Now, the driver sends this plan and the <em>code</em> to the executors. The foreman tells each executor which part of the data to work on.</p><ul><li>Executor 1 gets books 1–2500.</li><li>Executor 2 gets books 2501–5000.</li><li>…and so on.</li></ul><p>Each executor works on its chunk of data <em>in parallel</em>, following the steps: read, split, filter, and count the word “Spark” in their assigned books.</p><p><strong>Step 5: Reporting Back (Shuffling and Aggregating)</strong> Each executor now has a local count (e.g., Executor 1 found 5,234 “Spark”s, Executor 2 found 4,567 “Spark”s, etc.). They send these small results back to the driver.</p><p><strong>Step 6: The Final Result (Action)</strong> The <strong>driver</strong> receives all the small counts from the executors. It adds them all together into one grand total (e.g., 52,891) and prints it on your console.</p><p><strong>Step 7: Job Done (Teardown)</strong> The Foreman lets the Executors go. They are now free for another job. The driver program exits.</p><h3>Simple Diagram of the Data Flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SUc45q5_-Op_9Zn8M4rOpg.png" /></figure><h3>The Code</h3><pre># Import the necessary library<br>from pyspark.sql import SparkSession<br><br># Step 1: Initialize the Spark Session (The Boss gets ready)<br># This creates the &#39;Driver Program&#39; on your machine.<br>spark = SparkSession.builder \\\\<br>    .appName(&quot;WordCountExample&quot;) \\\\  # Name of your job<br>    .getOrCreate()<br><br># Step 2: Create a SparkContext object (The Boss&#39;s megaphone)<br># The SparkSession uses this underneath to communicate with the cluster.<br>sc = spark.sparkContext<br><br># Let&#39;s assume the path to our 10,000 books on HDFS/S3/Local storage<br># For example, &quot;hdfs:///data/books/*.txt&quot; or &quot;s3a://my-bucket/books/*.txt&quot;<br>books_path = &quot;/path/to/your/giant/book/folder/*.txt&quot;<br><br># Step 3: Read the data (The Boss points to the pile of bricks)<br># This creates an RDD (Resilient Distributed Dataset), the basic data structure in Spark.<br># The data is *not* loaded here yet. Spark just knows about it and its partitions.<br>lines_rdd = sc.textFile(books_path)<br><br># Step 4: Define the plan (The Boss creates the blueprint)<br># This is a chain of TRANSFORMATIONS. No computation happens here!<br># Spark builds the execution plan (DAG) in the background.<br># Split each line into words and flatten the list<br>words_rdd = lines_rdd.flatMap(lambda line: line.split(&quot; &quot;))<br><br># Filter to keep only the word &quot;Spark&quot;<br>spark_words_rdd = words_rdd.filter(lambda word: word.lower() == &quot;spark&quot;)<br><br># Map each word to a count of 1, then add them all up<br># This is a common pattern: map followed by reduce.<br>word_count = spark_words_rdd.count() # &#39;count()&#39; is an ACTION<br><br># Step 5: Execute the job (The Boss yells &quot;GO!&quot; via the Foreman)<br># The &#39;count()&#39; action above TRIGGERS the entire computation.<br># Now the Driver talks to the Cluster Manager, which launches Executors.<br># The plan (DAG) is optimized, sent to Executors, and they process the data in parallel.<br>print(&quot;=&quot;*50)<br>print(f&quot;The word &#39;Spark&#39; appears {word_count} times.&quot;)<br>print(&quot;=&quot;*50)<br><br># Step 6: Stop the Spark Session (The Boss tells the Foreman the job is done)<br>spark.stop()</pre><h3>How This Maps to Our Architecture</h3><p>Let’s trace the code execution back to our construction analogy:</p><ol><li><strong>SparkSession.builder...</strong>: This is <strong>you, the boss (the driver program),</strong> setting up your office and deciding you need to get a job done.</li><li><strong>sc.textFile(books_path)</strong>: You are pointing to the <strong>giant pile of bricks (your data)</strong> and telling Spark where it is. Spark logically divides this data into chunks (partitions) that will be sent to different workers. Notice the data isn&#39;t actually loaded yet.</li><li><strong>.flatMap(...).filter(...)</strong>:This is you designing the <strong>blueprint (the DAG)</strong>. You are defining the step-by-step instructions:&quot;First, split the text into words. Then, only keep the word &#39;Spark&#39;.&quot; These are <strong>transformations</strong>. Nothing is built yet—you are just drawing the plans.</li><li><strong>.count()</strong>: This is the crucial moment. You, the Boss, yell <strong>&quot;GO!&quot; (This is an ACTION)</strong>. This command triggers the entire process:</li></ol><ul><li>The driver talks to the cluster manager<strong> (the foreman).</strong></li><li>The foreman acquires <strong>executors (workers)</strong>.</li><li>The Driver sends the blueprint (DAG) and the code (the lambda functions) to the Executors.</li><li>Each Executor works on its partition of the data <em>in parallel</em>, reading its assigned books, splitting lines, filtering words, and counting.</li><li>The Executors send their local counts back to the Driver.</li></ul><ol><li><strong>print(f&quot;The word &#39;Spark&#39; appears {word_count} times...&quot;)</strong>: The <strong>Driver</strong> receives all the partial counts from the Executors, adds them together into a final total, and gives you the result.</li><li><strong>spark.stop()</strong>: You, the Boss, tell the Foreman that the project is complete. The Foreman releases the Executors so they can be used for other jobs.</li></ol><h3>Key Takeaway for a Newbie</h3><p>The most important concept in Spark is the difference between <strong>Transformations</strong> (like flatMap, filter) and <strong>Actions</strong> (like count, collect, saveAsTextFile).</p><ul><li><strong>Transformations</strong> are lazy. They are just instructions for a future computation. You can stack them all day long, and Spark will just keep adding to the blueprint. <strong>No data is processed.</strong></li><li><strong>Actions</strong> are eager. They are the trigger that forces Spark to take the blueprint, hire the crew, and actually do all the work.</li></ul><p>This lazy evaluation allows Spark to look at your entire plan (e.g., read -&gt; split -&gt; filter -&gt; count) and optimize it <em>before</em> doing any actual work, making it extremely efficient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ff087fd550e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ What is CORS?]]></title>
            <link>https://medium.com/@sagar.hande.work/what-is-cors-8c16c5d680cf?source=rss-949bb924c97a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c16c5d680cf</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[web-developement]]></category>
            <category><![CDATA[cors]]></category>
            <dc:creator><![CDATA[Sagar Hande]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 12:25:19 GMT</pubDate>
            <atom:updated>2025-06-17T12:25:19.699Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>CORS</strong> stands for <strong>Cross-Origin Resource Sharing</strong>.</p><p>It’s a <strong>security feature</strong> in web browsers that <strong>controls whether one website can request data from another</strong>.</p><h3>🔒 Why Does CORS Exist?</h3><p>Imagine this:</p><ul><li>You’re on <a href="https://mycoolapp.com./">https://mycoolapp.com.</a></li><li>Your JavaScript code tries to get data from <a href="https://api.someothersite.com./">https://api.someothersite.com.</a></li></ul><p>This is a <strong>cross-origin request</strong> (different domain).<br> Browsers <strong>block it by default</strong>, to <strong>protect users from malicious websites</strong>.</p><h3>✅ How to Allow It?</h3><p>The <strong>server (API)</strong> you’re trying to access must say:</p><blockquote><em>“Yes, I allow your site to talk to me.”</em></blockquote><p>It does this by sending a special header:</p><pre>Access-Control-Allow-Origin: https://mycoolapp.com</pre><p>Or to allow any site (not always safe):</p><pre>Access-Control-Allow-Origin: *</pre><h3>🔧 Common CORS Use Cases</h3><ul><li>Your <strong>frontend (React, Vue, etc.)</strong> runs on localhost:3000.</li><li>Your <strong>backend (API)</strong> runs on localhost:5000.</li><li>That’s a different <strong>origin</strong>, so your browser blocks the request <strong>unless</strong> the backend adds CORS headers.</li></ul><h3>💡 How to Fix CORS (As a Developer)</h3><p>On the <strong>backend</strong>, you can add CORS headers:</p><h3>Node.js (Express):</h3><pre>const cors = require(&#39;cors&#39;);<br>app.use(cors()); // allow all origins</pre><h3>Flask (Python):</h3><pre>from flask_cors import CORS<br>CORS(app)</pre><h3>🚫 CORS is Not a Security Wall on the Backend</h3><p>It’s a <strong>browser feature</strong>. CORS <strong>doesn’t stop</strong> someone from using tools like curl or Postman to call an API directly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c16c5d680cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Say Goodbye to Dependency Hell in Python with Docker]]></title>
            <link>https://medium.com/@sagar.hande.work/say-goodbye-to-dependency-hell-in-python-with-docker-0e8e49ceba28?source=rss-949bb924c97a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e8e49ceba28</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[pyodbc]]></category>
            <category><![CDATA[pylucene]]></category>
            <category><![CDATA[python-interpreter]]></category>
            <dc:creator><![CDATA[Sagar Hande]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 04:43:55 GMT</pubDate>
            <atom:updated>2025-04-20T04:43:55.229Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Problem: Python Dependencies Gone Wild</h3><p>If you’ve ever tried to run a Python SDK like pyodbc or pylucene, you’ve probably faced this dreaded scenario: missing system drivers, incompatible environments, and cryptic install errors — aka <strong>Dependency Hell</strong>.</p><p>Recently, I hit a wall trying to use pyodbc on macOS. The SDK needs a Microsoft SQL Server driver, but macOS doesn’t support one. Same with pylucene in the past — it required a specific Java version and native libraries that were nearly impossible to configure. 😩</p><p>That’s when I decided I’d had enough.</p><h3>The Solution: Run Everything in Docker</h3><p>After some digging, I found a surprisingly clean solution — <strong>use Docker for both your environment and dependencies</strong>. Most SDKs, drivers, and even databases already have official or community-maintained Docker images available on <a href="https://hub.docker.com/">Docker Hub</a>.</p><p>Rather than wrestling with dependencies manually, you can simply:</p><ul><li>Pull a compatible base image</li><li>Install what you need in Docker</li><li>Run your project in an isolated, fully-configured container</li></ul><h3>✅ Real-Life Example: Using pyodbc on macOS</h3><p>To make pyodbc work with MSSQL on my Mac, I created a Docker Compose setup with two containers:</p><ol><li><strong>MSSQL Server</strong> container</li><li><strong>Python + pyodbc</strong> container (with ODBC drivers pre-installed)</li></ol><p>Here’s how you can do the same:</p><h3>🧱 Dockerfile for Python + pyodbc + ODBC Driver</h3><pre>FROM amazonlinux:2</pre><pre># Install system dependencies<br>RUN yum update -y &amp;&amp; \<br>    yum install -y gcc-c++ unixODBC-devel tar curl</pre><pre># Install Microsoft ODBC Driver 18<br>RUN curl <a href="https://packages.microsoft.com/config/rhel/9/prod.repo">https://packages.microsoft.com/config/rhel/9/prod.repo</a> &gt; /etc/yum.repos.d/mssql-release.repo &amp;&amp; \<br>    yum remove -y unixODBC-utf16 unixODBC-utf16-devel &amp;&amp; \<br>    ACCEPT_EULA=Y yum install -y msodbcsql18</pre><pre># Install Python and pip<br>RUN yum install -y python3 python3-pip &amp;&amp; \<br>    pip3 install --upgrade pip</pre><pre># Install Python dependencies<br>COPY requirements.txt .<br>RUN pip3 install pyodbc &amp;&amp; \<br>    pip3 install -r requirements.txt || true</pre><pre># Set working directory<br>WORKDIR /app<br>COPY . /app</pre><h3>⚙️ Docker Compose File</h3><p>This sets up both services and links them on the same network:</p><pre>version: &#39;3.8&#39;</pre><pre>services:<br>  mssql:<br>    image: mcr.microsoft.com/mssql/server:2022-latest<br>    container_name: mssql<br>    environment:<br>      SA_PASSWORD: &quot;Root@123&quot;<br>      ACCEPT_EULA: &quot;Y&quot;<br>    ports:<br>      - &quot;1433:1433&quot;<br>    networks:<br>      - backend</pre><pre>  app:<br>    build:<br>      context: .<br>      dockerfile: Dockerfile<br>    container_name: python-interpreter<br>    depends_on:<br>      - mssql<br>    environment:<br>      - DB_SERVER=mssql<br>      - DB_PORT=1433<br>      - DB_USER=sa<br>      - DB_PASSWORD=Root@123<br>    volumes:<br>      - .:/app<br>    networks:<br>      - backend<br>    command: tail -f /dev/null  # Keeps container running</pre><pre>networks:<br>  backend:<br>    driver: bridge</pre><h3>🛠️ Running It Locally</h3><p>Once you’ve built everything, run the stack using:</p><pre>docker-compose up --build</pre><p>Then, you can enter your Python container like this:</p><pre>docker exec -it python-interpreter bash</pre><p>From there, run your scripts or even open a Python shell with all dependencies pre-installed:</p><pre>python3</pre><h3>💡 Bonus: Use Docker as a Remote Interpreter in PyCharm</h3><p>If you’re using <strong>PyCharm Professional</strong>, you can set up your container as a remote interpreter for a smoother development experience.</p><p>Here’s a great video from JetBrains to walk you through it: <a href="https://www.youtube.com/watch?v=6RlgQBB1UDU">PyCharm + Docker Setup</a></p><h3>Conclusion</h3><p>Docker is a game-changer when it comes to avoiding Python dependency nightmares. Whether it’s native drivers, database SDKs, or complex builds — you can package everything into a container and just <em>run</em>.</p><p>Stop fighting your system, and start containerizing your problems away. 🔥</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e8e49ceba28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LRU Cache Implementation in Python]]></title>
            <link>https://medium.com/@sagar.hande.work/lru-cache-implementation-in-python-3ae3e6953255?source=rss-949bb924c97a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ae3e6953255</guid>
            <category><![CDATA[lru-python-implementation]]></category>
            <category><![CDATA[lru-cache]]></category>
            <dc:creator><![CDATA[Sagar Hande]]></dc:creator>
            <pubDate>Mon, 03 Feb 2025 18:15:57 GMT</pubDate>
            <atom:updated>2025-02-03T18:15:57.306Z</atom:updated>
            <content:encoded><![CDATA[<p>Below is a Python implementation of an <strong>LRU Cache</strong> using a Python <br>Implementation:</p><pre>class Node:<br>     def __init__(self, key, value):<br>         self.key = key<br>         self.value = value<br>         self.prev = None<br>         self.next = None<br><br>class LRUCache:<br>     def __init__(self, capacity: int):<br>         self.capacity = capacity<br>         self.cache = {} # Hash map to store key -&gt; Node mapping<br>         self.head = Node(0, 0) # Dummy head node<br>         self.tail = Node(0, 0) # Dummy tail node<br>         self.head.next = self.tail<br>         self.tail.prev = self.head<br><br><br>    def _remove(self, node: Node):<br>         &quot;&quot;&quot;Remove a node from the linked list.&quot;&quot;&quot;<br>         prev_node = node.prev<br>         next_node = node.next<br>         prev_node.next = next_node<br>         next_node.prev = prev_node<br><br>    def _add_to_front(self, node: Node):<br>         &quot;&quot;&quot;Add a node to the front (right after the head) of the linked list.&quot;&quot;&quot;<br>         node.next = self.head.next<br>         node.prev = self.head<br>         self.head.next.prev = node<br>         self.head.next = node<br><br>    def get(self, key: int) -&gt; int:<br>         &quot;&quot;&quot;Get the value of the key if it exists in the cache, otherwise return -1.&quot;&quot;&quot;<br>         if key in self.cache:<br>         node = self.cache[key]<br>         self._remove(node) # Remove the node from its current position<br>         self._add_to_front(node) # Move it to the front (most recently used)<br>         return node.value<br>         return -1<br><br>    def put(self, key: int, value: int) -&gt; None:<br>         &quot;&quot;&quot;Add or update the value of the key in the cache.&quot;&quot;&quot;<br>         if key in self.cache:<br>         # If the key already exists, update its value and move it to the front<br>         node = self.cache[key]<br>         node.value = value<br>         self._remove(node)<br>         self._add_to_front(node)<br>         else:<br>         # If the key doesn&#39;t exist, create a new node and add it to the cache<br>         if len(self.cache) &gt;= self.capacity:<br>         # If the cache is full, remove the least recently used node (tail.prev)<br>         lru_node = self.tail.prev<br>         self._remove(lru_node)<br><br>     del self.cache[lru_node.key] # Remove it from the cache<br>         new_node = Node(key, value)<br>         self.cache[key] = new_node<br>         self._add_to_front(new_node)<br><br>    def __repr__(self):<br>         &quot;&quot;&quot;Helper method to visualize the cache.&quot;&quot;&quot;<br>         result = []<br>         current = self.head.next<br>         while current != self.tail:<br>         result.append(f&quot;({current.key}: {current.value})&quot;)<br>         current = current.next<br>         return &quot; -&gt; &quot;.join(result)<br><br>if __name__ == &quot;__main__&quot;:<br>    # Example usage:<br>    lru_cache = LRUCache(2)<br>    lru_cache.put(1, 1) # Cache is {1=1}<br>    lru_cache.put(2, 2) # Cache is {1=1, 2=2}<br>    print(lru_cache.get(1)) # Returns 1, Cache is {2=2, 1=1}<br>    lru_cache.put(3, 3) # LRU key was 2, evicts key 2, Cache is {1=1, 3=3}<br>    print(lru_cache.get(2)) # Returns -1 (not found)<br>    lru_cache.put(4, 4) # LRU key was 1, evicts key 1, Cache is {3=3, 4=4}<br>    print(lru_cache.get(1)) # Returns -1 (not found)<br>    print(lru_cache.get(3)) # Returns 3, Cache is {4=4, 3=3}<br>    print(lru_cache.get(4)) # Returns 4, Cache is {3=3, 4=4}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ae3e6953255" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to secure your Django application]]></title>
            <link>https://medium.com/@sagar.hande.work/how-to-secure-your-django-application-57dec771f8da?source=rss-949bb924c97a------2</link>
            <guid isPermaLink="false">https://medium.com/p/57dec771f8da</guid>
            <category><![CDATA[secret-key]]></category>
            <category><![CDATA[python-decouple]]></category>
            <category><![CDATA[django-admin]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[django-security]]></category>
            <dc:creator><![CDATA[Sagar Hande]]></dc:creator>
            <pubDate>Wed, 25 Jan 2023 06:25:03 GMT</pubDate>
            <atom:updated>2023-01-25T06:25:03.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*NhvzeXQlSmi8oQZt0Mt_QQ.png" /></figure><p>To secure your sensitive information in the Django project such as secret keys, DB credentials, and so on. We need some kind of secure way.</p><p>The <strong><em>python-decouple</em></strong><em> </em>library allows developers to store sensitive information, such as database credentials, in a secure and separate location, rather than hardcoding them in the codebase.</p><p><strong>Step-I)</strong> First things first, we need to install <strong><em>python-decouple</em></strong></p><pre>pip install python-decouple</pre><p><strong>Step-II) </strong>Then use it on your settings.py by importing as below.</p><pre>from decouple import config</pre><p><strong>Step-III) </strong>Create .env file at the root level and add secret data to it.</p><p>For example:</p><pre>SECRET_KEY=a(u*fei+lo!ipnp^itdotw(f7x&amp;29*@x+i7_*hx7hrvn*zagf@<br>EMAIL_HOST=smtp.gmail.com<br>EMAIL_PORT=587<br>DEBUG=True</pre><p><strong>Step-IV) </strong>Retrieve the configuration parameters to settings.py as below.</p><pre>SECRET_KEY = config(&#39;SECRET_KEY&#39;)<br>DEBUG = config(&#39;DEBUG&#39;, default=False, cast=bool)<br>EMAIL_HOST = config(&#39;EMAIL_HOST&#39;, default=&#39;localhost&#39;)<br>EMAIL_PORT = config(&#39;EMAIL_PORT&#39;, default=25, cast=int)</pre><p><strong>Step-V) </strong>add .env to your .ginignore file</p><p><strong>Step-VI) </strong>The last step is to secure your admin panel by changing the URL pattern so that hackers will not be able to access the page easily.</p><pre>path(&quot;admin/&quot;, admin.site.urls),</pre><p>Change the above default path to something like below</p><pre>path(&quot;admin_user_login/&quot;, admin.site.urls),</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57dec771f8da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VS Code: configure Black to format python code on file save]]></title>
            <link>https://medium.com/@sagar.hande.work/vs-code-configure-black-to-format-python-code-on-file-save-9fd4057bc98f?source=rss-949bb924c97a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fd4057bc98f</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[black]]></category>
            <category><![CDATA[format]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Sagar Hande]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 12:10:06 GMT</pubDate>
            <atom:updated>2023-01-18T12:10:06.394Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="https://pypi.org/project/black/" src="https://cdn-images-1.medium.com/max/1024/1*iwMjk9rEJ5PwsVYF2RJvBg.png" /></figure><p>First things first, we need to install the Black library using the below command. If you intend to use black for virtual env, make sure you have activated it.</p><pre>pip install black</pre><p>Go to VS code setting as shown below or simply type “ C<strong><em>trl + Comma“.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*E2TXzyIfcNuqv6F5zeHqaw.png" /></figure><p>The next step is to search below in the search bar of the settings. <strong><em>@lang:python format on save</em></strong></p><p>The below result will populate, and click on the check bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h9PyA3kym8_-Ku9w21GWxQ.png" /></figure><p>Next, search for <strong><em>python formatting provider</em></strong> and select “black” in the dropdown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_hODUtROV3RSP7gvO3WXzA.png" /></figure><p>That’s it, now, every time you save the python code it will get formatted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fd4057bc98f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>