<?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 Pranshu Shah on Medium]]></title>
        <description><![CDATA[Stories by Pranshu Shah on Medium]]></description>
        <link>https://medium.com/@shahpranshu27?source=rss-b7fc77dbaf96------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OF2k7FjMbX3h9Z1Q</url>
            <title>Stories by Pranshu Shah on Medium</title>
            <link>https://medium.com/@shahpranshu27?source=rss-b7fc77dbaf96------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:58:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shahpranshu27/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[Connecting FastAPI to a Database Using PostgreSQL and SQLModel (Beginner-Friendly Guide)]]></title>
            <link>https://medium.com/@shahpranshu27/connecting-fastapi-to-a-database-using-postgresql-and-sqlmodel-beginner-friendly-guide-52b5aabe6ac3?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/52b5aabe6ac3</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 04:57:18 GMT</pubDate>
            <atom:updated>2025-12-26T04:57:18.999Z</atom:updated>
            <content:encoded><![CDATA[<p>Up until now, we’ve built FastAPI applications using in-memory data. That’s great for learning, but in real-world applications, <strong>PostgreSQL</strong> is one of the most commonly used databases.</p><p>In this blog, we’ll connect <strong>FastAPI</strong> to <strong>PostgreSQL</strong> using <strong>SQLModel</strong>, keeping everything beginner-friendly and easy to follow.</p><p>If you’re already working with PostgreSQL, this guide will fit perfectly into your learning journey.</p><h3>Why PostgreSQL?</h3><p>PostgreSQL is widely used because it is:</p><ul><li>Reliable and production-ready</li><li>Highly scalable</li><li>Open-source</li><li>Great for complex queries and large applications</li></ul><p>Most backend jobs and real projects use PostgreSQL, so learning it early is a smart move.</p><h3>What Is SQLModel?</h3><p><strong>SQLModel</strong> is built by the creator of FastAPI and combines:</p><ul><li>SQLAlchemy (database ORM)</li><li>Pydantic (data validation)</li><li>Python type hints</li></ul><p>This means:</p><ul><li>One model for database + validation</li><li>Cleaner code</li><li>Less boilerplate</li></ul><p>If you already understand FastAPI and Pydantic, SQLModel feels very natural.</p><h3>Step 1: Install Required Packages</h3><p>First, install the required dependencies:</p><pre>pip install fastapi uvicorn sqlmodel psycopg2-binary</pre><p>psycopg2-binary is the PostgreSQL driver that allows Python to talk to PostgreSQL.</p><h3>Step 2: Create a PostgreSQL Database</h3><p>Make sure PostgreSQL is running, then create a database:</p><pre>CREATE DATABASE fastapi_db;</pre><p>You’ll also need:</p><ul><li>Database name</li><li>Username</li><li>Password</li></ul><p>We’ll use these in the connection string.</p><h3>Step 3: Project Setup</h3><p>Create a file:</p><pre>main.py</pre><h3>Step 4: Create the Database Engine</h3><p>Now let’s connect FastAPI to PostgreSQL.</p><pre>from sqlmodel import SQLModel, create_engine</pre><pre>DATABASE_URL = &quot;postgresql://username:password@localhost:5432/fastapi_db&quot;</pre><pre>engine = create_engine(DATABASE_URL, echo=True)</pre><p>👉 Replace username, password, and fastapi_db with your actual credentials.</p><p>echo=True logs SQL queries in the terminal (great for learning).</p><h3>Step 5: Create a Database Model</h3><p>Let’s define a simple Item table.</p><pre>from typing import Optional<br>from sqlmodel import SQLModel, Field</pre><pre>class Item(SQLModel, table=True):<br>    id: Optional[int] = Field(default=None, primary_key=True)<br>    name: str<br>    price: float</pre><p>This single model:</p><ul><li>Defines a PostgreSQL table</li><li>Validates incoming requests</li><li>Controls API responses</li></ul><p>That’s the real power of SQLModel.</p><h3>Step 6: Create Database Tables</h3><p>Before using the database, we need to create tables.</p><pre>def create_db_and_tables():<br>    SQLModel.metadata.create_all(engine)</pre><h3>Step 7: Create the FastAPI App</h3><pre>from fastapi import FastAPI</pre><pre>app = FastAPI()</pre><pre>@app.on_event(&quot;startup&quot;)<br>def on_startup():<br>    create_db_and_tables()</pre><p>Now tables will be created automatically when the app starts.</p><h3>Step 8: Create (POST) Item</h3><pre>from sqlmodel import Session</pre><pre>@app.post(&quot;/items&quot;)<br>def create_item(item: Item):<br>    with Session(engine) as session:<br>        session.add(item)<br>        session.commit()<br>        session.refresh(item)<br>        return item</pre><p>This saves data directly into PostgreSQL.</p><h3>Step 9: Read All Items</h3><pre>from sqlmodel import select</pre><pre>@app.get(&quot;/items&quot;)<br>def read_items():<br>    with Session(engine) as session:<br>        items = session.exec(select(Item)).all()<br>        return items</pre><h3>Step 10: Read a Single Item</h3><pre>from fastapi import HTTPException</pre><pre>@app.get(&quot;/items/{item_id}&quot;)<br>def read_item(item_id: int):<br>    with Session(engine) as session:<br>        item = session.get(Item, item_id)<br>        if not item:<br>            raise HTTPException(status_code=404, detail=&quot;Item not found&quot;)<br>        return item</pre><h3>Step 11: Update an Item</h3><pre>@app.put(&quot;/items/{item_id}&quot;)<br>def update_item(item_id: int, updated_item: Item):<br>    with Session(engine) as session:<br>        item = session.get(Item, item_id)<br>        if not item:<br>            raise HTTPException(status_code=404, detail=&quot;Item not found&quot;)</pre><pre>        item.name = updated_item.name<br>        item.price = updated_item.price</pre><pre>        session.add(item)<br>        session.commit()<br>        session.refresh(item)<br>        return item</pre><h3>Step 12: Delete an Item</h3><pre>@app.delete(&quot;/items/{item_id}&quot;)<br>def delete_item(item_id: int):<br>    with Session(engine) as session:<br>        item = session.get(Item, item_id)<br>        if not item:<br>            raise HTTPException(status_code=404, detail=&quot;Item not found&quot;)</pre><pre>        session.delete(item)<br>        session.commit()<br>        return {&quot;message&quot;: &quot;Item deleted successfully&quot;}</pre><h3>Step 13: Run the Application</h3><pre>uvicorn main:app --reload</pre><p>Open:</p><ul><li><strong>API</strong> → <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a></li><li><strong>Docs</strong> → <a href="http://127.0.0.1:8000/docs">http://127.0.0.1:8000/docs</a></li></ul><p>Test everything using Swagger UI.</p><h3>What You’ve Built</h3><p>You’ve now:</p><ul><li>Connected FastAPI to PostgreSQL</li><li>Used SQLModel as an ORM</li><li>Built full CRUD with real persistence</li><li>Written clean, production-style backend code</li></ul><p>This is a <strong>huge step forward</strong>.</p><h3>What Should You Learn Next?</h3><p>Now that PostgreSQL is in place, the best next topics are:</p><ul><li>Project structure &amp; routers</li><li>Environment variables (.env)</li><li>Authentication with JWT</li><li>Database migrations (Alembic)</li><li>Testing FastAPI apps</li><li>Deployment</li></ul><p>Each of these builds on what you’ve just done.</p><h3>Final Thoughts</h3><p>Working with PostgreSQL may feel intimidating at first, but SQLModel makes it surprisingly approachable, especially if you already know FastAPI.</p><p>If you understand this blog, you’re officially working with <strong>real-world backend architecture</strong>.</p><p>Keep building!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52b5aabe6ac3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Pydantic in FastAPI: Request & Response Validation for Beginners]]></title>
            <link>https://medium.com/@shahpranshu27/understanding-pydantic-in-fastapi-request-response-validation-for-beginners-d96e7ebc9b58?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/d96e7ebc9b58</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 04:39:58 GMT</pubDate>
            <atom:updated>2025-12-26T04:39:58.710Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve built a basic FastAPI app or a CRUD API, you’ve already used <strong>Pydantic, </strong>even if you didn’t fully realize it.</p><p>You probably wrote something like this:</p><pre>class Item(BaseModel):<br>    name: str<br>    price: float</pre><p>And magically, FastAPI started validating your requests.</p><p>In this blog, I’ll slow things down and <strong>really understand what Pydantic does</strong>, why it’s so powerful, and how FastAPI uses it behind the scenes to keep your APIs clean and safe.</p><p>No complicated theory. Just practical examples.</p><h3>What Is Pydantic?</h3><p><strong>Pydantic</strong> is a Python library used for:</p><ul><li>Data validation</li><li>Data parsing</li><li>Type checking</li></ul><p>FastAPI uses Pydantic to:</p><ul><li>Validate incoming request data</li><li>Convert data into correct Python types</li><li>Return structured responses</li><li>Show helpful error messages automatically</li></ul><p>In simple words:<br><em>Pydantic makes sure the data entering and leaving your API is exactly what you expect.</em></p><h3>Why FastAPI Loves Pydantic</h3><p>FastAPI combines:</p><ul><li><strong>Type hints</strong></li><li><strong>Pydantic models</strong></li><li><strong>Automatic validation</strong></li></ul><p>This gives you:</p><ul><li>Fewer bugs</li><li>Cleaner code</li><li>Better developer experience</li><li>Free API documentation</li></ul><p>And you don’t have to write validation logic manually.</p><h3>Basic Pydantic Model</h3><p>Let’s start simple.</p><pre>from pydantic import BaseModel</pre><pre>class User(BaseModel):<br>    name: str<br>    age: int</pre><p>This model means:</p><ul><li>name must be a string</li><li>age must be an integer</li></ul><p>If the input doesn’t match this, FastAPI will reject the request automatically.</p><h3>Request Body Validation in FastAPI</h3><p>Now let’s use this model in FastAPI.</p><pre>from fastapi import FastAPI<br>from pydantic import BaseModel</pre><pre>app = FastAPI()</pre><pre>class User(BaseModel):<br>    name: str<br>    age: int</pre><pre>@app.post(&quot;/users&quot;)<br>def create_user(user: User):<br>    return user</pre><h3>Valid Request</h3><pre>{<br>  &quot;name&quot;: &quot;Pranshu&quot;,<br>  &quot;age&quot;: 22<br>}</pre><h3>Invalid Request</h3><pre>{<br>  &quot;name&quot;: &quot;Pranshu&quot;,<br>  &quot;age&quot;: &quot;twenty&quot;<br>}</pre><p>FastAPI responds with a <strong>clear error message</strong> explaining exactly what went wrong.</p><p>No extra code required.</p><h3>Automatic Type Conversion</h3><p>Pydantic is smart.</p><pre>{<br>  &quot;name&quot;: &quot;Alex&quot;,<br>  &quot;age&quot;: &quot;25&quot;<br>}</pre><p>Even though &quot;25&quot; is a string, Pydantic converts it into an integer if possible.</p><p>This saves you from writing manual parsing logic.</p><h3>Optional Fields</h3><p>Sometimes fields shouldn’t be required.</p><pre>from typing import Optional</pre><pre>class User(BaseModel):<br>    name: str<br>    age: Optional[int] = None</pre><p>Now:</p><ul><li>name is required</li><li>age is optional</li></ul><p>This is extremely useful for update APIs.</p><h3>Default Values</h3><p>You can also assign default values.</p><pre>class User(BaseModel):<br>    name: str<br>    is_active: bool = True</pre><p>If the client doesn’t send is_active, it automatically becomes True.</p><h3>Response Models (Very Important)</h3><p>Pydantic isn’t only for requests — it’s also for <strong>responses</strong>.</p><pre>class UserResponse(BaseModel):<br>    name: str</pre><pre>@app.post(&quot;/users&quot;, response_model=UserResponse)<br>def create_user(user: User):<br>    return user</pre><p>Even if the user sends extra data, FastAPI only returns what you define.</p><p>This is <strong>great for security</strong>, especially when working with passwords or tokens.</p><h3>Validation Errors (Readable &amp; Helpful)</h3><p>One of the best things about FastAPI + Pydantic is the error messages.</p><p>Instead of vague errors, you get:</p><ul><li>Field name</li><li>Error type</li><li>Exact location</li></ul><p>This helps both developers and API consumers.</p><h3>How This Shows Up in Swagger Docs</h3><p>Every Pydantic model automatically appears in:</p><p>/docs (Swagger UI)</p><p>Your API docs become:</p><ul><li>Interactive</li><li>Self-explanatory</li><li>Easy to test</li></ul><p>This is something most frameworks don’t give for free.</p><h3>Why Beginners Should Care</h3><p>Understanding Pydantic early will help you:</p><ul><li>Write safer APIs</li><li>Avoid unexpected bugs</li><li>Build scalable backend systems</li><li>Read other FastAPI projects confidently</li></ul><p>Once this clicks, FastAPI feels <em>much easier</em>.</p><h3>What’s Next?</h3><p>Now that you understand Pydantic, the natural next steps are:</p><ul><li>Connecting FastAPI to a real database</li><li>Structuring larger FastAPI projects</li><li>Adding authentication (JWT)</li><li>Writing tests</li></ul><p>Pydantic will continue to be used everywhere.</p><h3>Final Thoughts</h3><p>FastAPI feels magical at first, but Pydantic is a big reason why.</p><p>Once you understand how request and response validation works, you stop guessing and start building with confidence.</p><p>If you’re learning FastAPI step by step, you’re absolutely on the right track.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d96e7ebc9b58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Your First CRUD App in FastAPI (Beginner-Friendly Guide)]]></title>
            <link>https://medium.com/@shahpranshu27/building-your-first-crud-app-in-fastapi-beginner-friendly-guide-3481e19d6e0a?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/3481e19d6e0a</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Fri, 12 Dec 2025 13:12:53 GMT</pubDate>
            <atom:updated>2025-12-12T13:12:53.841Z</atom:updated>
            <content:encoded><![CDATA[<p>Now that you’ve set up FastAPI, it’s time to build something real.<br>In this tutorial, we’ll create a simple <strong>CRUD API, </strong>the foundation of nearly every backend application.</p><p>CRUD stands for:</p><ul><li><strong>C</strong>reate</li><li><strong>R</strong>ead</li><li><strong>U</strong>pdate</li><li><strong>D</strong>elete</li></ul><p>We’ll use an in-memory list (no database yet), keeping everything simple and easy to understand.</p><p>Let’s get started!</p><h3>What We’re Building</h3><p>A small API to manage a list of items.<br>Each item will have:</p><pre>{<br>  &quot;id&quot;: 1,<br>  &quot;name&quot;: &quot;Sample Item&quot;,<br>  &quot;price&quot;: 10.99<br>}</pre><p>You’ll be able to:</p><ul><li>Add new items</li><li>View all items</li><li>Get a single item</li><li>Update an item</li><li>Delete an item</li></ul><p>Exactly what a classic CRUD app does.</p><h3>Step 1: Create Your Project Files</h3><p>Inside your project, create a file:</p><pre>crud_app.py</pre><p>Install FastAPI and Uvicorn if you haven’t already:</p><pre>pip install fastapi uvicorn</pre><h3>Step 2: Create a Pydantic Model</h3><p>We use <strong>Pydantic</strong> to define how our data should look.</p><p>Add this to crud_app.py:</p><pre>from fastapi import FastAPI, HTTPException<br>from pydantic import BaseModel</pre><pre>app = FastAPI()</pre><pre>class Item(BaseModel):<br>    name: str<br>    price: float</pre><p>This helps FastAPI automatically validate input data.</p><h3>Step 3: Create an In-Memory Database</h3><p>For now, we’ll store items in a simple list.</p><pre>items = []</pre><p>Later, you can replace this with a real database.</p><h3>Step 4: Build CRUD Endpoints</h3><p>Now let’s create each operation.</p><h3>1. Create an Item (POST)</h3><pre>@app.post(&quot;/items&quot;)<br>def create_item(item: Item):<br>    item_id = len(items) + 1<br>    item_dict = item.dict()<br>    item_dict[&quot;id&quot;] = item_id<br>    items.append(item_dict)<br>    return item_dict</pre><h3>2. Read All Items (GET)</h3><pre>@app.get(&quot;/items&quot;)<br>def get_items():<br>    return items</pre><h3>3. Read a Single Item (GET)</h3><pre>@app.get(&quot;/items/{item_id}&quot;)<br>def get_item(item_id: int):<br>    for item in items:<br>        if item[&quot;id&quot;] == item_id:<br>            return item<br>    raise HTTPException(status_code=404, detail=&quot;Item not found&quot;)</pre><h3>4. Update an Item (PUT)</h3><pre>@app.put(&quot;/items/{item_id}&quot;)<br>def update_item(item_id: int, updated_item: Item):<br>    for index, item in enumerate(items):<br>        if item[&quot;id&quot;] == item_id:<br>            updated_data = updated_item.dict()<br>            updated_data[&quot;id&quot;] = item_id<br>            items[index] = updated_data<br>            return updated_data<br>    raise HTTPException(status_code=404, detail=&quot;Item not found&quot;)</pre><h3>5. Delete an Item (DELETE)</h3><pre>@app.delete(&quot;/items/{item_id}&quot;)<br>def delete_item(item_id: int):<br>    for index, item in enumerate(items):<br>        if item[&quot;id&quot;] == item_id:<br>            deleted = items.pop(index)<br>            return {&quot;message&quot;: &quot;Item deleted&quot;, &quot;item&quot;: deleted}<br>    raise HTTPException(status_code=404, detail=&quot;Item not found&quot;)</pre><h3>Step 5: Run the App</h3><p>Run your API using Uvicorn:</p><pre>uvicorn crud_app:app --reload</pre><p>Open your browser:</p><p>👉 <a href="http://127.0.0.1:8000/items"><strong>http://127.0.0.1:8000/items</strong></a></p><p>or view the API docs:</p><p>👉 <a href="http://127.0.0.1:8000/docs"><strong>http://127.0.0.1:8000/docs</strong></a><br> (Automatically generated by FastAPI!)</p><h3>You Just Built a CRUD App!</h3><p>You now have a fully functional CRUD API:</p><ul><li>Input validation</li><li>Clean endpoints</li><li>Error handling</li><li>Auto-generated docs</li></ul><p>This is the foundation of almost every real-world backend.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3481e19d6e0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to Setting Up FastAPI (Step-By-Step)]]></title>
            <link>https://medium.com/@shahpranshu27/a-beginners-guide-to-setting-up-fastapi-step-by-step-792de4453c5a?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/792de4453c5a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[fastapi]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Fri, 12 Dec 2025 12:54:42 GMT</pubDate>
            <atom:updated>2025-12-12T12:54:42.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X20dQzsnk9h_cLG2PdRmIg.png" /></figure><p>If you’re new to FastAPI and want a simple, clear guide to get started, you’re in the right place. FastAPI is one of the fastest and most intuitive Python frameworks for building APIs. It’s modern, lightweight, and surprisingly easy to learn, even if you’re just starting out.</p><p>Let’s walk through the setup from scratch so you can build and run your first FastAPI application in minutes.</p><h3>What Is FastAPI?</h3><p>FastAPI is a high-performance, Python web framework for building APIs.<br>It’s:</p><ul><li><strong>Fast</strong> — thanks to Starlette and Pydantic</li><li><strong>Easy to use</strong> — clean Python type hints</li><li><strong>Reliable</strong> — automatic validation</li><li><strong>Self-documenting</strong> — Swagger UI comes built-in</li></ul><p>Perfect for beginners and professionals alike.</p><h3>Step 1: Set Up Your Environment</h3><p>Before we start, ensure you have:</p><ul><li><strong>Python 3.8+</strong> installed</li><li>A terminal or command prompt</li><li>(Optional) A virtual environment</li></ul><h3>Create a project folder:</h3><pre>mkdir fastapi-demo<br>cd fastapi-demo</pre><h3>Create and activate a virtual environment:</h3><pre>python -m venv venv<br>source venv/bin/activate   # macOS/Linux<br>venv\Scripts\activate      # Windows</pre><h3>Step 2: Install FastAPI and Uvicorn</h3><p>FastAPI is just the framework; you need a server to run it.<br> We’ll use <strong>Uvicorn</strong>, a lightning-fast ASGI server.</p><p>Run:</p><pre>pip install fastapi uvicorn</pre><p>That’s it, FastAPI is now installed on your machine.</p><h3>Step 3: Create Your First FastAPI App</h3><p>Inside your project folder, create a new file:</p><pre>main.py</pre><p>Add the following code:</p><pre>from fastapi import FastAPI</pre><pre>app = FastAPI()</pre><pre>@app.get(&quot;/&quot;)<br>def read_root():<br>    return {&quot;message&quot;: &quot;Hello, FastAPI!&quot;}</pre><p>This creates:</p><ul><li>A FastAPI instance</li><li>A single GET endpoint at /</li><li>A JSON response</li></ul><p>Simple and clean.</p><h3>Step 4: Run the Application</h3><p>Run this in your terminal:</p><pre>uvicorn main:app --reload</pre><ul><li>main → file name (main.py)</li><li>app → FastAPI instance name</li><li>--reload → auto-refresh on code changes (super helpful)</li></ul><p>You should see something like:</p><pre>Running on http://127.0.0.1:8000</pre><p>Open that link in your browser, you’ll see:</p><pre>{&quot;message&quot;: &quot;Hello, FastAPI!&quot;}</pre><p>Congratulations, you just built your first FastAPI app!</p><h3>Step 5: Explore the Automatic API Docs</h3><p>One of FastAPI’s coolest features is that it generates interactive documentation automatically.</p><p>Open:</p><h3>Swagger UI</h3><p><a href="http://127.0.0.1:8000/docs">http://127.0.0.1:8000/docs</a></p><h3>ReDoc</h3><p><a href="http://127.0.0.1:8000/redoc">http://127.0.0.1:8000/redoc</a></p><p>You’ll find a beautifully formatted dashboard showing all your endpoints.</p><p>This is incredibly useful for testing and collaboration.</p><h3>Step 6: Add Another Endpoint (Optional)</h3><p>Try adding this to your main.py:</p><pre>@app.get(&quot;/hello/{name}&quot;)<br>def greet(name: str):<br>    return {&quot;message&quot;: f&quot;Hello, {name}!&quot;}</pre><p>Now visit:</p><pre>http://127.0.0.1:8000/hello/YourName</pre><p>Dynamic routing made simple.</p><h3>Final Thoughts</h3><p>FastAPI is an amazing tool for beginners because it:</p><ul><li>Makes writing APIs feel intuitive</li><li>Handles validation for you</li><li>Creates documentation automatically</li><li>Encourages clean, modern Python</li></ul><p>Once you master the basics, you can explore deeper topics like:</p><ul><li>Dependency injection</li><li>Authentication</li><li>Database integration</li><li>Background tasks</li><li>Middleware</li></ul><p>But for now, you’ve built a real, working API. That’s something to be proud of.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=792de4453c5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Big O Notation Explained Like You’re Five (But Actually for Developers)]]></title>
            <link>https://medium.com/@shahpranshu27/big-o-notation-explained-like-youre-five-but-actually-for-developers-e0c17bcbf83b?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0c17bcbf83b</guid>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Thu, 04 Dec 2025 07:01:45 GMT</pubDate>
            <atom:updated>2025-12-04T07:01:45.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ENAP16Z-YXbzEebQllXFYA.jpeg" /></figure><p>Big O is one of the most misunderstood concepts in computer science.<br>Not because it’s too mathematical, but because nobody explains <em>why it matters</em>.</p><p>So here’s the simplest explanation you’ll find.</p><h3>Big O answers one question:</h3><p><strong>“What happens when your data gets very, very large?”</strong></p><p>That’s it.</p><p>You’re not measuring exact speed.<br>You’re measuring <strong>how badly your code will struggle as input grows</strong>.</p><h3>The Real-World Analogy: Carrying Groceries</h3><p>Imagine you&#39;re carrying grocery bags from the car to your kitchen.</p><p>Different strategies have different “Big Os”:</p><h3>O(1): one trip no matter what</h3><p>You have a super-bag that magically expands.<br>1 trip. Always. Perfect scaling.</p><h3>O(n): one bag at a time</h3><p>10 bags = 10 trips<br>100 bags = 100 trips<br>Linear growth, manageable.</p><h3>O(n²): for every bag, pick up every other bag again</h3><p>You keep rechecking every bag each time.<br>It becomes chaos when you have lots of bags.</p><h3>O(log n): your bags are arranged perfectly</h3><p>You divide them into halves efficiently.<br>This is what binary search does.</p><h3>O(n log n): efficient sorting</h3><p>Most fast sorting algorithms live here.</p><h3>O(2ⁿ): adding one more bag doubles the time</h3><p>Impossible at scale, this is brute force.</p><h3>Why Developers Should Care</h3><p>Big O helps you answer questions like:</p><ul><li>Why is my app slow with large files?</li><li>Why does this database query hang when there are 1M rows?</li><li>Should I use a set or list?</li><li>Should I use BFS or DFS here?</li><li>Better Big O = better scalability.</li></ul><h3>The Secret No One Tells You</h3><p>Big O is <strong>NOT</strong> about being perfect.<br>It’s about avoiding disasters.</p><p>Choosing a slightly slower algorithm is fine.<br>Choosing one that collapses at scale is not.</p><h3>Conclusion</h3><p>Big O isn’t scary, it’s a way of predicting the future performance of your code.</p><p>If you understand this, you’re already ahead of most developers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0c17bcbf83b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding OOP in Python: The 4 pillars explained]]></title>
            <link>https://medium.com/@shahpranshu27/understanding-oop-in-python-the-4-pillars-explained-b977cac1d562?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/b977cac1d562</guid>
            <category><![CDATA[abstraction]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[encapsulation]]></category>
            <category><![CDATA[polymorphism]]></category>
            <category><![CDATA[oop-concepts]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Wed, 04 Dec 2024 11:21:51 GMT</pubDate>
            <atom:updated>2024-12-04T11:21:51.760Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, world! Today, we’re diving into the fascinating world of <strong>Object-Oriented Programming (OOP)</strong> in Python. OOP isn’t just about code — it’s a mindset, like realizing your laundry basket is overflowing <em>again</em>. Let’s explore its four foundational pillars: <strong>Encapsulation</strong>, <strong>Abstraction</strong>, <strong>Inheritance</strong>, and <strong>Polymorphism</strong>. (Sounds fancy, right? Let’s break it down with code, coffee, and comedy.)</p><h3>1. Encapsulation: Protecting Your Stuff</h3><p>Encapsulation is like locking your fridge to keep your sibling from devouring your snacks. You wrap your data (variables) and methods (functions) inside a class and control access using private (_) or protected (__) attributes.</p><h3>Code Snippet:</h3><pre>class SnackBox:<br>    def __init__(self):<br>        self._hidden_snacks = [&quot;Cookies&quot;, &quot;Chips&quot;, &quot;Chocolate&quot;]  # Protected snack stash<br>    <br>    def reveal_snacks(self):<br>        return f&quot;Available snacks: {&#39;, &#39;.join(self._hidden_snacks)}&quot;<br><br>def __private_snack_policy(self):  # A private method<br>        return &quot;Hands off my snacks!&quot;<br><br>box = SnackBox()<br>print(box.reveal_snacks())  # Allowed<br># print(box._hidden_snacks)  # Possible but frowned upon<br># print(box.__private_snack_policy())  # Nope, Python will protest!</pre><p><em>Encapsulation</em> teaches us boundaries — useful in code and life. Lock your fridge responsibly.</p><h3>2. Abstraction: Simplify the Complexity</h3><p>Abstraction is like asking your friend to drive you somewhere without explaining how the engine works. You just need the result — less talk, more action.</p><h3>Code Snippet:</h3><pre>from abc import ABC, abstractmethod<br><br>class Vehicle(ABC):  # Abstract Base Class<br>    @abstractmethod<br>    def start_engine(self):<br>        pass<br><br>class Car(Vehicle):<br>    def start_engine(self):<br>        return &quot;Vroom! The car engine roars to life.&quot;<br><br>class Bike(Vehicle):<br>    def start_engine(self):<br>        return &quot;Brmmm! The bike engine starts.&quot;<br><br># ride = Vehicle()  # Will throw an error—abstract classes can&#39;t be instantiated<br>car = Car()<br>print(car.start_engine())  # Vroom!<br>bike = Bike()<br>print(bike.start_engine())  # Brmmm!</pre><p><em>Abstraction</em> is about giving just enough details to make life easier. Like not telling your crush about your action figure collection on the first date.</p><h3>3. Inheritance: Passing Down the Traits</h3><p>Inheritance is like getting your dad’s bushy eyebrows or your mom’s sarcasm — classes inherit features from other classes. This promotes reusability, making code cleaner than your room on inspection day.</p><h3>Code Snippet:</h3><pre>class Parent:<br>    def family_recipe(self):<br>        return &quot;Top-secret pancake recipe.&quot;<br><br>class Child(Parent):<br>    def family_recipe(self):  # Optional override<br>        return &quot;I modified it to add chocolate chips!&quot;<br><br>child = Child()<br>print(child.family_recipe())  # Chocolate chip pancakes for the win!</pre><p>With <em>Inheritance</em>, you save time and code. And let’s admit, we’re all a little grateful for the genetic shortcuts.</p><h3>4. Polymorphism: One Thing, Many Forms</h3><p>Polymorphism is like your best friend who can be a chef, comedian, or therapist depending on the situation. One interface, many implementations.</p><h3>Code Snippet:</h3><pre>class Dog:<br>    def make_sound(self):<br>        return &quot;Woof!&quot;<br><br>class Cat:<br>    def make_sound(self):<br>        return &quot;Meow!&quot;<br><br>class Parrot:<br>    def make_sound(self):<br>        return &quot;Squawk!&quot;<br><br># Polymorphism in action<br>for pet in [Dog(), Cat(), Parrot()]:<br>    print(pet.make_sound())  # Everyone speaks their own language</pre><p><em>Polymorphism</em> shows how flexibility makes life — and code — more interesting. Unless the parrot starts swearing.</p><h3>Wrapping It All Up</h3><p>Object-Oriented Programming is like running a well-organized café:</p><ul><li><strong>Encapsulation</strong> keeps the recipe book locked.</li><li><strong>Abstraction</strong> ensures the customer doesn’t know how the coffee machine works.</li><li><strong>Inheritance</strong> lets you expand the café to sell cupcakes too.</li><li><strong>Polymorphism</strong> means both the barista and the robot can serve your coffee.</li></ul><p>Python makes OOP intuitive, powerful, and (with a bit of humor) fun to learn. So grab your keyboard and start building something awesome — whether it’s a snack box, a vehicle, or a pancake-inheriting robot chef.</p><p>Please share this article, clap &amp; comment. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b977cac1d562" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to save Machine Learning model using ‘Pickle’ and ‘Joblib’]]></title>
            <link>https://medium.com/@shahpranshu27/how-to-save-machine-learning-model-using-pickle-and-joblib-532103258ddb?source=rss-b7fc77dbaf96------2</link>
            <guid isPermaLink="false">https://medium.com/p/532103258ddb</guid>
            <category><![CDATA[model-training]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[joblib]]></category>
            <dc:creator><![CDATA[Pranshu Shah]]></dc:creator>
            <pubDate>Thu, 24 Oct 2024 10:19:10 GMT</pubDate>
            <atom:updated>2024-10-24T10:47:37.178Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to save your Machine Learning model using ‘<strong>Pickle’</strong> and ‘<strong>Joblib’</strong></h3><p>When building machine learning models, saving your work is crucial. Instead of retraining the model every time you want to use it, you can simply save the model and load it when needed.</p><p>In this post, I’ll walk you through how to save and load models using two powerful tools: <strong>Pickle</strong> and <strong>Joblib.</strong></p><h3>Why Save Your ML Model?</h3><p>Saving models is important for several reasons:</p><p>- <em>Efficiency</em>: No need to retrain the model every time.<br>- <em>Deployment</em>: Use the trained model in production environments.<br>- <em>Collaboration</em>: Share your models with others.<br>- <em>Reproducibility</em>: Ensure the same model can be reused with the exact same parameters and weights.</p><p>In this article, I’ll cover how to:</p><p>1. Save models using <strong>Pickle</strong> and <strong>Joblib</strong>.<br>2. Load saved models and make predictions.</p><p>Let’s dive in!</p><h3>Step 1: Train a Sample Model</h3><p>For simplicity, I’ll use the famous ‘Iris dataset’ and a ‘RandomForestClassifier’ to demonstrate model saving and loading.</p><pre>from sklearn.datasets import load_iris<br>from sklearn.ensemble import RandomForestClassifier<br>from sklearn.model_selection import train_test_split<br><br># Load Iris dataset<br>data = load_iris()<br>X = data.data<br>y = data.target<br><br># Split into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<br><br># Train a RandomForest model<br>model = RandomForestClassifier(n_estimators=100)<br>model.fit(X_train, y_train)<br></pre><h3>Step 2: Save the Model using <em>Pickle</em></h3><p><strong><em>Pickle</em></strong> is a Python library that serializes Python objects, including machine learning models, so they can be saved to disk and reloaded later.</p><pre>import pickle<br><br># Save the model as a .pkl file<br>with open(&#39;random_forest_model.pkl&#39;, &#39;wb&#39;) as f:<br> pickle.dump(model, f)<br>print(&quot;Model saved using Pickle!&quot;)<br><br># Once saved, you can load the model at any time and use it for predictions.<br><br># Load the saved model<br>with open(&#39;random_forest_model.pkl&#39;, &#39;rb&#39;) as f:<br> loaded_model = pickle.load(f)<br><br># Make predictions using the loaded model<br>y_pred = loaded_model.predict(X_test)</pre><figure><img alt="Pickle Image" src="https://cdn-images-1.medium.com/max/1024/1*kXndeMy3dbYNx5-w8auOvg.png" /></figure><h3>Step 3: Save the Model using Joblib</h3><p><strong><em>Joblib</em></strong> is another powerful library optimized for large datasets and models. It’s generally faster for saving and loading large objects compared to Pickle.</p><pre>import joblib<br><br># Save the model as a .joblib file<br>joblib.dump(model, &#39;random_forest_model.joblib&#39;)<br>print(&quot;Model saved using Joblib!&quot;)<br><br># Just like with Pickle, you can load the Joblib-saved model and make predictions.<br><br># Load the saved model<br>loaded_model_joblib = joblib.load(&#39;random_forest_model.joblib&#39;)<br><br># Make predictions using the Joblib-loaded model<br>y_pred_joblib = loaded_model_joblib.predict(X_test)</pre><h3>Step 4: Visualize the Model’s predictions</h3><p>Let’s visualize the model’s predictions using ‘Matplotlib’. This will give us an idea of how well the model is performing.</p><pre>import matplotlib.pyplot as plt<br># Plot true vs predicted values<br>plt.figure(figsize=(10, 6))<br>plt.plot(y_test, label=&#39;True Values&#39;, color=&#39;b&#39;)<br>plt.plot(y_pred, label=&#39;Predicted Values&#39;, color=&#39;r&#39;, linestyle=&#39; - &#39;)<br>plt.title(&quot;True vs Predicted Values - Pickle Model&quot;)<br>plt.legend()<br>plt.show()</pre><p>You can do the same for the ‘Joblib’ model as well.</p><h3>When to Use Pickle vs Joblib?</h3><p>- <strong>Pickle</strong>: Best for general-purpose serialization, supports many Python object types.<br>- <strong>Joblib</strong>: Optimized for larger models or objects, making it faster and more efficient for big datasets.</p><p>In general, if you’re working with larger datasets or more complex models, I would recommend using Joblib. For smaller models or more general use, Pickle is a great choice.</p><h3>Conclusion</h3><p>Saving and loading models is a critical step in machine learning workflows, especially when deploying models into production. In this post, we’ve seen how to easily save models using <strong>Pickle</strong> and <strong>Joblib.</strong></p><p>By using these tools, you can efficiently manage your models, making sure that you don’t need to train from scratch every time.</p><p>Feel free to drop a comment if you have any questions or additional insights on saving models. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=532103258ddb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>