# Add Virtual Threads to Python

**URL:** <https://discuss.python.org/t/add-virtual-threads-to-python/91403>\
**Category:** Ideas\
**Created:** [May 9, 2025, 5:33pm UTC](https://discuss.python.org/t/add-virtual-threads-to-python/91403 "2025-05-09T17:33:14Z")\
**Posts on this page:** 1\
**Showing post:** 71

<div class="post-metadata">

**Author:** ![rtpg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rtpg/32/14068_2.png) [@rtpg](https://discuss.python.org/u/rtpg)\
**Post date:** [May 20, 2025, 2:05am UTC](https://discuss.python.org/t/add-virtual-threads-to-python/91403/71 "2025-05-20T02:05:37Z")

</div>

Having something like this would sound very exciting for libraries like Django. Django could use this to support async and sync APIs (using virtual threads under the hood to support a “clean”-ish single implementation, while still maintaining some performance guarantees in both spaces).

Without a way to have single implementations of async and sync APIs, various libraries have landed on using codegen to support both sides. we are asking _all libraries_ to basically do codegen to support both APIs. What is going to happen in the end? **Libraries are going to go more and more into async-only API territory for ease of maintenance.** The future of sync Python _depends_ on libraries being able to support sync and async variants cleanly.

More libs being async only there will be even more pressure to improve the (IMO) lackluster debugging support for async code (`breakpoint()` into an async method call and try to get any other async value).

We want good things and better suppoort in this space! But do we want libraries across the board to be doing codegen to do the good thing?

And the subtler thing: users of these libraries _end up wanting codegen themselves_ to preserve sync and async API layering.

* * *

So my short version is that I think if you support structured concurrency through `async`/`await`, you should consider supporting this idea, because it will allow for libraries to offer good ergnomics in the space.

Libraries like Django could rely on continuations deep in the database code to have a single, “clean” implementation that yields only when the user is expecting an `async` variant of an API.

I had previously written a [very silly idea](https://discuss.python.org/t/async-eagerness-as-a-context-variable/62416) to basically turn async “on or off”. But this would provide a pretty principled way to sidestep this problem entirely, while still giving me dual sync/async variant API support.

---

_[View the full topic](https://discuss.python.org/t/add-virtual-threads-to-python/91403)._
