Skip to main content
    listerineh.dev
    • About
    • Experience
    • Projects
    • Skills
    • Blog
    • Talks
    • Contact
    • Why
    • About
    • Experience
    • Projects
    • Skills
    • Blog
    • Talks
    • Contact
    • Why

    © 2026 Sebastian Alvarez

    Back to Blog

    Python in the AI Era: Why It Ended Up Everywhere

    Five years of writing Python: why it became the default for AI, what is genuinely new in the language, where it still isn't the right tool, and why the "Python is slow" argument misses the point.

    Sebastian Alvarez

    February 24, 2026·8 min read·
    Loading...
    • Python
    • AI
    • Machine Learning
    • Web Development
    • DevOps
    • Programming Languages
    Python in the AI Era: Why It Ended Up Everywhere
    Table of Contents

    From "that scripting language" to the default for AI

    I've been writing Python for more than five years, and in that time I've watched it go from "the scripting language" to the default choice for AI. That didn't happen by accident. It's the result of design decisions made long before anyone was training large models, a huge ecosystem, and very good timing.

    This post is about why Python ended up everywhere, from web APIs to the frameworks used to train today's models: what it's good at, what's new in the language, and where it still isn't the right tool. Short answer to "is it worth learning in 2026?": yes.

    One language, a lot of jobs

    What sets Python apart is that it's genuinely multi-purpose. Not "it can do many things badly", but good enough in areas that used to need different languages.

    Web. Instagram famously runs on Django, and Python is all over companies like Spotify and Netflix. My go-to for production APIs is FastAPI: async, built on type hints, with documentation generated for free. Django is still the full-featured option, and Flask is there when you want something minimal.

    Infrastructure and automation. Ansible, AWS CDK and Pulumi all speak Python, and plenty of Kubernetes operators are written in it. I've built whole deployment pipelines in Python, from provisioning cloud resources to managing containers.

    Data. If you work with data at scale, you're probably writing Python: Airflow for orchestration, dbt for transformations, SQLAlchemy as the ORM, pandas and Polars for dataframes, Great Expectations for data quality.

    Security. It's a favorite in security work: Scapy for packet manipulation, quick exploit prototypes, and automation from scanning to incident response.

    Games and mobile. Python is not the main language here, and it's fair to say so. There's Pygame and Panda3D for games (Godot's GDScript looks like Python but isn't), and Kivy or BeeWare for mobile. For an MVP or an internal tool it can work. For a serious mobile app, Swift and Kotlin are still the answer.

    What's new in the language

    Python has changed more in the last few versions than people outside it tend to notice.

    It got faster. Python 3.11 was between 10% and 60% faster than 3.10 depending on the benchmark, and later versions kept improving. 3.13 also shipped an experimental build without the GIL and an experimental JIT, which says a lot about where it's heading.

    Types are first-class now. Type hints went from optional decoration to something the tooling relies on:

    from typing import TypedDict, NotRequired
    
    class UserData(TypedDict):
        name: str
        email: str
        age: NotRequired[int]  # optional key
    
    # Generic type aliases (3.12+)
    type Vector[T] = list[T]
    type Matrix[T] = list[Vector[T]]
    

    Structural pattern matching (3.10+) makes code that branches on the shape of data much easier to read:

    match response:
        case {"status": 200, "data": data}:
            process_success(data)
        case {"status": 404}:
            handle_not_found()
        case {"status": code} if code >= 500:
            handle_server_error(code)
        case _:
            handle_unknown()
    

    Error messages that help. Recent versions point at the exact part of the expression that failed and suggest fixes. Forget an import in 3.12 and you get NameError: name 'sys' is not defined. Did you forget to import 'sys'?.

    Better async. Task groups (3.11+) make concurrent work much easier to get right:

    async with asyncio.TaskGroup() as tg:
        task1 = tg.create_task(fetch_user(1))
        task2 = tg.create_task(fetch_user(2))
        task3 = tg.create_task(fetch_user(3))
    # Either every task finishes, or they all get cancelled together
    

    Why AI ended up in Python

    NumPy came first. Long before TensorFlow or PyTorch, Python had NumPy: efficient array operations backed by BLAS and LAPACK, so C and Fortran speed with Python syntax. That was the foundation for scientific computing, and everything else was built on top.

    The math reads like the paper. AI research is about trying ideas quickly, and Python lets you focus on the algorithm instead of the language. Attention, the core of transformers, fits in a few lines:

    def attention(Q, K, V):
        scores = Q @ K.T / sqrt(d_k)
        weights = softmax(scores)
        return weights @ V
    

    Try writing that as clearly in C++ or Java.

    The ecosystem snowballed. Once PyTorch and TensorFlow picked Python, everything followed: Hugging Face Transformers, LangChain, and the official SDKs from OpenAI, Anthropic and Google, which all have Python as a first-class citizen.

    You see it in the big frameworks. PyTorch came out of Meta and is Python-first, and Meta's Llama models were built with it. Google's TensorFlow and JAX are driven from Python, with C++ and XLA underneath. Stable Diffusion was built on PyTorch. The language people use to run these systems is Python, even if the heavy lifting happens somewhere else.

    Why it works so well for AI work

    Tensor code looks like math.

    import torch
    
    x = torch.randn(1000, 1000)
    y = torch.randn(1000, 1000)
    z = (x @ y).softmax(dim=-1)  # matrix multiply + softmax, running in C++
    

    Moving to the GPU is one line. model = model.to("cuda") and the rest of the code stays the same.

    From paper to prototype is fast. A basic transformer encoder is a handful of lines with PyTorch's building blocks:

    class Transformer(nn.Module):
        def __init__(self, d_model, nhead, num_layers):
            super().__init__()
            self.encoder = nn.TransformerEncoder(
                nn.TransformerEncoderLayer(d_model, nhead),
                num_layers,
            )
    
        def forward(self, x):
            return self.encoder(x)
    

    Everything around the model is Python too. Scraping data (BeautifulSoup, Scrapy), images (Pillow, OpenCV), audio (librosa), serving (FastAPI), metrics (the Prometheus client). One language for the whole pipeline.

    The language features fit the work. Type hints give you autocomplete and documentation without Java-level verbosity. Functions are values, so the same training loop works with any loss function or optimizer you pass in. And building models dynamically is natural:

    layers = []
    for _ in range(num_layers):
        layers += [nn.Linear(hidden_size, hidden_size), nn.ReLU()]
    model = nn.Sequential(*layers)
    

    Notebooks. Jupyter is where a lot of AI work actually happens: train, plot the loss, tweak a hyperparameter, run again, all in the same place.

    "But Python is slow"

    Pure Python is slow, sure. The trick is that the heavy lifting in AI isn't done in Python:

    result = model(input_tensor)
    # 1. Python calls into PyTorch (C++)
    # 2. PyTorch launches CUDA kernels on the GPU
    # 3. The GPU does the matrix multiplications
    # 4. The result comes back to Python
    

    Python orchestrates; C++, CUDA and the GPU execute. Writing the same training loop in pure Python would be orders of magnitude slower. Through PyTorch, the overhead of Python itself is a rounding error next to the GPU work.

    Python in production

    Serving a model is also mostly Python:

    from fastapi import FastAPI
    import torch
    
    app = FastAPI()
    model = torch.jit.load("model.pt")  # TorchScript, compiled for inference
    
    @app.post("/predict")
    async def predict(text: str):
        with torch.no_grad():
            result = model(text)
        return {"prediction": result}
    

    With enough Uvicorn workers behind a load balancer, this kind of service scales a long way. The architecture is always the same: a thin Python layer (the API), the framework in C++ underneath, and GPU kernels at the bottom doing the real work.

    Should you learn it in 2026?

    Yes, if you're interested in AI or machine learning (there's no real alternative), if you do data engineering, if you build APIs, if you automate infrastructure, or if you just want one language that covers a lot of ground.

    Probably not as your main language if you only do frontend (TypeScript), if you need bare-metal performance (Rust, C++), or if you build mobile apps (Swift, Kotlin). Even then, knowing Python opens doors.

    Where it's going

    It's getting faster: PyPy has been several times faster than CPython on pure-Python code for years, Cython compiles hot paths to C, and CPython itself now has an experimental JIT and a GIL-free build. Mojo is trying to be a Python-compatible language with systems-level performance. Typing keeps getting better and more widespread. And a lot of the recent work (async, memory, concurrency) is clearly shaped by what model serving and data pipelines need.

    If you're starting with Python for AI

    1. Get the fundamentals right: comprehensions, generators, decorators, context managers and type hints.
    2. Learn NumPy. Everything else is built on it.
    3. Pick a framework. Today that's PyTorch for most people, in research and increasingly in production. TensorFlow and JAX are still around, especially in Google's ecosystem.
    4. Build things: fine-tune a model, build a RAG system, write your own training pipeline, deploy a model behind an API.

    My take

    Python's place in AI isn't hype, it was earned. It evolved at the right time, with the right features and the right ecosystem behind it. It isn't perfect, and pure Python is slow, but for AI work in 2026 it's still the best tool we have. The frameworks behind today's models are driven from Python, and so is most of the research and the code that puts those models in production.

    After more than five years writing it, I'm honestly more excited about it now than when I started. The language is getting faster, the ecosystem keeps growing and the problems are more interesting every year.

    What are you using Python for? AI, web, something else? I'd love to hear what you're building.

    What did you think?

    Loading reactions...

    Found this article helpful? Share it!

    Help others discover this content by sharing it on your favorite platform.

    Previous articleAdapting to New Jobs: From Well-Structured Teams to Chaotic StartupsNext articleThe First Digital Death: A Prediction from 2022 That Looks More Plausible Every Year

    Keep reading

    More Articles
    • July 24, 2026 · 20 min read

      Your Portfolio Speaks Before You Do: Design Language and Design Systems

      Chefs say we eat with our eyes first, and portfolios work the same way. Typography, mockups, UI/UX basics, component libraries and the technical decisions that make a redesign easy, with my own as the example.

    • March 30, 2026 · 7 min read

      Vibe Coding with AI: Building a Production Landing Page in Under an Hour

      At a Cursor workshop in Quito I skipped the script and ran an experiment: Gemini as the architect, Cursor in auto mode with custom skills, a production landing page in under an hour. It worked, and it made me disagree with the workshop's main message.

    • May 21, 2026 · 8 min read

      Floci: The AWS Local Emulator That Starts in 24ms and Costs $0

      When LocalStack went paid I tried Floci, a free, MIT-licensed AWS emulator. It starts in 24ms and runs real engines. How I use it with Terraform, and where it still falls short.

    Don't miss the next post

    Secure · Private · Unsubscribe

    listerineh.dev

    Full-stack engineer building AI agents, cloud platforms and web products. Based in Quito, working remotely.

    Open to new projects

    Work

    • Projects
    • Experience
    • Skills
    • Blog
    • Talks

    About me

    • About
    • Why Listerineh?
    • Contact

    Connect

    • GitHub
    • LinkedIn
    • Instagram
    • Email

    © 2026 Sebastian Alvarez · All rights reserved.

    • Privacy Policy
    • Terms of Use
    • Unsubscribe from the newsletter
    • Component Library