LLMS & GENERATIVE AIv3.15
LLMs & Generative AI

Python 3.15 Brings Lazy Imports, Sampling Profiler, and More

Python 3.15 introduces explicit lazy imports, a new sampling profiler, and deprecates Python 3.10.

Table of contents
  1. What's New in Python 3.15?
  2. Explicit Lazy Imports
  3. Unpacking in Comprehensions
  4. Sampling Profiler: Tachyon
  5. Should You Upgrade to Python 3.15?
  6. Am I Affected by the Retirement of Python 3.10?
  7. Applying Python 3.15 Features in Your Projects
  8. Limitations and Considerations

Python 3.15 has arrived, bringing with it some exciting new features and enhancements like explicit lazy imports and a new sampling profiler. Alongside these changes, Python 3.10 has reached the end of its support, making way for developers to fully embrace Python 3.11 features.

What's New in Python 3.15?

Among the standout features of Python 3.15 are explicit lazy imports, a new unpacking syntax in comprehensions, and a new sampling profiler named Tachyon. These updates are set to streamline development processes and improve performance in specific scenarios.

Explicit Lazy Imports

One of the most eagerly anticipated features of Python 3.15 is explicit lazy imports, as outlined in PEP 810. This feature allows developers to defer the import of a module until its symbols are actually used, improving startup time for applications, especially those with heavy dependencies. You can use it with syntax like:

lazy import json
lazy from pathlib import Path

This change is particularly beneficial for applications like plugin systems, where loading unnecessary modules can add significant overhead. For example, in CLI tools with plugins that include large libraries, lazy imports can significantly reduce startup delays. For applications that demand quick startup times or have a modular architecture with numerous dependencies, lazy imports optimize resource loading efficiently, especially when inactive or rarely used features are present.

Unpacking in Comprehensions

The new unpacking syntax in list, set, and dict comprehensions makes code more concise and readable. Here's how you can utilize it:

lists = [[1, 2], [3, 4], [5]]
[*L for L in lists]  # [1, 2, 3, 4, 5]

This syntactic sugar simplifies iteration over nested structures, simultaneously boosting both performance and readability. In scenarios with nested loops where you aim to flatten lists or handle collections with ease, this syntax can simplify function implementation, making code behavior intuitive. For example, processing datasets or converting nested query results into a flat list becomes straightforward.

Sampling Profiler: Tachyon

Python 3.15 introduces a sampling profiler named Tachyon, or profiling.sampling. Sampling profilers provide deep insights into running systems by periodically capturing stack traces and calculating which functions consume the most time. Measuring function performance without instrumenting systems first offers developers a low-overhead means of profiling applications. To use it, you can run:

sudo uv run --python 3.15 python -m profiling.sampling attach 1234

Interactive visual tools like flame graphs and heatmaps can expose application bottlenecks, guiding optimization efforts. These tools help visualize the call stack data collected by the profiler, offering a clear picture of where most execution time is spent and enabling data-driven optimization strategies.

Should You Upgrade to Python 3.15?

If you are actively developing projects on Python 3.14 or earlier, consider upgrading to 3.15 to access lazy imports and the sampling profiler—especially if your applications involve large dependencies or require performance optimization.

Miguel Grinberg's tests showed that Python 3.15 runs at about the same speed as 3.14, except when using the experimental JIT, which showed a minor performance improvement. While the core speed enhancements might not be revolutionary, the new features themselves make 3.15 an attractive choice for modernizing your Python codebase. It's a version that embraces finesse over brute force, favoring nuanced improvements over raw speed.

Am I Affected by the Retirement of Python 3.10?

Python 3.10 is no longer supported as of this release. If your projects are still reliant on it, upgrading is necessary to ensure that you continue to receive updates and security patches. Deprecated support means taking steps towards the newer versions ensures better integration with the broader Python ecosystem. Adopting the latest versions allows access to new language features, libraries, and bug fixes that can enhance efficiency and security.

Applying Python 3.15 Features in Your Projects

Here's how you can start leveraging Python 3.15 in your own projects:

  • Update Your Python Version: Use uv to update to Python 3.15. First, update uv for compatibility, then:
uv self update
uv python install 3.15
uv python pin --global 3.15

Check if the update aligns with your software dependencies, testing dependencies on this Python version before full deployment. Ensure third-party libraries used in your project are compatible with 3.15 to prevent integration issues.

  • Utilize Lazy Imports: Refactor your imports to be lazy where it can improve startup times. This is often beneficial in CLI tools or web services with optional plugins. Iterate through your existing codebase, identifying heavy modules that contribute to longer startup times and consider lazy importing them.
  • Optimize with Tachyon: Run Tachyon to identify bottlenecks without adding overhead. This is particularly useful for long-running server processes, where the accurate profiling of function calls helps mitigate execution delays. Use the insights gained to refactor critical sections of your application that contribute to performance bottlenecks.
  • For those maintaining or developing open-source software, it's a good time to update your test environments to include Python 3.11 to 3.15, since 3.10 support is officially over. Transitioning to a newer environment can help preempt issues that might arise from using obsolete versions.

    Limitations and Considerations

    Not all features will fit every use case. For instance, if your application doesn't suffer from startup delays or you don't need advanced profiling, the implementation benefits may not be immediately visible. Also, the JIT is experimental and its gains are modest in this version.

    Some developers might choose to wait for 3.15.1 or later releases, often a stable strategy to allow for early bug fixes. I'd consider using Python 3.15 in non-critical environments first before rolling it out to production systems. Ensuring that dependencies and frameworks are compatible with Python 3.15 can save significant integration effort.

    These updates make Python 3.15 an exciting release, with potential to streamline certain development processes. As always, testing in a controlled environment is my first move before a full-scale adoption, guaranteeing that benefits are maximized while minimizing potential disruptions. For instance, sandbox testing helps identify compatibility issues early, reducing the risk of major conflicts during production deployment.

    For more on technology updates, check out our articles on Node.js updates and ambient intelligence in workflows.

    Frequently asked questions

    What are explicit lazy imports in Python 3.15?

    They allow modules to be imported only when their symbols are used, improving startup times.

    How does the sampling profiler in Python 3.15 work?

    It captures stack traces periodically, offering performance insights with low overhead.

    Is Python 3.10 still supported?

    No, Python 3.10 support has ended with the release of Python 3.15.

    What should I consider before upgrading to Python 3.15?

    Assess whether the new features like lazy imports and sampling profiler are beneficial for your projects.

    Source: Hello Python 3.15, goodbye 3.10, and now I can use 3.11

    How this article was made: drafted with AI from the source above, then fact-checked against it before publishing.

    Written by

    · Senior Software Engineer

    Deepak Kumar is a Senior Software Engineer based in New Delhi. He builds Generative AI into production: RAG on MongoDB Atlas Vector Search, semantic search over an editorial archive, and the multi-agent pipelines behind ByteMuni itself. He started ByteMuni to publish clear, source-checked guides for working developers.