English | 한국어
Comfortable concurrency for Python apps on Kotlin Multiplatform: asyncio and Kotlin coroutines, together.
Python apps that run on Android, iOS and desktop through
python-multiplatform meet two worlds of
concurrency. Python has asyncio. Kotlin has coroutines, and on Android you will use them.
pythonx-concurrent is a pythonx library, Python language extensions in the spirit of androidx and
kotlinx. It joins the two worlds and gives Python the structure kotlinx.coroutines gives Kotlin.
- Scopes and jobs, spelled like
asyncio.TaskGroup, named like Kotlin:launch,Job,with_context,with_timeout. - Dispatchers:
Main,IOandDefault, mapped to each platform's threads. - Both-way bridge: Python awaits Kotlin
suspendfunctions andFlow. Kotlin awaits Python coroutines. Cancellation flows both ways. - Goroutine-style scheduling of many lightweight tasks over a few threads, parallel on free-threaded CPython where that exists.
from pythonx.concurrent import Scope, Dispatchers, with_context
async def load(user_id):
async with Scope() as s:
profile = s.defer(fetch_profile, user_id)
data = await with_context(Dispatchers.IO, read_cache, user_id)
return profile.result(), dataThis example shows the planned spelling. Nothing is built yet.
Not published yet. When it is:
uv add --prerelease allow pythonx-concurrentSpec stage. There is no code. The intent, the behaviour contract and the research are written, and
every behaviour is planned. Several features wait on python-multiplatform; each is tracked as an
issue there.
Apache-2.0.