AnyIO

High-level async concurrency and networking API that runs on both asyncio and Trio

Library
PyPI
v4.15.1
2,560 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
87 /100 Excellent
Development Activity 100
Maintenance 72
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 85
Code Quality 88
Innovation 78
Learning Curve 68

AnyIO is a Python library that provides a single, high-level asynchronous programming API — structured concurrency with task groups, cancellation scopes, sockets, streams, synchronization primitives, and subprocess/thread offloading — that works identically whether the underlying event loop is asyncio or Trio. Rather than choosing between the two ecosystems, library authors can target AnyIO’s API once and let end users run their code on whichever backend they prefer, while application authors get Trio-style structured concurrency (task groups that guarantee child tasks finish or are cancelled before the parent scope exits) even when running on plain asyncio.

AnyIO is widely used as the concurrency layer underneath other popular async libraries (including Starlette/FastAPI’s test client and httpx’s async transport), because it removes the need for those projects to hand-write asyncio/Trio compatibility shims. It also ships a pytest plugin (anyio.pytest_plugin) for testing async code against both backends without duplicating test suites, and provides thread/subprocess/interpreter offloading helpers (to_thread, to_process, to_interpreter) for running blocking or CPU-bound work without blocking the event loop.

What You Get

  • Structured concurrency via task groups and cancellation scopes that guarantee child tasks complete or are cancelled before their parent scope exits
  • A unified socket/stream API for TCP, UDP, and Unix sockets that behaves identically on asyncio and Trio
  • Synchronization primitives (locks, semaphores, events, condition variables) usable from either backend
  • Thread, process, and subinterpreter offloading helpers (to_thread, to_process, to_interpreter) for running blocking work off the event loop
  • A pytest plugin for running the same async test suite against both asyncio and Trio backends

Common Use Cases

  • Library authors writing async I/O code once that needs to run on both asyncio and Trio user applications
  • Application developers wanting Trio-style structured concurrency (guaranteed task cleanup) while staying on the asyncio ecosystem
  • Frameworks (e.g. web frameworks, HTTP clients) using AnyIO internally as their concurrency primitive layer instead of hand-rolling asyncio/Trio shims
  • Offloading blocking or CPU-bound work (file I/O, C extensions) from async code via to_thread/to_process without blocking the event loop
  • Testing async libraries against both backends in a single pytest suite via the built-in anyio pytest plugin

Under The Hood

Architecture AnyIO’s public API in src/anyio/_core is backend-agnostic; at runtime it dispatches to one of two backend implementations in src/anyio/_backends — _asyncio.py (which adapts native asyncio primitives, adding structured-concurrency semantics asyncio lacks natively) or _trio.py (a thinner pass-through, since Trio already implements structured concurrency natively). This split lets AnyIO present one API while each backend module handles the real differences in cancellation semantics, task scheduling, and socket implementation between the two runtimes.

Tech Stack Pure Python (3.10+), using setuptools/setuptools_scm for packaging, with idna as its only hard runtime dependency (plus conditional exceptiongroup/typing_extensions backports for older Python versions) and trio as an optional extra for the Trio backend. Ships a py.typed marker for full type-checker support.

Code Quality The tests/ directory (over 15,000 lines including a dedicated streams subdirectory) covers task groups, cancellation, sockets, subprocesses, synchronization, deprecations, and the pytest plugin itself, and both AGENTS.md and CLAUDE.md files in the repo root document contributor/agent conventions directly — an unusually explicit level of process documentation for a library of this size. The project is fully type-annotated and uses blockbuster (a dev dependency) to detect accidental blocking calls inside async code during its own test suite.

API Design The core primitives — anyio.create_task_group(), anyio.CancelScope, anyio.to_thread.run_sync() — closely mirror Trio’s already well-regarded structured-concurrency API, so developers familiar with Trio (or who read AnyIO’s docs) get a consistent mental model regardless of which backend actually executes their code. This deliberate API alignment with Trio, rather than asyncio’s lower-level primitives, is what allows AnyIO to add real cancellation guarantees on top of asyncio without exposing two divergent programming models.

Used by 22 apps in this directory

Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 5 days ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago
TypeScript
92%
Other

OpenHands

AI Code Assistants · AI Development

91,695

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 92%
Updated 6 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 5 days ago
Go
71%
Apache 2.0

OSV.dev

Security

3,001

Google's open-source vulnerability database that maps CVEs to exact package versions across 50+ ecosystems with a public API and data dumps.

View details
87
Repo Health
82
Technical
66
Dependency
Built with
Go 71%
Python 19%
Updated 6 days ago
Python
62%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,410

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 62%
TypeScript 31%
Updated 6 days ago
TypeScript
98%
MIT

Promptfoo

AI Development

26,358

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
67
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
98%
Apache 2.0

rowboat

AI Assistants · AI Development

18,060

Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.

View details
88
Repo Health
72
Technical
65
Dependency
Built with
TypeScript 98%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers