<?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 Rohit Kumar Yadav on Medium]]></title>
        <description><![CDATA[Stories by Rohit Kumar Yadav on Medium]]></description>
        <link>https://medium.com/@rohitkuyadav2003?source=rss-d6f16edbb548------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hUxTNg5JAFOyeG-7eG97ng.jpeg</url>
            <title>Stories by Rohit Kumar Yadav on Medium</title>
            <link>https://medium.com/@rohitkuyadav2003?source=rss-d6f16edbb548------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:49:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rohitkuyadav2003/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[Stop Guessing: The Right Way to Deploy FastAPI on IIS]]></title>
            <link>https://medium.com/@rohitkuyadav2003/stop-guessing-the-right-way-to-deploy-fastapi-on-iis-d3887894ad4d?source=rss-d6f16edbb548------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3887894ad4d</guid>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[ii]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[windows-server]]></category>
            <dc:creator><![CDATA[Rohit Kumar Yadav]]></dc:creator>
            <pubDate>Tue, 24 Mar 2026 12:30:25 GMT</pubDate>
            <atom:updated>2026-03-25T04:19:10.556Z</atom:updated>
            <content:encoded><![CDATA[<p>Most of the EMS companies and others still using the Old Microsoft IIS(Internet Information Services) server. <strong>Internet Information Services (IIS)</strong> is a web server created by <strong>Microsoft</strong> to host websites, APIs, and applications on <strong>Windows servers</strong>. It’s similar to, <strong>Apache HTTP Server, Nginx. </strong>Working with IIS feels like: ‘Why is this so complicated?’ and IIS replying: ‘Because I was designed before you were born. IIS can run many technologies… but let’s be honest, it clearly has a favorite child — .NET . In this article I will guide you how you will deploy you FastAPI applicaion on IIS without being grumpy.</p><h3>Ways to Deploy FastAPI on IIS</h3><p><strong>1.</strong> <strong>Reverse Proxy (Ideal)</strong></p><ul><li>Run FastAPI with <strong>Uvicorn/Gunicorn</strong> (port like 8000/8111)</li><li>IIS acts as <strong>reverse proxy</strong> using:</li></ul><p>a. URL Rewrite</p><p>b. ARR (Application Request Routing)</p><p>Flow:</p><pre>Client → IIS → FastAPI (Uvicorn)</pre><ul><li>Best for production</li><li>Easy to manage</li><li>Most commonly used</li></ul><p><strong>2.</strong> <strong>IIS + FastCGI</strong> <strong>(Not recommended for FastAPI):</strong></p><p>Use FastCGI bridge to connect IIS with Python</p><p>Problem:</p><ul><li>Not designed for ASGI (FastAPI)</li><li>Works better for Flask/Django (WSGI)</li></ul><blockquote>We will move forward with — ‘<strong>Reverse Proxy</strong>’</blockquote><h3>Initial Setup Before we start deploying.</h3><p>You must install <strong>ARR + URL Rewrite.</strong></p><ol><li>URL Rewrite: <a href="https://www.iis.net/downloads/microsoft/url-rewrite">https://www.iis.net/downloads/microsoft/url-rewrite</a></li><li>ARR (Application Request Routing): <a href="https://www.iis.net/downloads/microsoft/application-request-routing">https://www.iis.net/downloads/microsoft/application-request-routing</a></li><li>NSSM(Non-Sucking Service Manager): <a href="https://nssm.cc/download?utm_source=chatgpt.com">https://nssm.cc/download</a></li></ol><p><strong>URL Rewrite</strong>: Change you incoming request URL.</p><p><strong>ARR</strong>: Forwards the request to another server (your FastAPI).</p><p><strong>NSSM</strong>: IT is a tool that lets you run any application (like your FastAPI/Uvicorn server) as a windows service. Even if you app crash or server restart it will keep running its like a Daemon.</p><pre>Client (Browser)<br>      ↓<br>IIS (URL Rewrite)<br>      ↓<br>IIS (ARR forwards)<br>      ↓<br>FastAPI (Uvicorn :8111)<br>      ↓<br>Response back same path</pre><h3>Deployment Steps</h3><ol><li><strong>Move you complete file at this destination</strong> — C:\inetpub\wwwroot\ . This is the common location for all the severs. Now you will add your project directory inside ‘wwwroot’. <strong>Example: C:\inetpub\wwwroot\Dashboard.</strong></li><li><strong>Create a virtual Environment:</strong></li></ol><pre>cd C:\inetpub\wwwroot\Dashboard<br>python -m venv venv<br>venv\Scripts\activate<br>pip install -r requirements.txt</pre><p>3. <strong>Test you Project it is working or not. (MANDATORY TEST)</strong></p><pre>uvicorn api:app - host 0.0.0.0 - port 8001</pre><p><strong>Then ,</strong> Test: <a href="http://localhost:8001/">http://localhost:8001</a></p><p>4. <strong>Create NSSM Service</strong></p><ul><li>Open CMD(Administrator)</li><li>Negivate to the directory where nssm is else it not works.</li><li>‘nssm install &lt;name&gt;’</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*Qx5zxrWSiFVnkb9v6WB3_w.png" /><figcaption>A simple form will appear.</figcaption></figure><p><strong>Now fill:</strong><br>1. Application Path: C:\inetpub\wwwroot\&lt;proj&gt;\venv\Scripts\python.exe<br>2. Arguments: -m uvicorn api:app — host 0.0.0.0 — port 8001<br>3. Startup Directory: C:\inetpub\wwwroot\&lt;proj&gt;</p><p>Click <strong>install service</strong>.</p><p><strong>Now,</strong></p><ul><li>Install &amp; Start<br>1. nssm start &lt;project name&gt;<br>2. nssm set &lt;project name&gt; Start SERVICE_AUTO_START</li><li>Check<br>nssm status &lt;project name&gt;</li></ul><blockquote><strong>Must show:</strong><br>SERVICE_RUNNING</blockquote><p>5.<strong> Test Backend[It must work]</strong><br> <a href="http://localhost:8001/">http://localhost:8001</a></p><p>6. <strong>Setup the IIS</strong></p><ul><li>Open IIS &gt; click on sites <strong>&gt;</strong> New site</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*Gut_7m0chvnLb7cepyeoXQ.png" /><figcaption>Fill this.</figcaption></figure><ul><li>Path: C:\inetpub\wwwroot\&lt;Projectname&gt;</li><li>Select the IP address and the port &gt; OK.</li><li>Inside You project: click <strong>URL Rewrite &gt; Add Rule &gt; click on Proxy &gt; Enable Reverse proxy.</strong></li><li>Enter: localhost:8111</li><li>Final: Restart IIS <br>&gt;&gt; iisreset</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*64206Bd_FEuqXJIIgz_bJg.png" /><figcaption>Inside you website you will see something like this.</figcaption></figure><blockquote>One more important thing. Inside your server you have to expose the port so that outside the server you can use the website. <strong>Go to windows firewall and Advanced Security&gt; Inbound Rules &gt; New rule &gt; select port then next &gt; choose specific local ports and enter your website port that you entered in the IIS.</strong></blockquote><p><strong>Hurray!! You have deployed your application.</strong></p><h3>Conclusion</h3><p>Deploying FastAPI on IIS might initially seem complicated, but using reverse proxy method with ARR and URL Rewrite, You can achieve both stability and flexibility by integrating IIS with Uvicorn and using NSSM to manage the service. With this technique, companies that already use IIS can incorporate contemporary Python APIs without having to modify their infrastructure. Even in conventional enterprise settings, FastAPI can function effectively with the right setup and testing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3887894ad4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use .env Files in Python the Right Way (Beginner to Production)]]></title>
            <link>https://medium.com/@rohitkuyadav2003/how-to-use-env-files-in-python-the-right-way-beginner-to-production-2e15228a0a6e?source=rss-d6f16edbb548------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e15228a0a6e</guid>
            <dc:creator><![CDATA[Rohit Kumar Yadav]]></dc:creator>
            <pubDate>Tue, 27 Jan 2026 05:43:55 GMT</pubDate>
            <atom:updated>2026-01-27T05:43:55.454Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Use .env Files in Python the Right Way (Beginner to Production)</h3><h3>What is a .env file?</h3><p>A .env file stores <strong>environment variables</strong> outside your code.</p><p>Need:</p><ul><li>Keeps secrets <strong>out of GitHub</strong></li><li>Easy to change configs without touching code</li><li>Used in <strong>Django, FastAPI, Flask, ML pipelines, Docker</strong></li></ul><h3><strong>How to use:</strong></h3><ol><li>Install python-dotenv</li></ol><pre>pip install python-dotenv</pre><p>2. Create a .env file</p><blockquote>Create this file in your <strong>project root</strong>.</blockquote><pre>API_KEY=sk-123456<br>DB_HOST=localhost<br>DB_PORT=5432<br>DEBUG=True<br>MODEL_PATH=models/best_model.pkl</pre><h4>Rules</h4><ul><li>No quotes needed</li><li>No spaces around =</li><li>One variable per line</li></ul><p>3. Load .env in Python</p><pre>from dotenv import load_dotenv<br>import os<br><br>load_dotenv()   # loads .env into environment<br><br>api_key = os.getenv(&quot;API_KEY&quot;)<br>db_host = os.getenv(&quot;DB_HOST&quot;)<br><br>print(api_key)<br>print(db_host)</pre><p>Now Python reads values <strong>securely</strong> from .env</p><p>4. Use .env in Real Projects</p><p>-&gt; ML project Example</p><pre>MODEL_PATH = os.getenv(&quot;MODEL_PATH&quot;)<br><br>with open(MODEL_PATH, &quot;rb&quot;) as f:<br>    model = pickle.load(f)</pre><p>-&gt; Flask / FastAPI Example</p><pre>DEBUG = os.getenv(&quot;DEBUG&quot;) == &quot;True&quot;</pre><p>-&gt; Database Connection Example</p><pre>DB_URL = f&quot;postgresql://{os.getenv(&#39;DB_USER&#39;)}:{os.getenv(&#39;DB_PASS&#39;)}@{os.getenv(&#39;DB_HOST&#39;)}/{os.getenv(&#39;DB_NAME&#39;)}&quot;</pre><p>5. Add .env to .gitignore<strong> (VERY IMPORTANT )</strong></p><pre>.env</pre><blockquote>This ensures secrets never go to GitHub.</blockquote><p><strong>Project Structure</strong></p><pre>project/<br>│── src/<br>│── models/<br>│── .env<br>│── .gitignore<br>│── requirements.txt<br>│── main.py</pre><h3><strong>Using GitHub Secrets in GitHub Actions for Secure CI/CD</strong></h3><ol><li>Go to <strong>GitHub Repo(In your project)</strong></li><li><strong>Settings → Secrets and variables → Actions</strong></li></ol><p>3. Click <strong>New repository secret</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*VcEA_x4QyDPPDcYhene-wA.png" /><figcaption>Paste the secret name and the Secret without any Quotation, create multiple if you have multiple secret keys</figcaption></figure><h3><strong>Summary</strong></h3><p>In this article, we explored how to use .env files in Python, why they should never be committed to GitHub, and how GitHub Secrets help manage sensitive configuration securely in CI/CD workflows.</p><p><strong>The key takeaway is simple: never hardcode secrets, never push them to GitHub, and always inject them at runtime.</strong></p><p>This setup is what I personally use in real-world Python, machine learning, and backend projects because it scales cleanly from local development to production.</p><p>If you found this helpful, feel free to clap , share it with other developers, or follow me for more practical content on Python, Git, and real-world software engineering.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e15228a0a6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git and GitHub Made Easy: A Simple Guide from Beginner to Advanced (Part -I)]]></title>
            <link>https://medium.com/@rohitkuyadav2003/git-and-github-made-easy-a-simple-guide-from-beginner-to-advanced-part-i-5b8e095ff1cd?source=rss-d6f16edbb548------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b8e095ff1cd</guid>
            <dc:creator><![CDATA[Rohit Kumar Yadav]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 15:43:14 GMT</pubDate>
            <atom:updated>2025-03-31T15:43:14.195Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Git?</h3><p>Git is a version control system used to track changes, go back to older versions, and work with others without messing things up. It is free and open-source and works on OS like Windows, Mac, and Linux. Think of it as a time machine for your projects.<br>- Git is a software (Tool)<em> </em>you can install on your computer.<br>- Tool for tracking changes.</p><h3>What is Github?</h3><p>It’s a website that uses Git. It lets you store your files online, share them with others, and collaborate on projects. Think of it as “cloud storage”- an Online platform to store and share git projects</p><h3>What is Version Control?</h3><p>Used to manage the history of your code. They allow you to track changes to your files and to collaborate with others.<br>- It’s like a checkpoint in games</p><h3>Basic Git workflow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/0*LmiP9PSHpSTdlGGj" /><figcaption>simple workflow</figcaption></figure><h3>Repository</h3><p>A Repository is a collection of files and directories (folders) that are stored together. It is a way to store and manage the code.<br><strong>-</strong> Simply, a repository is like a folder on your computer, but it is more than just a folder.</p><h3>Here’s a comparison of common terms in Git/GitHub vs. general usage:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*jKskObHeB4cFgaHSn9xgvA.png" /></figure><p><strong>CODE:<br></strong>To check the git version:</p><pre>git --version</pre><h3>Initial Setups</h3><ul><li>Adding name and email</li></ul><pre>git config --global user.name &quot;yourname&quot;<br>git config --global user.email &quot;yourmail@example.com&quot;</pre><ul><li>To check configuration settings</li></ul><pre>git config - list</pre><ul><li>To edit the change</li></ul><pre># For windows<br>code C:\Users\YourUsername\.gitconfig<br>notepad C:\Users\YourUsername\.gitconfig<br># For Linux and Mac<br>nano ~/.gitconfig # for Linux and mac<br>code ~/.gitconfig # opening in vscode</pre><ul><li>To change the “default Editor”</li></ul><pre>git config --local core.editor &quot;editor_command&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*l79CaGizZv2N5nVdgIvGow.png" /><figcaption><strong>Examples for Different Editors</strong></figcaption></figure><h3>Types of Configuration Levels</h3><p><strong>1. Local Configuration (</strong><strong>--local)</strong></p><ul><li><strong>Scope</strong>: This applies only to a specific repository.</li><li><strong>Storage</strong>: Saved inside the .git/config file of that particular repository.</li><li><strong>Command</strong>:</li></ul><pre>git config --local key value<br># Example<br>git config --local user.name &quot;yourname&quot;</pre><p><strong>2. Global Configuration (</strong><strong>--global)</strong></p><ul><li><strong>Scope</strong>: This applies to all repositories for the current user.</li><li><strong>Storage</strong>: Saved inside ~/.gitconfig (Linux/macOS) or C:\Users\YourUser\.gitconfig (Windows).</li><li><strong>Command</strong>:</li></ul><pre>git config --local key value<br># Example<br>git config --local user.name &quot;yourname&quot;</pre><p><strong>3. System Configuration (</strong><strong>--system)</strong></p><ul><li><strong>Scope</strong>: This applies to all users and repositories on the system (requires admin/root access).</li><li><strong>Storage</strong>: Saved inside /etc/gitconfig (Linux/macOS) or C:\ProgramData\Git\config (Windows).</li><li><strong>Command</strong>:<br><em>NOTE: It requires admin permission.</em></li></ul><pre>git config --system key value<br># Example<br>git config --system user.name &quot;yourname&quot;</pre><h3>Getting started with Git.</h3><ol><li>Creating a repository is the process of creating a new folder on your system and initializing it as a git repo. It&#39;s just a regular folder to code your project, you are just asking git to track it.</li></ol><p>To do so:</p><pre>git init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*nbu6zBUb6Qd0L6tIYe208w.png" /><figcaption>This is how it looks when you initialize the repo.</figcaption></figure><p>COMPLETE GIT FLOW:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*-zGJfIjXWH5Tkabd5vazKg.png" /><figcaption>Complete Flow</figcaption></figure><h4>After Initialization The Next step is:</h4><pre># create new file.. Example<br>echo this is file 1 &gt;&gt; file1.txt<br>echo this is file 2 &gt;&gt; file2.txt<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*Vk_yoYgZyHvTAdBoxpm63w.png" /><figcaption>After running the command.</figcaption></figure><p><strong>To check the status of repo:</strong></p><pre>git status</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*i-oJoIZ2DzwceaJNPqF66Q.png" /><figcaption>It tells that the file is <strong>added the to staging area</strong> and <strong>next you have to add it to the commit</strong> after reviewing the changes that you have made.</figcaption></figure><h3>Stage:</h3><p>Stage is a way to tell git to track a particular file or folder.</p><pre># After the files has been created than <br>git add file1.txt file2.txt<br># or you can use<br>git add .<br><br># This command add the file in the staging area</pre><h3><strong>Now Commit:</strong></h3><pre># To review the changes before commiting<br>git diff --staged</pre><pre>git commit -m &quot;commit message&quot;<br>git status</pre><p>Here, we are committing the changes to the repository. We can see that the changes have been committed to the repository. The -m flag is used to add a message to the commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*LZ5lN4hb7gZ4rB7M61-8Cg.png" /><figcaption>Sample code</figcaption></figure><blockquote>NOTE: git add *.txt # to add all the files end with .txt</blockquote><pre># How to remove the file from staging area<br> git rm --cached filename<br><br># To undo the removed file<br>git restore --staged filename<br><br>#* TO view the file in staging area<br>git ls-files<br><br># Discard the changes in working Directory<br>git restore filename<br><br># If you want to remove the file from both working dir and staging area<br>git rm filename</pre><blockquote>NOTE: if you want to directly commit the changes without staging them use :<br>git commit -a -m “commit message”</blockquote><h3><strong>Logs:</strong></h3><p>This is one of the important commands that shows you the history of the code.</p><pre># For detailed history<br>git log <br><br># To get the History in oneline<br>git log --oneline<br><br># To get the commit added details use<br>git log --oneline --stat<br># or<br>git log --oneline --patch<br><br># To get the specific changes<br>git show &lt;log id&gt;<br><br># searching by name<br>gir log --author=&quot;author name&quot;<br><br># searching by commit message<br>git log --grep=&quot;commit message keyword&quot;<br><br># Using date format(YYYY-MM-DD)<br>git log --since=&quot;2024-01-01&quot;<br>git log --until=&quot;2023-01-01&quot;<br>git log --since=&quot;2012-01-21&quot; --until=&quot;2024-01-12&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*xybl0vBZv2qF4D-AtJEwwA.png" /><figcaption>Sample code</figcaption></figure><p><strong>Part 2 soon<em>…</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b8e095ff1cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Python Virtual Environments Like a Pro]]></title>
            <link>https://medium.com/@rohitkuyadav2003/working-on-virtual-environment-in-python-22cfc11ae487?source=rss-d6f16edbb548------2</link>
            <guid isPermaLink="false">https://medium.com/p/22cfc11ae487</guid>
            <dc:creator><![CDATA[Rohit Kumar Yadav]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 09:56:29 GMT</pubDate>
            <atom:updated>2026-01-11T09:24:25.744Z</atom:updated>
            <content:encoded><![CDATA[<p>A virtual environment is a separate space for a Python project that keeps its dependencies isolated</p><h4><strong>Why we use virtual environment in python?</strong></h4><p>Think of Python as a house. Every project has its own room (a virtual environment). In that room are only the tools it needs, not any it doesn’t. This keeps projects isolated from each other.</p><h4><strong>Problems without Virtual Environments:</strong></h4><ol><li><strong>Package version conflicts</strong> — One project may require an older library version while another needs a newer one, causing errors.</li><li><strong>Projects break unexpectedly</strong> — Installing or upgrading a package for one project can silently break others.</li><li><strong>No project isolation</strong> — All projects share the same global Python environment, making debugging difficult.</li><li><strong>Hard to reproduce projects</strong> — It becomes difficult to recreate the exact setup on another system or server.</li></ol><h4><strong>Benefits of Virtual Environments:</strong></h4><ol><li><strong>Dependency isolation</strong> — Each project uses its own libraries and versions without conflicts.</li><li><strong>Project stability</strong> — Changes in one project do not break others.</li><li><strong>Easy reproducibility</strong> — Projects can be recreated easily on another system using the same dependencies.</li><li><strong>Clean system Python</strong> — Keeps the global Python installation safe and uncluttered.</li></ol><h3><strong>Creating Virtual Environment:</strong></h3><h4>1. <strong>venv (Built-in Python Virtual Environment)</strong></h4><p>venv is the <strong>official, built-in</strong> Python virtual environment tool available with Python 3.3+.</p><h4>When to Use</h4><ul><li>Beginners and students</li><li>Machine Learning &amp; Data Science projects</li><li>Backend development (Django, FastAPI)</li><li>Research &amp; production environments</li><li>When you want <strong>lightweight, no extra installs</strong></li></ul><h4>OS Support</h4><p>. Windows<br> . macOS<br> . Linux</p><p><strong>Commands :</strong></p><pre>python -m venv venv  # You can rename venv to anything (e.g., env, myenv)</pre><ul><li>Activate Environment</li></ul><pre>venv\Scripts\activate    # to activate # For Windows<br><br>source venv/bin/activate # For MacOS / Linux</pre><ul><li>Check Active Environment</li></ul><pre>which python        # macOS / Linux<br>where python        # Windows</pre><ul><li>Deactivate Environment</li></ul><pre>deactivate</pre><ul><li>Delete Environment</li></ul><pre>rm -rf venv        # macOS / Linux<br>rmdir /s venv      # Windows</pre><h4>Limitations</h4><ul><li>Cannot manage <strong>multiple Python versions</strong></li><li>No built-in dependency lock file</li><li>Manual activation required</li></ul><h4>2. virtualenv (External but Very Popular)</h4><p>virtualenv is an older but powerful alternative that works even with <strong>older Python versions</strong> and creates environments faster.</p><h4>When to Use</h4><ul><li>When Python version &lt; 3.3</li><li>Legacy systems</li><li>When faster environment creation is needed</li><li>CI/CD pipelines</li></ul><h4>OS Support</h4><p>. Windows<br> . macOS<br> . Linux</p><h4>Commands</h4><pre>pip install virtualenv # to install</pre><ul><li>Create Environment</li></ul><pre>virtualenv venv</pre><ul><li>Activate</li></ul><p>Same as venv:</p><pre>venv\Scripts\activate # Windows<br><br>source venv/bin/activate # macOS / Linux</pre><ul><li>Check Environment</li></ul><pre>pip list</pre><h4>Limitations</h4><ul><li>External dependency (extra install)</li><li>Mostly replaced by venv</li><li>No Python version management</li></ul><h4>3. Conda (Anaconda / Miniconda) [ Recommended]</h4><p>Conda is both a <strong>package manager and environment manager</strong>, widely used in <strong>Data Science and ML</strong>.</p><h4>When to Use</h4><ul><li>Heavy ML / Deep Learning projects</li><li>CUDA, PyTorch, TensorFlow setups</li><li>When non-Python dependencies are needed</li><li>Research environments</li></ul><h4>OS Support</h4><p>. Windows<br> . macOS<br> . Linux</p><h4>Commands</h4><ul><li>Create Environment</li></ul><pre>conda create -n myenv python=3.10 </pre><ul><li>Activate</li></ul><pre>conda activate myenv</pre><ul><li>List Environments</li></ul><pre>conda env list<br># or <br>conda info --envs</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*ZuXCCLI3p0wPduGe_ATI0A.png" /><figcaption>List of the Environments.</figcaption></figure><ul><li>Switch Environment</li></ul><pre>conda activate another_env</pre><ul><li>Install Packages</li></ul><pre>conda install numpy pandas<br><br># or<br>pip install &lt;package name&gt;</pre><blockquote><strong>NOTE</strong>: You can install package using <strong>conda</strong> or <strong>pip</strong> but make sure you are in the desired environment.</blockquote><ul><li>Deactivate</li></ul><pre>conda deactivate</pre><ul><li>Delete Environment</li></ul><pre>conda remove -n myenv --all</pre><ul><li>Check the size of the Environment [For <strong>Linux</strong> only]</li></ul><pre>du -sh ~/miniconda3/envs/* <br># or <br>du -sh ~/anaconda3/envs/*</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*FsUWbM2mT6MGrRCqcjENZw.png" /><figcaption><strong>Total disk space used by your entire Miniconda installation</strong>.</figcaption></figure><h4>Limitations</h4><ul><li>Heavy disk usage</li><li>Slower startup</li><li>Overkill for simple projects</li><li>Can conflict with pip if misused</li></ul><h3>Final Recommendation (Industry-Friendly)</h3><blockquote><strong><em>Use </em></strong><strong><em>venv for 80% of projects</em></strong><em><br> </em><strong><em>Use Conda only for heavy ML / CUDA-based work</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22cfc11ae487" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Hotword Detection with Porcupine and Python]]></title>
            <link>https://medium.com/@rohitkuyadav2003/building-a-hotword-detection-with-porcupine-and-python-f95de3b8278d?source=rss-d6f16edbb548------2</link>
            <guid isPermaLink="false">https://medium.com/p/f95de3b8278d</guid>
            <dc:creator><![CDATA[Rohit Kumar Yadav]]></dc:creator>
            <pubDate>Sat, 25 Nov 2023 05:50:08 GMT</pubDate>
            <atom:updated>2024-10-06T09:10:14.057Z</atom:updated>
            <content:encoded><![CDATA[<p>In the realm of modern technology, voice-controlled applications have emerged as an integral component of our digital landscape. Propelled by the widespread adoption of virtual assistants such as Jarvis, Siri, and Alexa, users have become accustomed to seamless interactions with their devices through spoken commands. At the core of these sophisticated applications lies a critical functionality — Hotword detection. This essential feature serves as the catalyst, prompting the system to actively listen and respond, creating a dynamic and intuitive user experience.</p><p>In this article, we embark on a journey to delve into the intricacies of Hotword detection systems, with a focus on implementation using the Porcupine library and the versatile programming language, Python. Developed by Picovoice, Porcupine stands out as a lightweight, real-time Hotword detection engine meticulously crafted to operate with exceptional efficiency across a spectrum of platforms.</p><p>As we navigate through the technical landscape of voice-controlled applications, the subsequent sections will provide a comprehensive guide on harnessing the power of Porcupine, enabling developers to integrate robust Hotword detection seamlessly into their projects. Join us as we unravel the intricacies of this innovative solution, poised to elevate the capabilities of voice-controlled applications to new heights.</p><h3>Platforms</h3><ul><li>Linux (x86_64)</li><li>macOS (x86_64, arm64)</li><li>Windows (x86_64)</li><li>BeagleBone</li><li>NVIDIA Jetson Nano</li><li>Raspberry Pi (Zero, 2, 3, 4)</li></ul><h3>Custom Keywords</h3><p>Create custom keywords using the <a href="https://console.picovoice.ai/">Picovoice Console</a></p><p>. Download the custom wake word file (.ppn) and create an instance of Porcupine using the keyword_paths input argument</p><pre>porcupine = pvporcupine.create(<br>  access_key=&#39;${ACCESS_KEY}&#39;,<br>  keyword_paths=[&#39;${KEYWORD_FILE_PATH}&#39;]<br>)<br><br></pre><ul><li>Python 3</li><li>PIP</li></ul><p><strong>Setting Up Porcupine</strong></p><p>Installation of the Porcupine library.</p><blockquote>pip install pvporcupine</blockquote><p>Installation of the PyAudio library for audio input.</p><p><em>pip install pyaudio</em></p><blockquote>1. <strong>Importing Libraries:</strong></blockquote><pre>import struct # Module for handling binary data<br>import pyaudio # Module for audio input/output<br>import pvporcupine # Porcupine hotword detection engine</pre><p>2.<strong>Setting Up Access key of Porcupine</strong></p><pre>access_key = &quot;&quot;<br># Initializing Porcupine with access key and wake word (&quot;jarvis&quot; in this case)<br>porcupine = pvporcupine.create(access_key=access_key, keywords=[&quot;jarvis&quot;, &quot;jarvis&quot;])</pre><p>3. <strong>Audio Stream Configuration:</strong>This code uses the PyAudio library to set up an audio stream for the Porcupine Hotword detection engine. The PyAudio library is employed to handle audio-related tasks. The configured audio stream has specific settings, such as sample rate, number of channels, format, and frames per buffer, ensuring compatibility with Porcupine’s requirements. This stream is designed for input (recording) and is ready to capture audio data for Hotword detection by Porcupine.</p><pre># Configuring the audio stream using PyAudio<br>paud = pyaudio.PyAudio()<br>audio_stream = paud.open(rate=porcupine.sample_rate, channels=1, format=pyaudio.paInt16, input=True,<br>frames_per_buffer=porcupine.frame_length)</pre><p>4.<strong>. Hotword Detection Loop:</strong>In summary, this code continually reads and processes audio data from the stream, checks if a specific Hotword is detected, and prints a message when the Hotword is recognized. This is a simplified example of how you might integrate Porcupine’s Hotword detection into a real-time audio processing system.</p><pre>while True:<br>  # Reading audio data from the stream<br>  keyword = audio_stream.read(porcupine.frame_length)<br>  keyword = struct.unpack_from(&quot;h&quot; * porcupine.frame_length, keyword)<br>  # Processing audio data using Porcupine<br>  keyword_index = porcupine.process(keyword)<br>  # Checking if a hotword is detected<br>  if keyword_index &gt;= 0:<br>    print(&quot;Hotword detected&quot;)</pre><p><strong>5. Cleanup:</strong>In the `finally` block:</p><p>- **Porcupine Cleanup:**<br> — `porcupine.delete()`: Releases resources associated with the Porcupine engine.</p><p>- **Audio Stream Cleanup:**<br> — `audio_stream.close()`: Closes the audio stream, ensuring proper resource release.</p><p>- **PyAudio Cleanup:**<br> — `paud.terminate()`: Terminates the PyAudio instance, freeing up any resources it holds.</p><p>This block is crucial for resource management, ensuring that all resources used in the script are properly released, whether or not an exception occurred during the execution.</p><pre>finally:<br># Ensuring proper release of resources<br>  if porcupine is not None:<br>    porcupine.delete()<br>  if audio_stream is not None:<br>    audio_stream.close()<br>  if paud is not None:<br>    paud.terminate()</pre><h4><strong>Here is the complete code:</strong></h4><pre>import struct<br>import pyaudio<br>import pvporcupine<br>porcupine=None<br>paud=None<br>audio_stream=None<br>try:<br>    porcupine=pvporcupine.create(access_key=access_key, keywords=[&quot;jarvis&quot;,&quot;jarvis&quot;]) <br>    paud=pyaudio.PyAudio()<br>    audio_stream=paud.open(rate=porcupine.sample_rate,channels=1,format=pyaudio.paInt16,input=True,frames_per_buffer=porcupine.frame_length)<br>    while True:<br>        keyword=audio_stream.read(porcupine.frame_length)<br>        keyword=struct.unpack_from(&quot;h&quot;*porcupine.frame_length,keyword)<br>        keyword_index=porcupine.process(keyword)<br>        if keyword_index&gt;=0:<br>            print(&quot;hotword detected&quot;)<br><br>finally:<br>    if porcupine is not None:<br>        porcupine.delete()<br>    if audio_stream is not None:<br>        audio_stream.close()<br>    if paud is not None:<br>        paud.terminate()</pre><blockquote><strong>You can also visit my PyPI page for a streamlined installation of the package, which is the recommended method to get this module up and running:</strong></blockquote><p><a href="https://pypi.org/project/pico-hwd-detection/">pico-hwd-detection</a></p><p>Here is the Demo of this project:</p><p><a href="https://drive.google.com/file/d/1J4vUXl7m8mR-eOGYUXjvR2VanAASx47R/view?usp=drive_link">https://drive.google.com/file/d/1J4vUXl7m8mR-eOGYUXjvR2VanAASx47R/view?usp=drive_link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f95de3b8278d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>