I'm relatively new to Python, coming from a background in systems and embedded programming, and I'm looking to automate IoT device testing using Python and pytest. I started with Trio since it was used in a reference pytest plugin, and I really liked its focus on structured concurrency—a concept I'm already familiar with from Swift. I've made some progress in prototyping, but I've hit a roadblock with libraries. While I found a wrapper for serial communication, there seems to be no support for BLE with Trio. Bleak, the main library for BLE in Python, uses the asyncio backend. I'm wondering if I should switch to another framework like anyio (since it's a bit of a middle ground) to avoid refactoring later. Will I lose significant advantages if I move away from Trio? I'm particularly fond of its Tasks and TaskGroups (Nurseries) and the native support for sockets and subprocesses. I'd love to hear your experiences with Trio or similar async libraries!
4 Answers
I'd say just stick with asyncio if you're asking whether to use Trio. Many of us find that asyncio is more than adequate for most needs. Structured concurrency is great, but it's primarily useful for building larger applications. If you're dealing with IoT and TCP/IP, you might not need all the bells and whistles that Trio provides.
I think Trio makes some great design choices and has definite improvements over asyncio, like safer interrupt handling. However, the library support is pretty limited. If you want to stick with Trio, consider using trio-asyncio, which creates an asyncio loop within Trio to help bridge the gap. Still, I'd recommend going with anyio using the asyncio backend because it offers similar structured concurrency but lets you easily tap into the rich ecosystem of asyncio libraries. Plus, transitioning your code between Trio and Anyio is pretty straightforward!
For me, Anyio is the way to go! Its API is very close to Trio's, but it allows you to use asyncio libraries without issues. Plus, you can run Trio as the backend too—it just becomes a compatibility layer. Definitely worth checking out!
I went from asyncio to anyio for my IoT work, and it was a smooth transition! Anyio still gives you those structured concurrency benefits while working seamlessly with asyncio libraries. If you might want to keep your libraries versatile, Anyio should serve you well.

Thanks! This is really helpful. I’ll switch to Anyio and try the asyncio backend.