Real Python 2026-03-16T14:00:00+00:00 https://realpython.com/ Real Python Spyder: Your IDE for Data Science Development in Python https://realpython.com/spyder-ide/ 2026-03-16T14:00:00+00:00 Learn how to use the Spyder IDE, a Python code editor built for scientists, engineers, and data analysts working with data-heavy workflows. <div><p>There are many different integrated development environments (IDEs) to choose from for Python development. One popular option for data-focused work is Spyder, an open-source Python IDE geared toward scientists, engineers, and data analysts. Its name comes from <em>Scientific PYthon Development EnviRonment</em>.</p> <p>Out of the box, it has powerful plotting, what-if, and profiling capabilities. It also integrates well with the <a href="https://realpython.com/tutorials/data-science/">data science</a> ecosystem, is extensible with first- or third-party plugins, and has a relatively quick learning curve.</p> <p>How does Spyder stack up against other Python <a href="/ref/glossary/ide/" class="ref-link">IDEs</a>? It depends on your use case. It’s not as powerful or customizable as <a href="/ref/code-editors-ides/visual-studio-code/" class="ref-link">VS Code</a>, nor does it pretend to be. It does, however, excel for data science workflows:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th>Pick Spyder</th> <th>Pick an Alternative</th> </tr> </thead> <tbody> <tr> <td>Optimized for data science workflows</td> <td>✅</td> <td>—</td> </tr> <tr> <td>Dedicated to Python</td> <td>✅</td> <td>—</td> </tr> <tr> <td>Full-featured</td> <td>—</td> <td>VS Code</td> </tr> <tr> <td>Supports interactive notebooks</td> <td>✅ With a plugin</td> <td>Jupyter, VS Code</td> </tr> </tbody> </table> </div> <p>If you’re focused on data science in Python, Spyder is a strong fit. For a more full-featured IDE or heavy notebook use, consider <a href="https://realpython.com/jupyter-notebook-introduction/">Jupyter</a> or VS Code instead.</p> <p>You can get a handy Spyder IDE cheat sheet at the link below:</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Free Spyder Cheat Sheet:</strong> <a href="https://realpython.com/bonus/spyder-ide-cheatsheet/" class="alert-link" data-toggle="modal" data-target="#modal-spyder-ide-cheatsheet" markdown>Click here to download the PDF</a> with installation steps, shortcuts, and interface tips.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Spyder: Your IDE for Data Science Development in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/spyder-ide/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #b9abe6;" alt="Spyder: Your IDE for Data Science Development in Python" src="https://files.realpython.com/media/Pythons-Spyder-IDE_Watermarked.a5f4691ecaa3.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Pythons-Spyder-IDE_Watermarked.a5f4691ecaa3.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Pythons-Spyder-IDE_Watermarked.a5f4691ecaa3.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Pythons-Spyder-IDE_Watermarked.a5f4691ecaa3.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Pythons-Spyder-IDE_Watermarked.a5f4691ecaa3.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/spyder-ide/" class="stretched-link"><span class="my-0 h4">Spyder: Your IDE for Data Science Development in Python</span></a> <p class="text-muted mb-0 small">Test your knowledge of the Spyder IDE for Python data science, including its Variable Explorer, Plots pane, and Profiler.</p> </div> </div> </div> <h2 id="start-using-the-spyder-ide">Start Using the Spyder IDE<a class="headerlink" href="#start-using-the-spyder-ide" title="Permanent link"></a></h2> <p>You can install <a href="/ref/code-editors-ides/spyder/" class="ref-link">Spyder</a> in a few ways: as a standalone program, through a prepackaged distribution, or from the command line. You can also try out Spyder <a href="https://mybinder.org/v2/gh/spyder-ide/binder-environments/spyder-stable?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.com%252Fspyder-ide%252FSpyder-Workshop%26urlpath%3Ddesktop%252F%26branch%3Dmaster">online</a>.</p> <p>To install Spyder as a standalone application, go to the Spyder <a href="https://www.spyder-ide.org/download">download page</a>. When you visit the site, it detects your operating system and offers the appropriate download. Once you download your install file, open it and follow the directions.</p> <p>You can also install a Python distribution tailored to data science, such as <a href="/ref/tools/anaconda/" class="ref-link">Anaconda</a> or <a href="https://winpython.github.io/">WinPython</a>. Both of these choices include Spyder in their base installations.</p> <p>You’ll likely want to install dependencies and useful data libraries in addition to Spyder. In this case, first create a <a href="https://realpython.com/python-virtual-environments-a-primer/">Python virtual environment</a>, then use this command:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>conda<span class="w"> </span>create<span class="w"> </span>-c<span class="w"> </span>conda-forge<span class="w"> </span>-n<span class="w"> </span>spyder-env<span class="w"> </span>spyder<span class="w"> </span>numpy<span class="w"> </span>scipy<span class="w"> </span>pandas<span class="w"> </span>matplotlib<span class="w"> </span>sympy<span class="w"> </span>cython </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>The install process for <a href="/ref/glossary/pip/" class="ref-link"><code>pip</code></a> is similar. To install <code>spyder</code> together with common packages, run:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>spyder<span class="w"> </span>numpy<span class="w"> </span>scipy<span class="w"> </span>pandas<span class="w"> </span>matplotlib<span class="w"> </span>sympy<span class="w"> </span>cython </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>For more information on installing Spyder, refer to their <a href="https://docs.spyder-ide.org/current/installation.html">install guide</a>.</p> <p>Out of the box, the Spyder interface consists of three panes:</p> <figure class="js-lightbox"><a href="https://files.realpython.com/media/interface.ab9b83e4a70e.jpg" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block " src="https://files.realpython.com/media/interface.ab9b83e4a70e.jpg" width="1904" height="1072" srcset="/cdn-cgi/image/width=476,format=auto/https://files.realpython.com/media/interface.ab9b83e4a70e.jpg 476w, /cdn-cgi/image/width=634,format=auto/https://files.realpython.com/media/interface.ab9b83e4a70e.jpg 634w, /cdn-cgi/image/width=952,format=auto/https://files.realpython.com/media/interface.ab9b83e4a70e.jpg 952w, /cdn-cgi/image/width=1904,format=auto/https://files.realpython.com/media/interface.ab9b83e4a70e.jpg 1904w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Spyder IDE Interface" data-asset="6708"></a><figcaption class="figure-caption text-center">The Spyder IDE Interface</figcaption></figure> <p>On the left, you see code in the <em>Editor</em> pane. In the bottom right, you’ll find the <em><a href="https://realpython.com/ipython-interactive-python-shell/">IPython</a> Console</em>. Here, you can run code and check past commands using the <em>History</em> tab. The top-right area includes tabs such as <em>Help</em>, <em>Debugger</em>, <em>Files</em>, <em>Find</em>, and <em>Code Analysis</em>. You’ll learn about the <em>Variable Explorer</em>, <em>Plots</em>, and <em>Profiler</em> in the upcoming sections.</p> <h2 id="explore-data-with-the-variable-explorer">Explore Data With the Variable Explorer<a class="headerlink" href="#explore-data-with-the-variable-explorer" title="Permanent link"></a></h2> </div><h2><a href="https://realpython.com/spyder-ide/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/spyder-ide/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Speed Up Python With Concurrency https://realpython.com/quizzes/speed-python-concurrency/ 2026-03-16T12:00:00+00:00 Test your Python concurrency knowledge: CPU vs I/O-bound tasks, GIL, asyncio, race conditions, and multiprocessing. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/courses/speed-python-concurrency/">Speed Up Python With Concurrency</a>.</p> <p>You&rsquo;ll explore how I/O-bound programs face latency, which concurrency patterns to use, the differences between <code>threading</code>, <code>asyncio</code>, and <code>multiprocessing</code>, and how the Global Interpreter Lock (GIL) affects Python programs.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Splitting, Concatenating, and Joining Python Strings https://realpython.com/quizzes/splitting-concatenating-and-joining-strings-python/ 2026-03-14T12:00:00+00:00 Brush up on splitting, concatenating, and joining strings in Python. Test your understanding of methods, immutability, and common pitfalls. <p>How well do you know Python string manipulation? In this quiz, you&rsquo;ll revisit concepts like string immutability, splitting and joining with different arguments, and building safe string operations for tasks like CSV handling.</p> <p>You&rsquo;ll get hands-on practice with real examples from the <a href="https://realpython.com/courses/splitting-concatenating-and-joining-strings-python/">Splitting, Concatenating, and Joining Strings in Python</a> course. Ready to test your skills?</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #287: Crafting and Editing In-Depth Tutorials at Real Python https://realpython.com/podcasts/rpp/287/ 2026-03-13T12:00:00+00:00 What goes into creating the tutorials you read at Real Python? What are the steps in the editorial process, and who are the people behind the scenes? This week on the show, Real Python team members Martin Breuss, Brenda Weleschuk, and Philipp Acsany join us to discuss topic curation, review stages, and quality assurance. <p>What goes into creating the tutorials you read at Real Python? What are the steps in the editorial process, and who are the people behind the scenes? This week on the show, Real Python team members Martin Breuss, Brenda Weleschuk, and Philipp Acsany join us to discuss topic curation, review stages, and quality assurance.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Your Python Coding Environment on Windows: Setup Guide https://realpython.com/quizzes/python-coding-setup-windows/ 2026-03-13T12:00:00+00:00 Test your knowledge of setting up a Python dev environment on Windows, from updates and terminals to paths, tools, and WSL. <p>Test your understanding of <a href="https://realpython.com/python-coding-setup-windows/">Python Coding Setup on Windows</a>.</p> <p>By working through this quiz, you&rsquo;ll review the key steps for setting up a Python development environment on Windows. You&rsquo;ll cover system updates, Windows Terminal, package managers, PowerShell profiles, environment variables, and safe use of remote scripts.</p> <p>You&rsquo;ll also check practical details like configuring Path, managing Python versions, using version control, and streamlining your workflow.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: How to Use Ollama to Run Large Language Models Locally https://realpython.com/quizzes/ollama/ 2026-03-12T12:00:00+00:00 Test your knowledge of running LLMs locally with Ollama. Install it, pull models, chat, and connect coding tools from your terminal. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/ollama/">How to Use Ollama to Run Large Language Models Locally</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit how to install Ollama, pull and manage models, chat with local LLMs from your terminal, and connect them to AI coding tools.</p> <p>Running models locally means your prompts stay private and no API keys or cloud services are needed. See how well you remember the key commands and concepts.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Working With Files in Python https://realpython.com/quizzes/working-with-files-in-python/ 2026-03-12T12:00:00+00:00 Practice handling files and directories in Python, including opening, iterating, filtering, creating, deleting, copying, and renaming. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/working-with-files-in-python/">Working With Files in Python</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit key techniques for handling files and directories in Python. You&rsquo;ll practice safely opening files, iterating over directories, and filtering entries to select only files or subdirectories.</p> <p>You&rsquo;ll also explore creating directories and managing files and directories, including deleting, copying, and renaming them.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Pydantic AI: Build Type-Safe LLM Agents in Python https://realpython.com/pydantic-ai/ 2026-03-11T14:00:00+00:00 Learn how to use Pydantic AI to build type-safe LLM agents in Python with structured outputs, function calling, and dependency injection patterns. <div><p>Pydantic AI is a Python framework for building LLM agents that return validated, structured outputs using Pydantic models. Instead of parsing raw strings from LLMs, you get type-safe objects with automatic validation.</p> <p>If you’ve used FastAPI or Pydantic before, then you’ll recognize the familiar pattern of defining schemas with type hints and letting the framework handle the type validation for you.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li><strong>Pydantic AI</strong> uses <code>BaseModel</code> classes to define structured outputs that guarantee <strong>type safety</strong> and automatic <strong>validation</strong>.</li> <li>The <code>@agent.tool</code> <strong>decorator</strong> registers Python functions that <strong>LLMs can invoke</strong> based on user queries and docstrings.</li> <li><strong>Dependency injection</strong> with <code>deps_type</code> provides <strong>type-safe</strong> runtime context like database connections without using <strong>global state</strong>.</li> <li><strong>Validation retries</strong> automatically rerun queries when the LLM returns invalid data, which increases <strong>reliability</strong> but also <strong>API costs</strong>.</li> <li><strong>Google Gemini</strong>, <strong>OpenAI</strong>, and <strong>Anthropic</strong> models support structured outputs best, while other providers have <strong>varying capabilities</strong>.</li> </ul> <p>Before you invest time learning Pydantic AI, it helps to understand when it’s the right tool for your project. This decision table highlights common use cases and what to choose in each scenario:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th class="text-center">Pydantic AI</th> <th class="text-center">If not, look into …</th> </tr> </thead> <tbody> <tr> <td>You need structured, validated outputs from an LLM</td> <td class="text-center">✅</td> <td class="text-center">-</td> </tr> <tr> <td>You’re building a quick prototype or single-agent app</td> <td class="text-center">✅</td> <td class="text-center">-</td> </tr> <tr> <td>You already use Pydantic or FastAPI</td> <td class="text-center">✅</td> <td class="text-center">-</td> </tr> <tr> <td>You need a large ecosystem of pre-built integrations (vector stores, retrievers, and so on)</td> <td class="text-center">-</td> <td class="text-center"><a href="https://realpython.com/build-llm-rag-chatbot-with-langchain/">LangChain</a> or <a href="https://realpython.com/llamaindex-examples/">LlamaIndex</a></td> </tr> <tr> <td>You want fine-grained control over prompts with no framework overhead</td> <td class="text-center">-</td> <td class="text-center"><a href="https://realpython.com/chatgpt-api-python/">Direct API calls</a></td> </tr> </tbody> </table> </div> <p>Pydantic AI emphasizes type safety and minimal boilerplate, making it ideal if you value the FastAPI-style development experience.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/pydantic-ai-code/" class="alert-link" data-toggle="modal" data-target="#modal-pydantic-ai-code" markdown>Click here to download the free sample code</a> you’ll use to work with Pydantic AI and build type-safe LLM agents in Python.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Pydantic AI: Build Type-Safe LLM Agents in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/pydantic-ai/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #fe7e73;" alt="PydanticAI: Typed LLM Agents With Structured Outputs" src="https://files.realpython.com/media/Pydantic-AI-Typed-LLM-Agents-with-Structured-Outputs_Watermarked.043c8afd949c.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Pydantic-AI-Typed-LLM-Agents-with-Structured-Outputs_Watermarked.043c8afd949c.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Pydantic-AI-Typed-LLM-Agents-with-Structured-Outputs_Watermarked.043c8afd949c.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Pydantic-AI-Typed-LLM-Agents-with-Structured-Outputs_Watermarked.043c8afd949c.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Pydantic-AI-Typed-LLM-Agents-with-Structured-Outputs_Watermarked.043c8afd949c.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/pydantic-ai/" class="stretched-link"><span class="my-0 h4">Pydantic AI: Build Type-Safe LLM Agents in Python</span></a> <p class="text-muted mb-0 small">Learn the trade-offs of using Pydantic AI in production, including validation retries, structured outputs, tool usage, and token costs.</p> </div> </div> </div> <h2 id="start-using-pydantic-ai-to-create-agents">Start Using Pydantic AI to Create Agents<a class="headerlink" href="#start-using-pydantic-ai-to-create-agents" title="Permanent link"></a></h2> <p>Before you dive into building agents with <a href="/ref/ai-coding-tools/pydantic-ai/" class="ref-link"><strong>Pydantic AI</strong></a> and Python, you’ll need to install it and set up an <a href="/ref/glossary/api/" class="ref-link">API</a> key for your chosen language model provider. For this tutorial, you’ll use Google <a href="/ref/ai-coding-tools/gemini/" class="ref-link">Gemini</a>, which offers a free tier perfect for experimentation.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> Pydantic AI is LLM-agnostic and supports multiple AI providers. Check the <a href="https://ai.pydantic.dev/models/overview/">Model Providers</a> documentation page for more details on other providers.</p> </div> <p>You can install Pydantic AI from the <a href="/ref/glossary/pypi/" class="ref-link">Python Package Index (PyPI)</a> using a package manager like <a href="https://realpython.com/what-is-pip/"><code>pip</code></a>. Before running the command below, you should create and activate a <a href="https://realpython.com/python-virtual-environments-a-primer/">virtual environment</a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>pydantic-ai </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>This command installs all supported model providers, including Google, Anthropic, and OpenAI. From this point on, you just need to set up your favorite provider’s API key to use their models with Pydantic AI. Note that in most cases, you’d need a paid subscription to get a working API key.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> You can also power your Pydantic AI apps with local language models. To do this, you can use <a href="/ref/ai-coding-tools/ollama/" class="ref-link">Ollama</a> with your favorite local models. In this scenario, you won’t need to set up an API key.</p> </div> <p>If you prefer a minimal installation with only Google Gemini support, you can install the <a href="https://ai.pydantic.dev/install/#slim-install">slim package</a> instead:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span><span class="s2">"pydantic-ai-slim[google]"</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>You need a personal <a href="https://www.google.com/account/about/">Google account</a> to use the Gemini free tier. You’ll also need a Google API key to run the examples in this tutorial, so head over to <a href="https://ai.google.dev/gemini-api/docs/api-key">ai.google.dev</a> to get a free API key.</p> <p>Once you have the API key, set it as an environment variable:</p> <ul class="nav nav-tabs justify-content-end js-platform-widget-tabs" role="tablist"> <li class="nav-item mb-0 js-platform-widget-tab-windows" role="presentation"> <a class="nav-link link-unstyled text-body active small" id="windows-tab-1" data-toggle="tab" href="#windows-1" role="tab" aria-controls="windows-1" aria-selected="true"><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#brands--windows"></use></svg></span>Windows</a> </li> <li class="nav-item mb-0 js-platform-widget-tab-linuxmacos" role="presentation"> <a class="nav-link link-unstyled text-body small" id="macos-tab-1" data-toggle="tab" href="#linux-macos-1" role="tab" aria-controls="linux-macos-1" aria-selected="false"><span class="icon baseline text-muted" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#v4--linux"></use></svg></span><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#v4--apple"></use></svg></span>Linux + macOS</a> </li> </ul> <div class="tab-content mt-2 mb-0 js-platform-widget-content"> <div aria-labelledby="windows-tab-1" class="tab-pane fade show active" id="windows-1" role="tabpanel"> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">PS&gt; </span><span class="nv">$ENV:GOOGLE_API_KEY</span> <span class="p">=</span> <span class="s2">"your-api-key-here"</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div> <div aria-labelledby="linux-macos-tab-1" class="tab-pane fade " id="linux-macos-1" role="tabpanel"> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span><span class="nb">export</span><span class="w"> </span><span class="nv">GOOGLE_API_KEY</span><span class="o">=</span><span class="s2">"your-api-key-here"</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div> </div> <p>With the installation complete and your API key configured, you’re ready to create your first agent. The Python professionals on Real Python’s team have technically reviewed and tested all the code examples in this tutorial, so you can work through them knowing they run as shown.</p> </div><h2><a href="https://realpython.com/pydantic-ai/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/pydantic-ai/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Create and Modify PDF Files in Python https://realpython.com/quizzes/creating-modifying-pdf/ 2026-03-11T12:00:00+00:00 Test your Python PDF skills: read, modify, extract, encrypt, and manipulate PDF files using the pypdf library. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/creating-modifying-pdf/">Creating and Modifying PDF Files in Python</a>.</p> <p>By working through this quiz, you&rsquo;ll practice reading, extracting, and modifying PDFs using the pypdf library. You&rsquo;ll also review how to write new PDFs, concatenate and merge files, crop pages, and encrypt or decrypt documents.</p> <p>These skills help you automate PDF workflows and handle documents programmatically in Python.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Threading in Python https://realpython.com/quizzes/threading-in-python/ 2026-03-11T12:00:00+00:00 Test your understanding of Python threading, including how to create threads, use locks, avoid race conditions, and build pipelines. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/courses/threading-python/">Threading in Python</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit how to create and manage threads, use <code>ThreadPoolExecutor</code>, prevent race conditions with locks, and build producer-consumer pipelines with the <code>queue</code> module.</p> <p>You can also review the written tutorial <a href="https://realpython.com/intro-to-python-threading/">An Intro to Threading in Python</a> for additional details and code examples.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Working With APIs in Python: Reading Public Data https://realpython.com/courses/working-apis-reading-public-data/ 2026-03-10T14:00:00+00:00 Learn how to consume REST APIs with Python using the requests library, including authentication, query parameters, and handling responses. <p>Python is an excellent choice for working with Application Programming Interfaces (APIs), allowing you to efficiently consume and interact with them. By using the Requests library, you can easily fetch data from APIs that communicate using HTTP, such as REST, SOAP, or GraphQL APIs. This video course covers the essentials of consuming REST APIs with Python, including authentication and handling responses.</p> <p><strong>By the end of this video course, you&rsquo;ll understand that:</strong></p> <ul> <li>An <strong>API</strong> is an interface that allows different systems to communicate, typically through requests and responses.</li> <li>Python is a versatile language for <strong>consuming APIs</strong>, offering libraries like <strong>Requests</strong> to simplify the process.</li> <li><strong>REST and GraphQL</strong> are two common <strong>types of APIs</strong>, with REST being more widely used for public APIs.</li> <li>To handle <strong>API authentication in Python</strong>, you can use API keys or more complex methods like <strong>OAuth</strong> to access protected resources.</li> </ul> <p>Knowing how to consume an API is one of those magical skills that, once mastered, will crack open a whole new world of possibilities, and consuming APIs using Python is a great way to learn such a skill.</p> <p>By the end of this video course, you&rsquo;ll be able to use Python to consume most of the APIs that you come across. If you&rsquo;re a developer, then knowing how to consume APIs with Python will empower you to integrate data from various online sources into your applications.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Python Descriptors: An Introduction https://realpython.com/quizzes/python-descriptors/ 2026-03-10T12:00:00+00:00 Learn how Python descriptors control attribute access, use special methods for getting and setting values, and implement read-only attributes. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/python-descriptors/">Python Descriptors</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit the descriptor protocol, how <code>.__get__()</code> and <code>.__set__()</code> control attribute access, and how to implement read only descriptors. You&rsquo;ll also explore data vs. non-data descriptors, attribute lookup order, and the <code>.__set_name__()</code> method.</p> <p>These exercises help you reason about real descriptor behavior and see when and why to use them in your code.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Python Gains frozendict and Other Python News for March 2026 https://realpython.com/python-news-march-2026/ 2026-03-09T14:00:00+00:00 Catch up on the latest Python news: frozendict joins the built-ins, Django patches SQL injections, and AI SDKs race to add WebSocket transport. <div><p>After years of community requests, Python is finally getting <strong><code>frozendict</code></strong>. The Steering Council accepted <a href="https://peps.python.org/pep-0814/">PEP 814</a> in February, bringing an immutable, hashable dictionary as a built-in type in Python 3.15. It’s one of those additions that feels overdue, and the <code>frozenset</code>-to-<code>set</code> analogy makes it immediately intuitive. This is just one piece of a busy month of Python news.</p> <p>Beyond that, February brought security patches, AI SDK updates, and some satisfying infrastructure improvements under Python’s hood. Time to dive into the biggest Python news from the past month!</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Join Now:</strong> <a href="https://realpython.com/bonus/newsletter/" class="alert-link" data-toggle="modal" data-target="#modal-newsletter" markdown>Click here to join the Real Python Newsletter</a> and you’ll never miss another Python tutorial, course, or news update.</p> </div> <h2 id="python-releases-and-pep-highlights">Python Releases and PEP Highlights<a class="headerlink" href="#python-releases-and-pep-highlights" title="Permanent link"></a></h2> <p>The <a href="/ref/glossary/python-steering-council/" class="ref-link">Steering Council</a> was active in February, with several <a href="/ref/glossary/pep/" class="ref-link">PEP</a> decisions landing. On the release side, both the 3.14 and 3.13 branches got maintenance updates.</p> <h3 id="python-3150-alpha-6-comprehension-unpacking-and-more">Python 3.15.0 Alpha 6: Comprehension Unpacking and More<a class="headerlink" href="#python-3150-alpha-6-comprehension-unpacking-and-more" title="Permanent link"></a></h3> <p><a href="https://pythoninsider.blogspot.com/2026/02/python-3150-alpha-6.html">Python 3.15.0a6</a> shipped on February 11, continuing the alpha series toward the May 5 beta freeze. This release includes several accepted PEPs that are now testable:</p> <ul> <li><a href="https://peps.python.org/pep-0798/">PEP 798</a>: Unpacking in <a href="https://realpython.com/list-comprehension-python/">comprehensions</a> using <code>*</code> and <code>**</code></li> <li><a href="https://peps.python.org/pep-0799/">PEP 799</a>: A high-frequency, low-overhead statistical sampling <a href="https://realpython.com/python-profiling/">profiler</a></li> <li><a href="https://peps.python.org/pep-0686/">PEP 686</a>: <a href="https://realpython.com/python-encodings-guide/">UTF-8</a> as the default text encoding</li> <li><a href="https://peps.python.org/pep-0728/">PEP 728</a>: <code>TypedDict</code> with typed extra items</li> </ul> <p>PEP 798 is the kind of quality-of-life improvement that makes you smile. It lets you <a href="https://realpython.com/python-flatten-list/">flatten</a> or merge <a href="/ref/glossary/collection/" class="ref-link">collections</a> directly in a <a href="/ref/glossary/comprehension/" class="ref-link">comprehension</a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n">lists</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">5</span><span class="p">]]</span> <span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="o">*</span><span class="n">it</span> <span class="k">for</span> <span class="n">it</span> <span class="ow">in</span> <span class="n">lists</span><span class="p">]</span> <span class="go">[1, 2, 3, 4, 5]</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">dicts</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">"a"</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="p">{</span><span class="s2">"b"</span><span class="p">:</span> <span class="mi">2</span><span class="p">}]</span> <span class="gp">&gt;&gt;&gt; </span><span class="p">{</span><span class="o">**</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">dicts</span><span class="p">}</span> <span class="go">{'a': 1, 'b': 2}</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>No more writing explicit loops just to concatenate a list of lists.</p> <p>The <a href="/ref/glossary/jit-compiler/" class="ref-link">JIT compiler</a> continues to show gains: <strong>3-4% on x86-64 Linux</strong> over the standard <a href="/ref/glossary/interpreter/" class="ref-link">interpreter</a> and <strong>7-8% on AArch64 macOS</strong> over the tail-calling interpreter, matching the numbers from <a href="https://realpython.com/python-news-february-2026/#python-3150-alpha-4-and-5-two-releases-in-two-days">alpha 5</a>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> Alpha 7 is scheduled for March 10, 2026, with the beta phase starting May 5. If you maintain packages, now is a great time to <a href="https://realpython.com/python-pre-release/">test against early builds</a>.</p> </div> <h3 id="python-3143-and-31312-maintenance-releases">Python 3.14.3 and 3.13.12: Maintenance Releases<a class="headerlink" href="#python-3143-and-31312-maintenance-releases" title="Permanent link"></a></h3> <p>On February 3, the team shipped <a href="https://www.python.org/downloads/release/python-3143/">Python 3.14.3</a> with around 300 bug fixes and <a href="https://www.python.org/downloads/release/python-31312/">Python 3.13.12</a> with about 240 fixes. No new features here, but if you’re running either version in production, it’s worth grabbing these patches to stay current.</p> <h3 id="pep-814-accepted-frozendict-joins-the-built-ins">PEP 814 Accepted: <code>frozendict</code> Joins the Built-Ins<a class="headerlink" href="#pep-814-accepted-frozendict-joins-the-built-ins" title="Permanent link"></a></h3> <p>This one has been on many Python developers’ wishlists for over a decade. <a href="https://peps.python.org/pep-0814/">PEP 814</a>, authored by Victor Stinner and Donghee Na, adds <code>frozendict</code> as a built-in <a href="/ref/glossary/immutable/" class="ref-link">immutable</a> <a href="https://realpython.com/python-dicts/">dictionary</a> type in Python 3.15.</p> <p>The concept is straightforward. Just as <a href="/ref/builtin-types/frozenset/" class="ref-link"><code>frozenset</code></a> gives you an immutable version of <a href="https://realpython.com/python-sets/"><code>set</code></a>, <code>frozendict</code> gives you an immutable version of <a href="/ref/builtin-types/dict/" class="ref-link"><code>dict</code></a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n">config</span> <span class="o">=</span> <span class="n">frozendict</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s2">"localhost"</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">8080</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">config</span><span class="p">[</span><span class="s2">"host"</span><span class="p">]</span> <span class="go">'localhost'</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">config</span><span class="p">[</span><span class="s2">"host"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"0.0.0.0"</span> <span class="gt">Traceback (most recent call last):</span> <span class="w"> </span><span class="o">...</span> <span class="gr">TypeError</span>: <span class="n">'frozendict' object does not support item assignment</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div><h2><a href="https://realpython.com/python-news-march-2026/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-news-march-2026/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Introduction to Python SQL Libraries https://realpython.com/quizzes/python-sql-libraries/ 2026-03-09T12:00:00+00:00 Learn to connect Python to databases, run queries, and manage data using SQLite, PostgreSQL, MySQL, and SQL basics. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/python-sql-libraries/">Python SQL Libraries</a>.</p> <p>Work through this quiz to connect to databases with Python, interact with SQLite, MySQL, and PostgreSQL, run SQL queries, and write scripts that work across databases.</p> <p>Reinforce your practical skills for building Python apps backed by databases.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Pydantic AI: Build Type-Safe LLM Agents in Python https://realpython.com/quizzes/pydantic-ai/ 2026-03-09T12:00:00+00:00 Learn the trade-offs of using Pydantic AI in production, including validation retries, structured outputs, tool usage, and token costs. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/pydantic-ai/">Pydantic AI: Build Type-Safe LLM Agents in Python</a>.</p> <p>You&rsquo;ll revisit what Pydantic AI is, how to specify a model provider, how to return structured outputs using Pydantic models, how to register and select tools, how dependency injection works, and what trade-offs to expect in production.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> How to Use the OpenRouter API to Access Multiple AI Models via Python https://realpython.com/openrouter-api/ 2026-03-04T14:00:00+00:00 Access models from popular AI providers in Python through OpenRouter's unified API with smart routing, fallbacks, and cost controls. <div><p>One of the quickest ways to call multiple AI models from a single Python script is to use OpenRouter’s API, which acts as a unified routing layer between your code and multiple AI providers. By the end of this guide, you’ll access models from several providers through one unified API, as shown in the image below:</p> <figure class="js-lightbox"><a href="https://files.realpython.com/media/open-router-multiple-AI-models-screenshot.adfb5097125a.png" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block " src="https://files.realpython.com/media/open-router-multiple-AI-models-screenshot.adfb5097125a.png" width="1527" height="773" srcset="/cdn-cgi/image/width=381,format=auto/https://files.realpython.com/media/open-router-multiple-AI-models-screenshot.adfb5097125a.png 381w, /cdn-cgi/image/width=509,format=auto/https://files.realpython.com/media/open-router-multiple-AI-models-screenshot.adfb5097125a.png 509w, /cdn-cgi/image/width=763,format=auto/https://files.realpython.com/media/open-router-multiple-AI-models-screenshot.adfb5097125a.png 763w, /cdn-cgi/image/width=1527,format=auto/https://files.realpython.com/media/open-router-multiple-AI-models-screenshot.adfb5097125a.png 1527w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Open Router Running Multiple AI Models" data-asset="6755"></a><figcaption class="figure-caption text-center">OpenRouter Unified API Running Multiple AI Models</figcaption></figure> <p>This convenience matters because the AI ecosystem is highly fragmented: each provider exposes its own API, authentication scheme, rate limits, and model lineup. Working with multiple providers often requires additional setup and integration effort, especially when you want to experiment with different models, compare outputs, or evaluate trade-offs for a specific task.</p> <p><a href="https://openrouter.ai/">OpenRouter</a> gives you access to thousands of models from leading providers such as OpenAI, Anthropic, Mistral, Google, and Meta. You switch between them without changing your application code.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/openrouter-api-code/" class="alert-link" data-toggle="modal" data-target="#modal-openrouter-api-code" markdown>Click here to download the free sample code</a> that shows you how to use the OpenRouter API to access multiple AI models via Python.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “How to Use the OpenRouter API to Access Multiple AI Models via Python” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/openrouter-api/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #abe5b2;" alt="How to Use the OpenRouter API to Access Multiple AI Models via Python" src="https://files.realpython.com/media/How-To-Use-OpenRouter-to-Access-Multiple-AI-Models-via-Python_Watermarked-2.7cb51570b2ac.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/How-To-Use-OpenRouter-to-Access-Multiple-AI-Models-via-Python_Watermarked-2.7cb51570b2ac.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-To-Use-OpenRouter-to-Access-Multiple-AI-Models-via-Python_Watermarked-2.7cb51570b2ac.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-To-Use-OpenRouter-to-Access-Multiple-AI-Models-via-Python_Watermarked-2.7cb51570b2ac.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-To-Use-OpenRouter-to-Access-Multiple-AI-Models-via-Python_Watermarked-2.7cb51570b2ac.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/openrouter-api/" class="stretched-link"><span class="my-0 h4">How to Use the OpenRouter API to Access Multiple AI Models via Python</span></a> <p class="text-muted mb-0 small">Test your Python skills with OpenRouter: learn unified API access, model switching, provider routing, and fallback strategies.</p> </div> </div> </div> <h2 id="prerequisites">Prerequisites<a class="headerlink" href="#prerequisites" title="Permanent link"></a></h2> <p>Before diving into OpenRouter, you should be comfortable with Python fundamentals like importing <a href="/ref/glossary/module/" class="ref-link">modules</a>, working with <a href="/ref/glossary/dictionary/" class="ref-link">dictionaries</a>, <a href="/ref/builtin-exceptions/" class="ref-link">handling exceptions</a>, and using environment <a href="/ref/glossary/variable/" class="ref-link">variables</a>. If you’re familiar with these basics, the first step is authenticating with OpenRouter’s API.</p> <h2 id="step-1-connect-to-openrouters-api">Step 1: Connect to OpenRouter’s API<a class="headerlink" href="#step-1-connect-to-openrouters-api" title="Permanent link"></a></h2> <p>Before using OpenRouter, you need to create an account and generate an <a href="/ref/glossary/api/" class="ref-link">API</a> key. Some models require prepaid credits for access, but you can start with free access to test the API and confirm that everything is working.</p> <p>To generate an API key:</p> <ul> <li>Create an account at <a href="https://openrouter.ai/">OpenRouter.ai</a> or sign in if you already have an account.</li> <li>Select <em>Keys</em> from the dropdown menu and create an <a href="https://openrouter.ai/settings/keys">API key</a>.</li> <li>Fill in the name, something like <em>OpenRouter Testing</em>.</li> <li>Leave the remaining defaults and click <em>Create</em>.</li> </ul> <p>Copy the generated key and keep it secure. In a moment, you’ll store it as an environment variable rather than embedding it directly in your code.</p> <p>To call multiple AI models from a single <a href="https://realpython.com/run-python-scripts/">Python script</a>, you’ll use OpenRouter’s API. You’ll use the <a href="https://realpython.com/python-requests/"><code>requests</code> library</a> to make HTTP calls, which gives you full control over the API interactions without requiring a specific <a href="https://en.wikipedia.org/wiki/Software_development_kit">SDK</a>. This approach works with any HTTP client and keeps your code simple and transparent.</p> <p>First, create a new directory for your project and set up a <a href="https://realpython.com/python-virtual-environments-a-primer/">virtual environment</a>. This isolates your project dependencies from your system Python installation:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>mkdir<span class="w"> </span>openrouter-project/ <span class="gp">$ </span><span class="nb">cd</span><span class="w"> </span>openrouter-project/ <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>venv<span class="w"> </span>venv/ </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Now, you can activate the virtual environment:</p> <ul class="nav nav-tabs justify-content-end js-platform-widget-tabs" role="tablist"> <li class="nav-item mb-0 js-platform-widget-tab-windows" role="presentation"> <a class="nav-link link-unstyled text-body active small" id="windows-tab-1" data-toggle="tab" href="#windows-1" role="tab" aria-controls="windows-1" aria-selected="true"><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#brands--windows"></use></svg></span>Windows</a> </li> <li class="nav-item mb-0 js-platform-widget-tab-linuxmacos" role="presentation"> <a class="nav-link link-unstyled text-body small" id="macos-tab-1" data-toggle="tab" href="#linux-macos-1" role="tab" aria-controls="linux-macos-1" aria-selected="false"><span class="icon baseline text-muted" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#v4--linux"></use></svg></span><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#v4--apple"></use></svg></span>Linux + macOS</a> </li> </ul> <div class="tab-content mt-2 mb-0 js-platform-widget-content"> <div aria-labelledby="windows-tab-1" class="tab-pane fade show active" id="windows-1" role="tabpanel"> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">PS&gt; </span><span class="n">venv</span><span class="p">\</span><span class="n">Scripts</span><span class="p">\</span><span class="n">activate</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div> <div aria-labelledby="linux-macos-tab-1" class="tab-pane fade " id="linux-macos-1" role="tabpanel"> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span><span class="nb">source</span><span class="w"> </span>venv/bin/activate </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div> </div> <p>You should see <a href="/ref/stdlib/venv/" class="ref-link">(<code>venv</code>)</a> in your terminal prompt when it’s active. Now you’re ready to install the <code>requests</code> package for conveniently <a href="https://realpython.com/python-requests/">making HTTP calls</a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>requests </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div><h2><a href="https://realpython.com/openrouter-api/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/openrouter-api/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> What Does Python's __init__.py Do? https://realpython.com/courses/init-py/ 2026-03-03T14:00:00+00:00 Learn how Python's __init__.py declares packages, initializes variables, simplifies imports, and controls what gets exported. <p>Python&rsquo;s special <code>__init__.py</code> file marks a directory as a regular Python package and allows you to import its modules. This file runs automatically the first time you import its containing package. You can use it to initialize package-level variables, define functions or classes, and structure the package&rsquo;s namespace clearly for users.</p> <p><strong>By the end of this video course, you&rsquo;ll understand that:</strong></p> <ul> <li>A directory <strong>without an <code>__init__.py</code> file</strong> becomes a <strong>namespace package</strong>, which behaves differently from a regular package and may cause slower imports.</li> <li>You can use <code>__init__.py</code> to explicitly define a package&rsquo;s <strong>public API</strong> by importing specific modules or functions into the package namespace.</li> <li>The Python convention of using <strong>leading underscores</strong> helps indicate to users which objects are intended as <strong>non-public</strong>, although this convention can still be bypassed.</li> <li>Code inside <code>__init__.py</code> runs <strong>only once</strong> during the first import, even if you run the import statement multiple times.</li> </ul> <p>Understanding how to effectively use <code>__init__.py</code> helps you structure your Python packages in a clear, maintainable way, improving usability and namespace management.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Automate Python Data Analysis With YData Profiling https://realpython.com/ydata-profiling-eda/ 2026-03-02T14:00:00+00:00 Automate exploratory data analysis by transforming DataFrames into interactive reports with one command from YData Profiling. <div><p>The YData Profiling package generates an exploratory data analysis (EDA) report with a few lines of code. The report provides dataset and column-level analysis, including plots and summary statistics to help you quickly understand your dataset. These reports can be exported to HTML or JSON so you can share them with other stakeholders.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li><strong>YData Profiling generates interactive reports</strong> containing EDA results, including summary statistics, visualizations, correlation matrices, and data quality warnings from DataFrames.</li> <li><strong><code>ProfileReport</code> creates a profile</strong> you can save with <code>.to_file()</code> for HTML or JSON export, or display inline with <code>.to_notebook_iframe()</code>.</li> <li>Setting <code>tsmode=True</code> and specifying a date column with <code>sortby</code> <strong>enables time series analysis</strong>, including stationarity tests and seasonality detection.</li> <li><strong>The <code>.compare()</code> method generates side-by-side reports</strong> highlighting distribution shifts and statistical differences between datasets.</li> </ul> <p>To get the most out of this tutorial, you’ll benefit from having knowledge of <a href="https://realpython.com/learning-paths/pandas-data-science/">pandas</a>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> The examples in this tutorial were tested using Python <a href="https://realpython.com/python313-new-features/">3.13</a>. Additionally, you may need to install <code>setuptools&lt;81</code> for backward compatibility.</p> </div> <p>You can install this package using <a href="/ref/glossary/pip/" class="ref-link"><code>pip</code></a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>ydata-profiling </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Once installed, you’re ready to transform any <a href="https://realpython.com/pandas-dataframe/">pandas DataFrame</a> into an interactive report. To follow along, download the example dataset you’ll work with by clicking the link below:</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/ydata-profiling-eda-code/" class="alert-link" data-toggle="modal" data-target="#modal-ydata-profiling-eda-code" markdown>Click here to download the free sample code</a> and start automating Python data analysis with YData Profiling.</p> </div> <p>The following example generates a profiling report from the 2024 flight delay dataset and saves it to disk:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="python"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <span class="mr-2" aria-label="Filename"><code style="color: inherit; background: inherit;">flight_report.py</code></span> <div class="noselect"> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">pandas</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">pd</span> <span class="kn">from</span><span class="w"> </span><span class="nn">ydata_profiling</span><span class="w"> </span><span class="kn">import</span> <span class="n">ProfileReport</span> <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="s2">"flight_data_2024_sample.csv"</span><span class="p">)</span> <span class="n">profile</span> <span class="o">=</span> <span class="n">ProfileReport</span><span class="p">(</span><span class="n">df</span><span class="p">)</span> <span class="n">profile</span><span class="o">.</span><span class="n">to_file</span><span class="p">(</span><span class="s2">"flight_report.html"</span><span class="p">)</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>This <a href="/ref/glossary/source-code/" class="ref-link">code</a> generates an HTML file containing interactive visualizations, statistical summaries, and data quality warnings:</p> <figure class="js-lightbox"><a href="https://files.realpython.com/media/report-overview.c5b7b1fa2ba4.png" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block " src="https://files.realpython.com/media/report-overview.c5b7b1fa2ba4.png" width="2225" height="995" srcset="/cdn-cgi/image/width=556,format=auto/https://files.realpython.com/media/report-overview.c5b7b1fa2ba4.png 556w, /cdn-cgi/image/width=741,format=auto/https://files.realpython.com/media/report-overview.c5b7b1fa2ba4.png 741w, /cdn-cgi/image/width=1112,format=auto/https://files.realpython.com/media/report-overview.c5b7b1fa2ba4.png 1112w, /cdn-cgi/image/width=2225,format=auto/https://files.realpython.com/media/report-overview.c5b7b1fa2ba4.png 2225w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Dataset overview displaying statistics and variable types. Statistics include 35 variables, 10,000 observations, and 3.2% missing cells. Variable types: 5 categorical, 23 numeric, 1 DateTime, 6 text." data-asset="6762"></a></figure> <p>You can open the file in any browser to explore your data’s characteristics without writing additional analysis code.</p> <p>There are a number of tools available for high-level dataset exploration, but not all are built for the same purpose. The following table highlights a few common options and when each one is a good fit:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use case</th> <th>Pick</th> <th>Best for</th> </tr> </thead> <tbody> <tr> <td>You want to quickly generate an exploratory report</td> <td><code>ydata-profiling</code></td> <td>Generating exploratory data analysis reports with visualizations</td> </tr> <tr> <td>You want an overview of a large dataset</td> <td><code>skimpy</code> or <code>df.describe()</code></td> <td>Providing fast, lightweight summaries in the console</td> </tr> <tr> <td>You want to enforce data quality</td> <td><code>pandera</code></td> <td>Validating schemas and catching errors in data pipelines</td> </tr> </tbody> </table> </div> <p>Overall, <a href="https://docs.profiling.ydata.ai/latest/">YData Profiling</a> is best used as an exploratory report creation tool. If you’re looking to generate an overview for a large dataset, using <a href="https://aeturrell.github.io/skimpy/">SkimPy</a> or a built-in <a href="/ref/glossary/dataframe/" class="ref-link">DataFrame</a> library method may be more efficient. Other tools, like <a href="https://pandera.readthedocs.io/en/stable/">Pandera</a>, are more appropriate for data validation.</p> <p>If YData Profiling looks like the right choice for your use case, then keep reading to learn about its most important features.</p> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Automate Python Data Analysis With YData Profiling” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/ydata-profiling-eda/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #b9abe6;" alt="Automate Python Data Analysis With YData Profiling" src="https://files.realpython.com/media/YData-Profiling-One-Click-EDA_Watermarked.dd7cbf2e0693.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/YData-Profiling-One-Click-EDA_Watermarked.dd7cbf2e0693.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/YData-Profiling-One-Click-EDA_Watermarked.dd7cbf2e0693.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/YData-Profiling-One-Click-EDA_Watermarked.dd7cbf2e0693.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/YData-Profiling-One-Click-EDA_Watermarked.dd7cbf2e0693.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/ydata-profiling-eda/" class="stretched-link"><span class="my-0 h4">Automate Python Data Analysis With YData Profiling</span></a> <p class="text-muted mb-0 small">Test your knowledge of YData Profiling, including report creation, customization, performance optimization, time series analysis, and comparisons.</p> </div> </div> </div> <h2 id="building-a-report-with-ydata-profiling">Building a Report With YData Profiling<a class="headerlink" href="#building-a-report-with-ydata-profiling" title="Permanent link"></a></h2> </div><h2><a href="https://realpython.com/ydata-profiling-eda/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/ydata-profiling-eda/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #286: Overcoming Testing Obstacles With Python's Mock Object Library https://realpython.com/podcasts/rpp/286/ 2026-02-27T12:00:00+00:00 Do you have complex logic and unpredictable dependencies that make it hard to write reliable tests? How can you use Python's mock object library to improve your tests? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects. <p>Do you have complex logic and unpredictable dependencies that make it hard to write reliable tests? How can you use Python's mock object library to improve your tests? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> How to Run Your Python Scripts and Code https://realpython.com/run-python-scripts/ 2026-02-25T14:00:00+00:00 Learn how to run Python scripts from the command line, REPL, IDEs, and file managers on Windows, Linux, and macOS. Master all execution approaches. <div><p>Running Python scripts is essential for executing your code. You can run Python scripts from the command line using <code>python script.py</code>, directly by making files executable with shebangs on Unix systems, or through IDEs and code editors. Python also supports interactive execution through the standard REPL for testing code snippets.</p> <p>This tutorial covers the most common practical approaches for running Python scripts across Windows, Linux, and macOS.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li>The <strong><code>python</code></strong> command followed by a <strong>script filename</strong> executes the code from the <strong>command line</strong> on all operating systems.</li> <li>Script mode runs code from <strong>files sequentially</strong>, while interactive mode uses the <strong>REPL</strong> for execution and testing with immediate feedback.</li> <li>Unix systems require <strong>executable permissions</strong> and a <strong>shebang line</strong> like <code>#!/usr/bin/env python3</code> to run scripts directly as programs.</li> <li>The <code>python</code> command’s <code>-m</code> option runs <strong>Python modules</strong> by searching <code>sys.path</code> rather than requiring file paths.</li> <li>IDEs like PyCharm and code editors like Visual Studio Code provide built-in options to <strong>run scripts</strong> from the environment interface.</li> </ul> <p>To get the most out of this tutorial, you should know the basics of working with your operating system’s <a href="https://realpython.com/terminal-commands/">terminal</a> and file manager. It’d also be beneficial to be familiar with a Python-friendly <a href="https://realpython.com/python-ides-code-editors-guide/">IDE or code editor</a> and with the standard Python <a href="https://realpython.com/python-repl/">REPL</a> (Read-Eval-Print Loop).</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Free Download:</strong> <a href="https://realpython.com/bonus/python-tricks-sample-pdf/" class="alert-link" data-toggle="modal" data-target="#modal-python-tricks-sample-pdf" markdown>Get a sample chapter from Python Tricks: The Book</a> that shows you Python’s best practices with simple examples you can apply instantly to write more beautiful + Pythonic code.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “How to Run Your Python Scripts” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/run-python-scripts/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #e6c7ab;" alt="How to Run Your Python Scripts" src="https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/run-python-scripts/" class="stretched-link"><span class="my-0 h4">How to Run Your Python Scripts</span></a> <p class="text-muted mb-0 small">One of the most important skills you need to build as a Python developer is to be able to run Python scripts and code. Test your understanding on how good you are with running your code.</p> </div> </div> </div> <h2 id="what-scripts-and-modules-are">What Scripts and Modules Are<a class="headerlink" href="#what-scripts-and-modules-are" title="Permanent link"></a></h2> <p>In computing, the term <strong>script</strong> refers to a text file containing a logical sequence of orders that you can run to accomplish a specific task. These orders are typically expressed in a <a href="https://en.wikipedia.org/wiki/Scripting_language">scripting language</a>, which is a <a href="https://en.wikipedia.org/wiki/Programming_language">programming language</a> that allows you to manipulate, customize, and automate tasks.</p> <p>Scripting languages are usually <a href="https://en.wikipedia.org/wiki/Interpreter_(computing)">interpreted</a> at <a href="https://en.wikipedia.org/wiki/Runtime_(program_lifecycle_phase)">runtime</a> rather than <a href="https://en.wikipedia.org/wiki/Compiler">compiled</a>. So, scripts are typically run by an <a href="/ref/glossary/interpreter/" class="ref-link">interpreter</a>, which is responsible for executing each order in a sequence.</p> <p><a href="/ref/glossary/python/" class="ref-link">Python</a> is an interpreted language. Because of that, Python programs are commonly called scripts. However, this terminology isn’t completely accurate because Python programs can be way more complex than a simple, sequential script.</p> <p>In general, a <a href="/ref/glossary/text-file/" class="ref-link">file</a> containing executable Python <a href="/ref/glossary/source-code/" class="ref-link">code</a> is called a script—or an <strong>entry-point script</strong> in more complex applications—which is a common term for a top-level <strong>program</strong>. On the other hand, a file containing Python code that’s designed to be <a href="https://realpython.com/python-import/">imported</a> and used from another Python file is called a <a href="/ref/glossary/module/" class="ref-link"><strong>module</strong></a>.</p> <p>So, the main difference between a <a href="https://realpython.com/python-modules-packages/">module</a> and a script is that modules store <strong>importable code</strong> while scripts hold <strong>executable code</strong>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> Importable code is code that defines something but doesn’t perform a specific action. Some examples include <a href="/ref/glossary/function/" class="ref-link">function</a> and <a href="/ref/glossary/class/" class="ref-link">class</a> definitions. In contrast, executable code is code that performs specific actions. Some examples include <a href="https://realpython.com/defining-your-own-python-function/#calling-functions-in-python">function calls</a>, <a href="/ref/glossary/loop/" class="ref-link">loops</a>, and <a href="https://realpython.com/python-conditional-statements/">conditionals</a>.</p> </div> <p>In the following sections, you’ll learn how to run Python scripts, programs, and code in general. To kick things off, you’ll start by learning how to run them from your operating system’s command line or terminal.</p> <h2 id="how-to-run-python-scripts-from-the-command-line">How to Run Python Scripts From the Command Line<a class="headerlink" href="#how-to-run-python-scripts-from-the-command-line" title="Permanent link"></a></h2> <p>In Python programming, you’ll write programs in plain text files. By convention, files containing Python code use the <code>.py</code> extension, and there’s no distinction between scripts or executable programs and modules. All of them will use the same extension.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> On <a href="https://realpython.com/python-coding-setup-windows/">Windows</a> systems, the extension can also be <code>.pyw</code> for those applications that should use the <code>pythonw.exe</code> launcher.</p> </div> <p>To create a Python script, you can use any Python-friendly <a href="https://realpython.com/python-ides-code-editors-guide/">code editor or IDE</a> (integrated development environment). To keep moving forward in this tutorial, you’ll need to create a basic script, so fire up your favorite text editor and create a new <code>hello.py</code> file containing the following code:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="python"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <span class="mr-2" aria-label="Filename"><code style="color: inherit; background: inherit;">hello.py</code></span> <div class="noselect"> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">"Hello, World!"</span><span class="p">)</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>This is the classic <code>"Hello, World!"</code> program in Python. The executable code consists of a call to the built-in <a href="https://realpython.com/python-print/"><code>print()</code></a> function that displays the <code>"Hello, World!"</code> message on your screen.</p> <p>With this small program in place, you’re ready to learn different ways to run it. You’ll start by running the program from your command line, which is arguably the most commonly used approach to running scripts.</p> <h3 id="using-the-python-command">Using the <code>python</code> Command<a class="headerlink" href="#using-the-python-command" title="Permanent link"></a></h3> <p>To run Python scripts with the <code>python</code> command, you need to open a command-line window and type in the word <code>python</code> followed by the path to your target script:</p> <ul class="nav nav-tabs justify-content-end js-platform-widget-tabs" role="tablist"> <li class="nav-item mb-0 js-platform-widget-tab-windows" role="presentation"> <a class="nav-link link-unstyled text-body active small" id="windows-tab-1" data-toggle="tab" href="#windows-1" role="tab" aria-controls="windows-1" aria-selected="true"><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#brands--windows"></use></svg></span>Windows</a> </li> <li class="nav-item mb-0 js-platform-widget-tab-linuxmacos" role="presentation"> <a class="nav-link link-unstyled text-body small" id="macos-tab-1" data-toggle="tab" href="#linux-macos-1" role="tab" aria-controls="linux-macos-1" aria-selected="false"><span class="icon baseline text-muted" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#v4--linux"></use></svg></span><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#v4--apple"></use></svg></span>Linux + macOS</a> </li> </ul> </div><h2><a href="https://realpython.com/run-python-scripts/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/run-python-scripts/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Start Building With FastAPI https://realpython.com/courses/start-building-with-fastapi/ 2026-02-24T14:00:00+00:00 Learn how to build APIs with FastAPI in Python, including Pydantic models, HTTP methods, CRUD operations, and interactive documentation. <p>FastAPI is a web framework for building APIs with Python. It leverages standard Python type hints to provide automatic validation, serialization, and interactive documentation. When you&rsquo;re deciding between Python web frameworks, FastAPI stands out for its speed, developer experience, and built-in features that reduce boilerplate code for API development:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th class="text-center">Pick FastAPI</th> <th class="text-center">Pick Flask or Django</th> </tr> </thead> <tbody> <tr> <td>You want to build an API-driven web app</td> <td class="text-center">✅</td> <td class="text-center">—</td> </tr> <tr> <td>You need a full-stack web framework</td> <td class="text-center">—</td> <td class="text-center">✅</td> </tr> <tr> <td>You value automatic API documentation</td> <td class="text-center">✅</td> <td class="text-center">—</td> </tr> </tbody> </table> </div> <p>Whether you&rsquo;re building a minimal <a href="https://realpython.com/api-integration-in-python/">REST API</a> or a complex backend service, understanding core features of <a href="https://fastapi.tiangolo.com/">FastAPI</a> will help you make an informed decision about adopting it for your projects. To get the most from this video course, you&rsquo;ll benefit from having basic knowledge of Python <a href="https://realpython.com/defining-your-own-python-function/">functions</a>, <a href="https://realpython.com/python-requests/">HTTP concepts</a>, and <a href="https://realpython.com/python-json/">JSON</a> handling.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Python for Loops: The Pythonic Way https://realpython.com/python-for-loop/ 2026-02-23T14:00:00+00:00 Learn how to use Python for loops to iterate over lists, tuples, strings, and dictionaries with Pythonic looping techniques. <div><p>Python’s <code>for</code> loop allows you to iterate over the items in a collection, such as lists, tuples, strings, and dictionaries. The <code>for</code> loop syntax declares a loop variable that takes each item from the collection in each iteration. This loop is ideal for repeatedly executing a block of code on each item in the collection. You can also tweak <code>for</code> loops further with features like <code>break</code>, <code>continue</code>, and <code>else</code>.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li><strong>Python’s <code>for</code> loop</strong> iterates over items in a data collection, allowing you to execute code for each item.</li> <li>To <strong>iterate from <code>0</code> to <code>10</code></strong>, you use the <code>for index in range(11):</code> construct.</li> <li>To <strong>repeat code a number of times</strong> without processing the data of an iterable, use the <code>for _ in range(times):</code> construct.</li> <li>To do <strong>index-based iteration</strong>, you can use <code>for index, value in enumerate(iterable):</code> to access both index and item.</li> </ul> <p>In this tutorial, you’ll gain practical knowledge of using <code>for</code> loops to traverse various collections and learn Pythonic looping techniques. You’ll also learn how to handle exceptions and use asynchronous iterations to make your Python code more robust and efficient.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/python-for-loop-code/" class="alert-link" data-toggle="modal" data-target="#modal-python-for-loop-code" markdown>Click here to download the free sample code</a> that shows you how to use for loops in Python.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Python for Loops: The Pythonic Way” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/python-for-loop/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #abe0e6;" alt="Python for Loops: The Pythonic Way" src="https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/python-for-loop/" class="stretched-link"><span class="my-0 h4">Python for Loops: The Pythonic Way</span></a> <p class="text-muted mb-0 small">In this quiz, you'll test your understanding of Python's for loop. You'll revisit how to iterate over items in a data collection, how to use range() for a predefined number of iterations, and how to use enumerate() for index-based iteration.</p> </div> </div> </div> <h2 id="getting-started-with-the-python-for-loop">Getting Started With the Python <code>for</code> Loop<a class="headerlink" href="#getting-started-with-the-python-for-loop" title="Permanent link"></a></h2> <p>In programming, <a href="/ref/glossary/loop/" class="ref-link"><strong>loops</strong></a> are <a href="https://realpython.com/python-control-flow/">control flow</a> <a href="/ref/glossary/statement/" class="ref-link">statements</a> that allow you to repeat a given set of operations a number of times. In practice, you’ll find two main types of loops:</p> <ol> <li><a href="https://en.wikipedia.org/wiki/For_loop"><code>for</code> loops</a> are mostly used to iterate a <em>known</em> number of times, which is common when you’re processing data <a href="/ref/glossary/collection/" class="ref-link">collections</a> with a specific number of data items.</li> <li><a href="https://realpython.com/python-while-loop/"><code>while</code> loops</a> are commonly used to iterate an <em>unknown</em> number of times, which is useful when the number of <a href="/ref/glossary/iteration/" class="ref-link">iterations</a> depends on a given condition.</li> </ol> <p>Python has both of these loops and in this tutorial, you’ll learn about <strong><code>for</code> loops</strong>. In Python, you’ll generally use <code>for</code> loops when you need to iterate over the items in a data collection. This type of loop lets you traverse different data collections and run a specific group of statements <em>on</em> or <em>with</em> each item in the input collection.</p> <p>In Python, <code>for</code> loops are <a href="https://docs.python.org/3/reference/compound_stmts.html">compound statements</a> with a <em>header</em> and a <em>code block</em> that runs a predefined number of times. The basic syntax of a <code>for</code> loop is shown below:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="python_syntax"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python Syntax</span> <div class="noselect"> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="k">for</span> <span class="n">variable</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">body</span><span class="o">&gt;</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>In this syntax, <code>variable</code> is the loop <a href="/ref/glossary/variable/" class="ref-link">variable</a>. In each iteration, this variable takes the value of the current item in <code>iterable</code>, which represents the data collection you need to iterate over. The loop body can consist of one or more statements that must be indented properly.</p> <p>Here’s a more detailed breakdown of this syntax:</p> <ul> <li><strong><code>for</code></strong> is the keyword that initiates the loop header.</li> <li><strong><code>variable</code></strong> is a variable that holds the current item in the input <a href="/ref/glossary/iterable/" class="ref-link">iterable</a>.</li> <li><strong><code>in</code></strong> is a keyword that connects the loop variable with the iterable.</li> <li><strong><code>iterable</code></strong> is a data collection that can be iterated over.</li> <li><strong><code>&lt;body&gt;</code></strong> consists of one or more statements to execute in each iteration.</li> </ul> <p>Here’s a quick example of how you can use a <code>for</code> loop to iterate over a <a href="/ref/builtin-types/list/" class="ref-link"><code>list</code></a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n">colors</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"red"</span><span class="p">,</span> <span class="s2">"green"</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">,</span> <span class="s2">"yellow"</span><span class="p">]</span> <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">color</span> <span class="ow">in</span> <span class="n">colors</span><span class="p">:</span> <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">color</span><span class="p">)</span> <span class="gp">...</span> <span class="go">red</span> <span class="go">green</span> <span class="go">blue</span> <span class="go">yellow</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>In this example, <code>color</code> is the loop variable, while the <code>colors</code> list is the target collection. Each time through the loop, <code>color</code> takes on a successive item from <code>colors</code>. In this loop, the body consists of a call to <a href="https://realpython.com/python-print/"><code>print()</code></a> that displays the value on the screen. This loop runs once for each item in the target iterable. The way the code above is written is the <a href="https://realpython.com/learning-paths/writing-pythonic-code/">Pythonic</a> way to write it.</p> <p>However, what’s an <a href="https://realpython.com/python-iterators-iterables/#getting-to-know-python-iterables">iterable</a> anyway? In Python, an <strong>iterable</strong> is an object—often a data collection—that can be iterated over. Common examples of iterables in Python include <a href="https://realpython.com/python-list/">lists</a>, <a href="https://realpython.com/python-tuple/">tuples</a>, <a href="https://realpython.com/python-strings/">strings</a>, <a href="https://realpython.com/python-dicts/">dictionaries</a>, and <a href="https://realpython.com/python-sets/">sets</a>, which are all built-in data types. You can also have custom classes that support iteration.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> Python has both iterables and iterators. Iterables support the <strong>iterable protocol</strong> consisting of the <code>.__iter__()</code> <a href="https://realpython.com/python-magic-methods/">special method</a>. Similarly, iterators support the <strong>iterator protocol</strong> that’s based on the <code>.__iter__()</code> and <code>.__next__()</code> special methods.</p> <p>Both iterables and iterators can be iterated over. All iterators are iterables, but not all iterables are iterators. Python iterators play a fundamental role in <code>for</code> loops because they drive the iteration process.</p> <p>A deeper discussion on iterables and iterators is beyond the scope of this tutorial. However, to learn more about them, check out the <a href="https://realpython.com/python-iterators-iterables/">Iterators and Iterables in Python: Run Efficient Iterations</a> tutorial.</p> </div> <p>You can also have a loop with multiple loop variables:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n">points</span> <span class="o">=</span> <span class="p">[(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">3</span><span class="p">)]</span> <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">points</span><span class="p">:</span> <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="si">= }</span><span class="s2"> and </span><span class="si">{</span><span class="n">y</span><span class="w"> </span><span class="si">= }</span><span class="s2">"</span><span class="p">)</span> <span class="gp">...</span> <span class="go">x = 1 and y = 4</span> <span class="go">x = 3 and y = 6</span> <span class="go">x = 7 and y = 3</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>In this loop, you have two loop variables, <code>x</code> and <code>y</code>. Note that to use this syntax, you just need to provide a tuple of loop variables. Also, you can have as many loop variables as you need as long as you have the correct number of items to <a href="https://realpython.com/python-tuple/#packing-and-unpacking-tuples">unpack</a> into them. You’ll also find this pattern useful when iterating over <a href="#collections-dictionaries-and-sets">dictionary</a> items or when you need to do <a href="#looping-over-several-iterables-in-parallel">parallel iteration</a>.</p> <p>Sometimes, the input iterable may be empty. In that case, the loop will run its header once but won’t execute its body:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="p">[]:</span> <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="gp">...</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div><h2><a href="https://realpython.com/python-for-loop/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-for-loop/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #285: Exploring MCP Apps & Adding Interactive UIs to Clients https://realpython.com/podcasts/rpp/285/ 2026-02-20T12:00:00+00:00 How can you move your MCP tools beyond plain text? How do you add interactive UI components directly inside chat conversations? This week on the show, Den Delimarsky from Anthropic joins us to discuss MCP Apps and interactive UIs in MCP. <p>How can you move your MCP tools beyond plain text? How do you add interactive UI components directly inside chat conversations? This week on the show, Den Delimarsky from Anthropic joins us to discuss MCP Apps and interactive UIs in MCP.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> How to Install Python on Your System: A Guide https://realpython.com/installing-python/ 2026-02-18T14:00:00+00:00 Learn how to install the latest Python version on Windows, macOS, and Linux. Check your version and choose the best installation method for your system. <div><p>To learn how to install Python on your system, you can follow a few straightforward steps. First, check if Python is already installed by opening a command-line interface and typing <code>python --version</code> or <code>python3 --version</code>.</p> <p>You can install Python on Windows using the official installer from Python.org or through the Microsoft Store. On macOS, you can use the official installer or Homebrew. For Linux, use your package manager or build Python from source.</p> <p><strong>By the end of this tutorial, you’ll understand how to:</strong></p> <ul> <li><strong>Check if Python is installed</strong> by running <code>python --version</code> or <code>python3 --version</code> in a command-line interface.</li> <li><strong>Upgrade Python</strong> by downloading and installing the latest version from Python.org.</li> <li><strong>Install and manage multiple Python versions</strong> with <code>pyenv</code> to keep them separate.</li> </ul> <p>This tutorial covers installing the latest Python on the most important platforms or operating systems, such as Windows, macOS, Linux, iOS, and Android. However, it doesn’t cover all the existing Linux distributions, as that would be a massive task. Nevertheless, you’ll find instructions for the most popular distributions available today.</p> <p>To get the most out of this tutorial, you should be comfortable using your operating system’s <a href="https://realpython.com/terminal-commands/">terminal</a> or command line.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Free Bonus:</strong> <a href="https://realpython.com/bonus/python-cheat-sheet-shortened/" class="alert-link" data-toggle="modal" data-target="#modal-python-cheat-sheet-shortened" markdown>Click here to get a Python Cheat Sheet</a> and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “How to Install Python on Your System: A Guide” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/python-installation-and-setup/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #b9abe6;" alt="Python 3 Installation &amp; Setup Guide" src="https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/python-installation-and-setup/" class="stretched-link"><span class="my-0 h4">How to Install Python on Your System: A Guide</span></a> <p class="text-muted mb-0 small">In this quiz, you'll test your understanding of how to install or update Python on your computer. With this knowledge, you'll be able to set up Python on various operating systems, including Windows, macOS, and Linux.</p> </div> </div> </div> <h2 id="windows-how-to-check-or-get-python">Windows: How to Check or Get Python<a class="headerlink" href="#windows-how-to-check-or-get-python" title="Permanent link"></a></h2> <p>In this section, you’ll learn to check whether Python is installed on your Windows operating system (OS) and which version you have. You’ll also explore three installation options that you can use on Windows.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> In this tutorial, you’ll focus on installing the latest version of Python in your current operating system (OS) rather than on installing multiple versions of Python. If you want to install several versions of Python in your OS, then check out the <a href="https://realpython.com/intro-to-pyenv/">Managing Multiple Python Versions With <code>pyenv</code></a> tutorial. Note that on Windows machines, you’d have to use <a href="https://github.com/pyenv-win/pyenv-win"><code>pyenv-win</code></a> instead of <code>pyenv</code>.</p> </div> <p>For a more comprehensive guide on setting up a Windows machine for Python programming, check out <a href="https://realpython.com/python-coding-setup-windows/">Your Python Coding Environment on Windows: Setup Guide</a>.</p> <h3 id="checking-the-python-version-on-windows">Checking the Python Version on Windows<a class="headerlink" href="#checking-the-python-version-on-windows" title="Permanent link"></a></h3> <p>To check whether you already have Python on your Windows machine, open a command-line application like <a href="https://realpython.com/python-coding-setup-windows/#installing-powershell-core">PowerShell</a> or the <a href="https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab">Windows Terminal</a>.</p> <p>Follow the steps below to open PowerShell on Windows:</p> <ol> <li>Press the <span class="keys"><kbd class="key-windows">Win</kbd></span> key.</li> <li>Type <code>PowerShell</code>.</li> <li>Press <span class="keys"><kbd class="key-enter">Enter</kbd></span>.</li> </ol> <p>Alternatively, you can right-click the <em>Start</em> button and select <em>Windows PowerShell</em> or <em>Windows PowerShell (Admin)</em>. In some versions of Windows, you’ll find <em>Terminal</em> or <em>Terminal (admin)</em>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> To learn more about your options for the Windows terminal, check out <a href="https://realpython.com/python-coding-setup-windows/">Your Python Coding Environment on Windows: Setup Guide</a>.</p> </div> <p>With the command line open, type in the following command and press the <span class="keys"><kbd class="key-enter">Enter</kbd></span> key:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">PS&gt; </span><span class="n">python</span> <span class="p">-</span><span class="n">-version</span> <span class="go">Python 3.x.z</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Using the <code>--version</code> switch will show you the installed version. Note that the <code>3.x.z</code> part is a placeholder here. In your machine, <code>x</code> and <code>z</code> will be numbers corresponding to the specific version you have installed.</p> <p>Alternatively, you can use the <code>-V</code> switch:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">PS&gt; </span><span class="n">python</span> <span class="n">-V</span> <span class="go">Python 3.x.z</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>You can also use the <code>py</code> launcher, which is the Python launcher for Windows and is especially helpful if you plan to work with multiple Python versions:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">PS&gt; </span><span class="n">py</span> <span class="p">-</span><span class="n">-version</span> <span class="go">Python 3.x.z</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> </div><h2><a href="https://realpython.com/installing-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/installing-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Write Python Docstrings Effectively https://realpython.com/courses/write-python-docstrings-effectively/ 2026-02-17T14:00:00+00:00 Learn to write clear, effective Python docstrings using best practices, common styles, and built-in conventions for your code. <p>Writing clear, consistent docstrings in Python helps others understand your code&rsquo;s purpose, parameters, and outputs. In this video course, you&rsquo;ll learn about best practices, standard formats, and common pitfalls to avoid, ensuring your documentation is accessible to users and tools alike.</p> <p><strong>By the end of this video course, you&rsquo;ll understand that:</strong></p> <ul> <li>Docstrings are strings used to <strong>document your Python code</strong> and can be accessed at runtime.</li> <li>Python <strong>comments and docstrings</strong> have important differences.</li> <li><strong>One-line</strong> and <strong>multiline docstrings</strong> are classifications of docstrings.</li> <li>Common docstring formats include <strong>reStructuredText</strong>, <strong>Google-style</strong>, <strong>NumPy-style</strong>, and <strong>doctest-style</strong>.</li> <li><strong>Antipatterns</strong> such as inconsistent formatting <strong>should be avoided</strong> when writing docstrings.</li> </ul> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> TinyDB: A Lightweight JSON Database for Small Projects https://realpython.com/tinydb-python/ 2026-02-16T14:00:00+00:00 If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be exactly what you need. <div><p>TinyDB is a Python implementation of a NoSQL, document-oriented database. Unlike a traditional relational database, which stores records across multiple linked tables, a document-oriented database stores its information as separate documents in a key-value structure. The keys are similar to the field headings, or attributes, in a relational database table, while the values are similar to the table’s attribute values.</p> <p>TinyDB uses the familiar Python <strong>dictionary</strong> for its document structure and stores its documents in a <strong>JSON file</strong>.</p> <p>TinyDB is written in Python, making it easily extensible and customizable, with no external dependencies or server setup needed. Despite its small footprint, it still fully supports the familiar database <a href="https://realpython.com/crud-operations/">CRUD features</a> of creating, reading, updating, and deleting documents using an <a href="/ref/glossary/api/" class="ref-link">API</a> that’s logical to use.</p> <p>The table below will help you decide whether TinyDB is a good fit for your use case:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th class="text-center">TinyDB</th> <th>Possible Alternatives</th> </tr> </thead> <tbody> <tr> <td>Local, small dataset, single-process use (scripts, <a href="https://realpython.com/command-line-interfaces-python-argparse/">CLIs</a>, prototypes)</td> <td class="text-center">✅</td> <td><a href="https://github.com/Milkman337/simpleJDB/">simpleJDB</a>, Python’s <a href="https://realpython.com/python-json/"><code>json</code> module</a>, <a href="https://realpython.com/python-sqlite-sqlalchemy/">SQLite</a></td> </tr> <tr> <td>Local use that requires SQL, constraints, joins, or stronger durability</td> <td class="text-center">—</td> <td>SQLite, <a href="https://realpython.com/python-sql-libraries/">PostgreSQL</a></td> </tr> <tr> <td>Multi-user, multi-process, distributed, or production-scale systems</td> <td class="text-center">—</td> <td>PostgreSQL, <a href="https://realpython.com/python-mysql/">MySQL</a>, <a href="https://realpython.com/introduction-to-mongodb-and-python/">MongoDB</a></td> </tr> </tbody> </table> </div> <p>Whether you’re looking to use a small NoSQL database in one of your projects or you’re just curious how a lightweight database like TinyDB works, this tutorial is for you. By the end, you’ll have a clear sense of when TinyDB shines, and when it’s better to reach for something else.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/tinydb-python-code/" class="alert-link" data-toggle="modal" data-target="#modal-tinydb-python-code" markdown>Click here to download the free sample code</a> you’ll use in this tutorial to explore TinyDB.</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “TinyDB: A Lightweight JSON Database for Small Projects” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/tinydb-python/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #b9abe6;" alt="TinyDB: A Lightweight JSON Database for Small Projects" src="https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/tinydb-python/" class="stretched-link"><span class="my-0 h4">TinyDB: A Lightweight JSON Database for Small Projects</span></a> <p class="text-muted mb-0 small">If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be what you need.</p> </div> </div> </div> <h2 id="get-ready-to-explore-tinydb">Get Ready to Explore TinyDB<a class="headerlink" href="#get-ready-to-explore-tinydb" title="Permanent link"></a></h2> <p>TinyDB is a standalone library, meaning it doesn’t rely on any other libraries to work. You’ll need to install it, though.</p> <p>You’ll also use the <a href="https://realpython.com/python-pretty-print/"><code>pprint</code></a> module to format <a href="https://realpython.com/python-dicts/">dictionary</a> documents for easier reading, and Python’s <a href="/ref/stdlib/csv/" class="ref-link"><code>csv</code></a> module to work with <a href="https://realpython.com/python-interview-problem-parsing-csv-files/">CSV</a> files. You don’t need to install either of these because they’re included in Python’s <a href="/ref/glossary/standard-library/" class="ref-link">standard library</a>.</p> <p>So to follow along, you only need to install the TinyDB library in your environment. First, <a href="https://realpython.com/python-virtual-environments-a-primer/">create and activate a virtual environment</a>, then install the library using <a href="/ref/glossary/pip/" class="ref-link"><code>pip</code></a>:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true"> <div class="codeblock__header codeblock--yellow"> <span class="mr-2 noselect" aria-label="Language">Shell</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>tinydb </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Alternatively, you could set up a small <a href="https://realpython.com/python-pyproject-toml/"><code>pyproject.toml</code> file</a> and <a href="https://realpython.com/python-uv/">manage your dependencies using <code>uv</code></a>.</p> <p>When you add documents to your database, you often do so manually by creating Python dictionaries. In this tutorial, you’ll do this, and also learn how to work with documents already stored in a <a href="https://realpython.com/python-json/">JSON</a> file. You’ll even learn how to add documents from data stored in a CSV file.</p> <p>These files will be highlighted as needed and are available in this tutorial’s downloads. You might want to download them to your program folder before you start to keep them handy:</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/tinydb-python-code/" class="alert-link" data-toggle="modal" data-target="#modal-tinydb-python-code" markdown>Click here to download the free sample code</a> you’ll use in this tutorial to explore TinyDB.</p> </div> <p>Regardless of the files you use or the documents you create manually, they all rely on the same world population data. Each document will contain up to six fields, which become the dictionary keys used when the associated values are added to your database:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Field</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>continent</code></td> <td>The continent the country belongs to</td> </tr> <tr> <td><code>location</code></td> <td>Country</td> </tr> <tr> <td><code>date</code></td> <td>Date population count made</td> </tr> <tr> <td><code>% of world</code></td> <td>Percentage of the world’s population</td> </tr> <tr> <td><code>population</code></td> <td>Population</td> </tr> <tr> <td><code>source</code></td> <td>Source of population</td> </tr> </tbody> </table> </div> <p>As mentioned earlier, the four primary database operations are <strong>C</strong>reate, <strong>R</strong>ead, <strong>U</strong>pdate, and <strong>D</strong>elete—collectively known as the <a href="https://realpython.com/crud-operations/">CRUD operations</a>. In the next section, you’ll learn how you can perform each of them.</p> <p>To begin with, you’ll explore the <em>C</em> in CRUD. It’s time to get creative.</p> <h2 id="create-your-database-and-documents">Create Your Database and Documents<a class="headerlink" href="#create-your-database-and-documents" title="Permanent link"></a></h2> <p>The first thing you’ll do is <strong>create</strong> a new database and add some documents to it. To do this, you create a <code>TinyDB()</code> <a href="/ref/glossary/object/" class="ref-link">object</a> that includes the name of a JSON file to store your data. Any documents you add to the database are then saved in that file.</p> <p>Documents in TinyDB are stored in tables. Although it’s not necessary to create a table manually, doing so can help you organize your documents, especially when working with multiple tables.</p> <p>To start, you create a script named <code>create_db.py</code> that initializes your first database and adds documents in several different ways. The first part of your script looks like this:</p> </div><h2><a href="https://realpython.com/tinydb-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/tinydb-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #284: Running Local LLMs With Ollama and Connecting With Python https://realpython.com/podcasts/rpp/284/ 2026-02-13T12:00:00+00:00 Would you like to learn how to work with LLMs locally on your own computer? How do you integrate your Python projects with a local model? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects. <p>Would you like to learn how to work with LLMs locally on your own computer? How do you integrate your Python projects with a local model? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> What Exactly Is the Zen of Python? https://realpython.com/zen-of-python/ 2026-02-11T14:00:00+00:00 The Zen of Python is a collection of 19 guiding principles for writing good Python code. Learn its history, meaning, and hidden jokes. <div><p>The <strong>Zen of Python</strong> is a collection of 19 aphorisms that capture the guiding principles behind Python’s design. You can display them anytime by running <code>import this</code> in a Python REPL. Tim Peters wrote them in 1999 as a joke, but they became an iconic part of Python culture that was even formalized as <a href="/ref/glossary/pep/" class="ref-link">PEP</a> 20.</p> <p><strong>By the end of this tutorial, you’ll understand:</strong></p> <ul> <li>The Zen of Python is a <strong>humorous poem</strong> of 19 aphorisms describing Python’s design philosophy</li> <li>Running <code>import this</code> in a Python <a href="/ref/glossary/interpreter/" class="ref-link">interpreter</a> displays the <strong>complete text</strong> of the Zen of Python</li> <li><strong>Tim Peters</strong> wrote the Zen of Python in 1999 as a tongue-in-cheek comment on a mailing list</li> <li>The aphorisms are <strong>guidelines, not strict rules</strong>, and some intentionally contradict each other</li> <li>The principles promote <strong>readability, simplicity, and explicitness</strong> while acknowledging that practicality matters</li> </ul> <p>Experienced Pythonistas often refer to the Zen of Python as a source of wisdom and guidance, especially when they want to settle an argument about certain design decisions in a piece of code. In this tutorial, you’ll explore the origins of the Zen of Python, learn how to interpret its mysterious aphorisms, and discover the Easter eggs hidden within it.</p> <p>You don’t need to be a Python master to understand the Zen of Python! But you do need to answer an important question: <strong>What exactly is the Zen of Python?</strong></p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Free Bonus:</strong> <a href="https://realpython.com/bonus/python-easter-eggs/" class="alert-link" data-toggle="modal" data-target="#modal-python-easter-eggs" markdown>Click here to download your Easter egg hunt</a> to discover what’s hidden inside Python!</p> </div> <div class="container border rounded text-wrap-pretty my-3"> <p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “What Exactly Is the Zen of Python?” quiz. You’ll receive a score upon completion to help you track your learning progress:</p> <hr> <div class="row my-3"> <div class="col-xs-12 col-sm-4 col-md-3 align-self-center"> <a href="/quizzes/zen-of-python/" tabindex="-1"> <div class="embed-responsive embed-responsive-16by9"> <img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #b9abe6;" alt="What's the Zen of Python?" src="https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)"> <div class="card-img-overlay d-flex align-items-center"> <div class="mx-auto"> <span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@quiz"></use></svg></span></span> </div> </div> </div> </a> </div> <div class="col"> <div class="mt-3 d-md-none"></div> <p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p> <a href="/quizzes/zen-of-python/" class="stretched-link"><span class="my-0 h4">What Exactly Is the Zen of Python?</span></a> <p class="text-muted mb-0 small">Learn and test the Zen of Python, its guiding aphorisms, and tips for writing clearer, more readable, and maintainable code.</p> </div> </div> </div> <h2 id="in-short-its-a-humorous-poem-listing-python-philosophies">In Short: It’s a Humorous Poem Listing Python Philosophies<a class="headerlink" href="#in-short-its-a-humorous-poem-listing-python-philosophies" title="Permanent link"></a></h2> <p>According to the <a href="https://docs.python.org/3/glossary.html">Python glossary</a>, which contains definitions of popular terms related to this programming language, the <strong>Zen of Python</strong> is a:</p> <blockquote> <p>Listing of Python design principles and philosophies that are helpful in understanding and using the language. The listing can be found by typing “<code>import this</code>” at the interactive prompt. (<a href="https://docs.python.org/3/glossary.html#term-Zen-of-Python">Source</a>)</p> </blockquote> <p>Indeed, when you type the indicated <a href="https://realpython.com/python-import/"><code>import</code> statement</a> into an interactive <a href="https://realpython.com/python-repl/">Python REPL</a>, then you’ll be presented with the nineteen aphorisms that make up the Zen of Python:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python</span> <div class="noselect"> <span class="codeblock__output-toggle" title="Toggle prompts and output" aria-label="Toggle prompts and output" role="button" tabindex="0"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#regular--rectangle-terminal"></use></svg></span></span> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span><span class="w"> </span><span class="nn">this</span> <span class="go">The Zen of Python, by Tim Peters</span> <span class="go">Beautiful is better than ugly.</span> <span class="go">Explicit is better than implicit.</span> <span class="go">Simple is better than complex.</span> <span class="go">Complex is better than complicated.</span> <span class="go">Flat is better than nested.</span> <span class="go">Sparse is better than dense.</span> <span class="go">Readability counts.</span> <span class="go">Special cases aren't special enough to break the rules.</span> <span class="go">Although practicality beats purity.</span> <span class="go">Errors should never pass silently.</span> <span class="go">Unless explicitly silenced.</span> <span class="go">In the face of ambiguity, refuse the temptation to guess.</span> <span class="go">There should be one-- and preferably only one --obvious way to do it.</span> <span class="go">Although that way may not be obvious at first unless you're Dutch.</span> <span class="go">Now is better than never.</span> <span class="go">Although never is often better than *right* now.</span> <span class="go">If the implementation is hard to explain, it's a bad idea.</span> <span class="go">If the implementation is easy to explain, it may be a good idea.</span> <span class="go">Namespaces are one honking great idea -- let's do more of those!</span> </code></pre></div> <button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard" aria-label="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.1fb5b1968c3f.svg#@copy"></use></svg></span></button> </div> </code-block> <p>The byline reveals the poem’s author, <a href="https://en.wikipedia.org/wiki/Tim_Peters_(software_engineer)">Tim Peters</a>, who’s a renowned software engineer and a long-standing <a href="https://realpython.com/cpython-source-code-guide/">CPython</a> core developer best known for inventing the <a href="https://realpython.com/sorting-algorithms-python/#the-timsort-algorithm-in-python">Timsort</a> sorting algorithm. He also authored the <a href="https://realpython.com/python-doctest/"><code>doctest</code></a> and <a href="https://realpython.com/python-timer/#estimating-running-time-with-timeit"><code>timeit</code></a> modules in the Python <a href="/ref/glossary/standard-library/" class="ref-link">standard library</a>, along with making many other contributions.</p> <p>Take your time to read through the Zen of Python and contemplate its wisdom. But don’t take the aphorisms literally, as they’re more of a guiding set of principles rather than strict instructions. You’ll learn about their humorous origins in the next section.</p> <h2 id="how-did-the-zen-of-python-originate">How Did the Zen of Python Originate?<a class="headerlink" href="#how-did-the-zen-of-python-originate" title="Permanent link"></a></h2> <p>The idea of formulating a single document that would encapsulate Python’s fundamental philosophies emerged among the core developers in June 1999. As more and more people began coming to Python from other programming languages, they’d often bring their preconceived notions of software design that weren’t necessarily <a href="https://realpython.com/learning-paths/writing-pythonic-code/">Pythonic</a>. To help them follow the spirit of the language, a set of recommendations for writing idiomatic Python was needed.</p> <p>The initial discussion about creating such a document took place on the Python mailing list under the subject <em>The Python Way</em>. Today, you can find this conversation in the official <a href="https://mail.python.org/pipermail/python-list/1999-June/subject.html">Python-list archive</a>. If you look closely at the <a href="https://mail.python.org/pipermail/python-list/1999-June/001951.html">first message from Tim Peters</a> in that thread, then you’ll notice that he clearly outlined the Zen of Python as a joke. That original form has stuck around until this day:</p> <blockquote> <p>Clearly a job for Guido alone – although I doubt it’s one he’ll take on (fwiw, I wish he would too!). Here’s the outline he would start from, though &lt;wink&gt;:</p> <p>Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one– and preferably only one –obvious way to do it. Although that way may not be obvious at first unless you’re Dutch. Now is better than never. Although never is often better than <em>right</em> now. If the implementation is hard to explain, it’s a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea – let’s do more of those!</p> <p>There you go: 20 Pythonic Fec^H^H^HTheses on the nose, counting the one I’m leaving for Guido to fill in. If the answer to <em>any</em> Python design issue isn’t obvious after reading those – well, I just give up &lt;wink&gt;. (<a href="https://mail.python.org/pipermail/python-list/1999-June/001951.html">Source</a>)</p> </blockquote> <p>The wink and the playful way of self-censoring some <a href="https://en.wikipedia.org/wiki/Toilet_humour">toilet humor</a> are clear giveaways that Tim Peters didn’t want anyone to take his comment too seriously.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> In case you didn’t get the joke, he started to write something like <em>Feces</em> but then used <code>^H</code>—which represents a <span class="keys"><kbd class="key-backspace">Backspace</kbd></span> in older text editors like <a href="https://realpython.com/vim-and-python-a-match-made-in-heaven/">Vim</a>—to delete the last three letters and make the word <em>Theses</em>. Therefore, the intended phrase is <em>20 Pythonic Theses</em>.</p> </div> <p>Eventually, these nearly twenty theses got a proper name and were formally codified in a <a href="https://peps.python.org/pep-0001/">Python Enhancement Proposal</a> document. Each PEP document receives a number. For example, you might have stumbled on <a href="https://realpython.com/python-pep8/">PEP 8</a>, which is the style guide for writing readable Python code. Perhaps as an inside joke, the Zen of Python received the number <a href="https://peps.python.org/pep-0020/">PEP 20</a> to signify the incomplete number of aphorisms in it.</p> <p>To win your next argument about what makes good Python code, you can back up your claims with the Zen of Python. If you’d like to refer to a specific aphorism instead of the entire poem, then consider visiting <a href="https://pep20.org/">pep20.org</a>, which provides convenient clickable links to each principle.</p> <p>And, in case you want to learn the poem by heart while having some fun, you can now listen to a <a href="https://www.youtube.com/watch?v=i6G6dmVJy74">song</a> with the Zen of Python as its lyrics. <a href="https://barry.warsaw.us/">Barry Warsaw</a>, another core developer involved with Python since its early days, composed and performed this musical rendition. The song became the closing track on a special vinyl record entitled <a href="https://www.edgedb.com/blog/the-zen-side-of-the-moon"><em>The Zen Side of the Moon</em></a>, which was <a href="https://x.com/pyladies/status/1649988104433061888">auctioned</a> at <a href="https://realpython.com/python-news-april-2023/#pycon-us-2023-celebrates-its-twentieth-anniversary">PyCon US 2023</a>.</p> <p>Okay. Now that you have a rough idea of what the Zen of Python is and how it came about, you might be asking yourself whether you should really follow it.</p> <h2 id="should-you-obey-the-zen-of-python">Should You Obey the Zen of Python?<a class="headerlink" href="#should-you-obey-the-zen-of-python" title="Permanent link"></a></h2> </div><h2><a href="https://realpython.com/zen-of-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/zen-of-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Improving Your Tests With the Python Mock Object Library https://realpython.com/courses/improve-tests-mock-object-library/ 2026-02-10T14:00:00+00:00 Master Python testing with unittest.mock. Create mock objects to tame complex logic and unpredictable dependencies. <p>When you&rsquo;re writing robust code, <strong>tests</strong> are essential for verifying that your application logic is correct, reliable, and efficient. However, the value of your tests depends on how well they demonstrate these qualities. Obstacles such as <strong>complex logic</strong> and unpredictable <strong>dependencies</strong> can make writing valuable tests challenging. The Python mock object library, <strong><code>unittest.mock</code></strong>, can help you overcome these obstacles.</p> <p><strong>By the end of this course, you&rsquo;ll be able to:</strong></p> <ul> <li>Create Python mock objects using <code>Mock</code></li> <li>Assert that you&rsquo;re using objects as you intended</li> <li>Inspect usage data stored on your Python mocks</li> <li>Configure certain aspects of your Python mock objects</li> <li>Substitute your mocks for real objects using <code>patch()</code></li> <li>Avoid common problems inherent in Python mocking</li> </ul> <p>You&rsquo;ll begin by learning what mocking is and how it will improve your tests!</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #283: Improving Your GitHub Developer Experience https://realpython.com/podcasts/rpp/283/ 2026-02-06T12:00:00+00:00 What are ways to improve how you're using GitHub? How can you collaborate more effectively and improve your technical writing? This week on the show, Adam Johnson is back to talk about his new book, "Boost Your GitHub DX: Tame the Octocat and Elevate Your Productivity". <p>What are ways to improve how you're using GitHub? How can you collaborate more effectively and improve your technical writing? This week on the show, Adam Johnson is back to talk about his new book, "Boost Your GitHub DX: Tame the Octocat and Elevate Your Productivity".</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Getting Started With Google Gemini CLI https://realpython.com/courses/getting-started-google-gemini-cli/ 2026-02-03T14:00:00+00:00 Learn how to use Gemini CLI to bring Google's AI-powered coding assistance into your terminal for faster code analysis, debugging, and fixes. <p>This video course will teach you how to use <a href="/ref/ai-coding-tools/gemini-cli/" class="ref-link">Gemini CLI</a> to bring Google&rsquo;s AI-powered coding assistance directly into your terminal. After you authenticate with your Google account, this tool will be ready to help you analyze code, identify bugs, and suggest fixes&mdash;all without leaving your familiar development environment.</p> <p>Imagine <a href="/ref/glossary/debugging/" class="ref-link">debugging</a> code without switching between your <a href="/ref/glossary/console/" class="ref-link">console</a> and browser, or picture getting instant explanations for unfamiliar projects. Like other command-line AI assistants, Google&rsquo;s Gemini CLI brings AI-powered coding assistance directly into your command line, allowing you to stay focused in your development workflow.</p> <p>Whether you&rsquo;re troubleshooting a stubborn bug, understanding legacy code, or generating documentation, this tool acts as an intelligent pair-programming partner that understands your codebase&rsquo;s context.</p> <p>You&rsquo;re about to install Gemini CLI, authenticate with Google&rsquo;s free tier, and put it to work on an actual Python project. You&rsquo;ll discover how natural language queries can help you understand code faster and catch bugs that might slip past manual review.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #282: Testing Python Code for Scalability & What's New in pandas 3.0 https://realpython.com/podcasts/rpp/282/ 2026-01-30T12:00:00+00:00 How do you create automated tests to check your code for degraded performance as data sizes increase? What are the new features in pandas 3.0? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects. <p>How do you create automated tests to check your code for degraded performance as data sizes increase? What are the new features in pandas 3.0? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Create Callable Instances With Python's .__call__() https://realpython.com/courses/create-callable-instances-dunder-call/ 2026-01-27T14:00:00+00:00 Learn Python callables: what "callable" means, how to use dunder call, and how to build callable objects with step-by-step examples. <p>In Python, a <strong>callable</strong> is any object that you can call using a pair of parentheses and, optionally, a series of arguments. Functions, classes, and methods are all common examples of callables in Python. Besides these, you can also create custom classes that produce <strong>callable instances</strong>. To do this, you can add the <strong><code>.__call__()</code></strong> special method to your class.</p> <p>Instances of a class with a <code>.__call__()</code> method behave like functions, providing a flexible and handy way to add functionality to your objects. Understanding how to create and use callable instances is a valuable skill for any Python developer.</p> <p><strong>In this video course, you&rsquo;ll:</strong></p> <ul> <li>Understand the concept of <strong>callable objects</strong> in Python</li> <li>Create <strong>callable instances</strong> by adding a <strong><code>.__call__()</code></strong> method to your classes </li> <li>Compare <strong><code>.__init__()</code></strong> and <strong><code>.__call__()</code></strong> and understand their distinct roles</li> <li>Build practical examples that use callable instances to <strong>solve real-world problems</strong></li> </ul> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #281: Continuing to Improve the Learning Experience at Real Python https://realpython.com/podcasts/rpp/281/ 2026-01-23T12:00:00+00:00 If you haven't visited the Real Python website lately, then it's time to check out a great batch of updates on realpython.com! Dan Bader returns to the show this week to discuss improvements to the site and more ways to learn Python. <p>If you haven't visited the Real Python website lately, then it's time to check out a great batch of updates on realpython.com! Dan Bader returns to the show this week to discuss improvements to the site and more ways to learn Python.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> uv vs pip: Python Packaging and Dependency Management https://realpython.com/courses/uv-vs-pip-packaging-dependency-management/ 2026-01-20T14:00:00+00:00 Choosing between uv vs pip? This video course compares speed, reproducible environments, compatibility, and dependency management to help you pick the right tool. <p>When it comes to Python package managers, the choice often comes down to <code>uv</code> vs <code>pip</code>. You may choose <code>pip</code> for out-of-the-box availability, broad compatibility, and reliable ecosystem support. In contrast, <code>uv</code> is worth considering if you prioritize fast installs, reproducible environments, and clean uninstall behavior, or if you want to streamline workflows for new projects.</p> <p>In this video course, you&rsquo;ll compare both tools. To keep this comparison meaningful, you&rsquo;ll focus on the overlapping features, primarily <em>package installation</em> and <em>dependency management</em>.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #280: Considering Fast and Slow in Python Programming https://realpython.com/podcasts/rpp/280/ 2026-01-16T12:00:00+00:00 How often have you heard about the speed of Python? What's actually being measured, where are the bottlenecks---development time or run time---and which matters more for productivity? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects. <p>How often have you heard about the speed of Python? What's actually being measured, where are the bottlenecks---development time or run time---and which matters more for productivity? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Intro to Object-Oriented Programming (OOP) in Python https://realpython.com/courses/intro-object-oriented-programming/ 2026-01-13T14:00:00+00:00 Learn Python OOP fundamentals fast: master classes, objects, and constructors with hands-on lessons in this beginner-friendly video course. <p>Object-oriented programming (OOP) is one of the most significant and essential topics in programming. This course will give you a foundational conceptual understanding of object-oriented programming to help you elevate your Python skills.</p> <p>You&rsquo;ll learn how to define custom types using classes and how to instantiate those classes into Python objects that can be used throughout your program.</p> <p>Finally, you&rsquo;ll discover how classes can inherit from one another, with a brief introduction to inheritance, enabling you to write maintainable and less redundant Python code.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #279: Coding Python With Confidence: Beginners Live Course Participants https://realpython.com/podcasts/rpp/279/ 2026-01-09T12:00:00+00:00 Are you looking for that solid foundation to begin your Python journey? Would the accountability of scheduled group classes help you get through the basics and start building something? This week, two members of the Python for Beginners live course discuss their experiences. <p>Are you looking for that solid foundation to begin your Python journey? Would the accountability of scheduled group classes help you get through the basics and start building something? This week, two members of the Python for Beginners live course discuss their experiences.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Tips for Using the AI Coding Editor Cursor https://realpython.com/courses/tips-using-ai-coding-editor-cursor/ 2026-01-06T14:00:00+00:00 Learn Cursor fast: Use AI-powered coding with agents, project-aware chat, and inline edits to supercharge your VS Code workflow. <p>Cursor is an AI-powered integrated development environment (IDE) based on the Visual Studio Code codebase. It comes with a multi-agent interface and the Composer model for fast, agentic coding while keeping a familiar editor workflow with project-aware chat, code completion, and inline edits.</p> <p>In this course, you will: </p> <ul> <li>Understand why Cursor might work for you</li> <li>Learn how to use different modes &amp; models</li> <li>See how to run multiple agents at a time</li> <li>Resolve a tiny merge conflict</li> <li>Run a project and fix a bug</li> <li>Learn commands and practice with the terminal</li> </ul> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #278: PyCoder's Weekly 2025 Top Articles & Hidden Gems https://realpython.com/podcasts/rpp/278/ 2026-01-02T12:00:00+00:00 PyCoder's Weekly included over 1,500 links to articles, blog posts, tutorials, and projects in 2025. Christopher Trudeau is back on the show this week to help wrap up everything by sharing some highlights and uncovering a few hidden gems from the pile. <p>PyCoder's Weekly included over 1,500 links to articles, blog posts, tutorials, and projects in 2025. Christopher Trudeau is back on the show this week to help wrap up everything by sharing some highlights and uncovering a few hidden gems from the pile.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p>