pydoc > anyio

📖 NAME

anyio

🚀 Quick Reference

Use CaseCommandDescription
Run an async functionanyio.run(func, *args)Run a coroutine in an event loop (asyncio/trio)
Create a task groupanyio.create_task_group()Create a task group for structured concurrency
Open an async fileawait anyio.open_file(...)Open a file with async I/O
Connect TCPawait anyio.connect_tcp(host, port)Connect to a TCP server
Create a memory object streamsend, recv = anyio.create_memory_object_stream()Create an in-memory channel for objects
Sleepawait anyio.sleep(seconds)Pause the current task
Timeoutwith anyio.fail_after(delay): ...Raise TimeoutError after delay
Cancel scopewith anyio.CancelScope() as scope: ...Make a block cancellable
Run in subprocessresult = await anyio.run_process(...)Run an external command and wait for completion
Async path operationsawait anyio.Path('/tmp').read_text()Async file path operations

📦 Package Contents

🏗️ Classes

AsyncContextManagerMixin

Mixin class providing async context manager functionality via a generator-based implementation.

AsyncFile

An asynchronous file object. Wraps a standard file object and provides async friendly versions of blocking methods.

Readonly properties: limiter, wrapped

BrokenResourceError

Raised when trying to use a resource that has been rendered unusable due to external causes.

BrokenWorkerInterpreter

Raised by anyio.to_interpreter.run_sync if an unexpected exception is raised in the subinterpreter.

BrokenWorkerProcess

Raised by anyio.to_process.run_sync if the worker process terminates abruptly.

BusyResourceError

Raised when two tasks are trying to read from or write to the same resource concurrently.

CancelScope

Wraps a unit of work that can be made separately cancellable.

CapacityLimiter

Used to limit the number of concurrent operations.

CapacityLimiterStatistics

Data class with fields: borrowed_tokens, total_tokens, borrowers, tasks_waiting.

ClosedResourceError

Raised when trying to use a resource that has been closed.

Condition

Async condition variable.

ConditionStatistics

Data class with fields: tasks_waiting, lock_statistics.

ConnectionFailed

Raised when a connection attempt fails. Inherits from OSError.

ContextManagerMixin

Mixin class providing context manager functionality via a generator-based implementation.

DelimiterNotFound

Raised during BufferedByteReceiveStream.receive_until if max bytes read without delimiter.

EndOfStream

Raised when trying to read from a stream that has been closed from the other end.

Event

Async event.

EventStatistics

Data class with field: tasks_waiting.

IncompleteRead

Raised during BufferedByteReceiveStream.receive_exactly or receive_until if connection closed before requested amount.

Lock

Async lock.

LockStatistics

Data class with fields: locked, owner, tasks_waiting.

NamedTemporaryFile

Async named temporary file.

NoEventLoopError

Raised when no event loop is running in the current thread.

Path

Async version of pathlib.Path.

ResourceGuard

Context manager for ensuring a resource is only used by a single task at a time.

RunFinishedError

Raised by from_thread.run/run_sync if the event loop has already finished.

Semaphore

Async semaphore.

SemaphoreStatistics

Data class with field: tasks_waiting.

SpooledTemporaryFile

Async spooled temporary file that starts in memory and is spooled to disk.

TCPConnectable

Connects to a TCP server.

TaskCancelled

Raised when awaiting on a TaskHandle that was cancelled. Inherits from TaskFailed.

TaskFailed

Raised when awaiting on a TaskHandle that raised an exception.

TaskHandle

Returned from task-spawning methods of TaskGroup. Can be awaited to get the return value.

TaskInfo

Represents an asynchronous task.

TaskNotFinished

Raised when attempting to access the return value or exception of a TaskHandle that is still pending.

TemporaryDirectory

Async temporary directory.

TemporaryFile

Async temporary file.

TypedAttributeLookupError

Raised by TypedAttributeProvider.extra when attribute not found and no default.

TypedAttributeProvider

Base class for classes that provide typed extra attributes.

TypedAttributeSet

Superclass for typed attribute collections.

UNIXConnectable

Connects to a UNIX domain socket.

WouldBlock

Raised by X_nowait functions if X() would block.

create_memory_object_stream

Creates a memory object stream. Returns a tuple of (MemoryObjectSendStream, MemoryObjectReceiveStream).

⚙️ Functions

__getattr__

__getattr__(attr: str) -> type[BrokenWorkerInterpreter] — Support deprecated aliases.

aclose_forcefully

async aclose_forcefully(resource: AsyncResource) -> None — Close an async resource in a cancelled scope.

as_connectable

as_connectable(remote, /, *, tls=False, ssl_context=None, tls_hostname=None, tls_standard_compatible=True) -> ByteStreamConnectable — Return a byte stream connectable from the given object.

connect_tcp

async connect_tcp(remote_host, remote_port, *, ...) -> SocketStream | TLSStream — Connect to a host using TCP with Happy Eyeballs.

connect_unix

async connect_unix(path) -> UNIXSocketStream — Connect to a UNIX socket.

create_connected_udp_socket

async create_connected_udp_socket(remote_host, remote_port, ...) -> ConnectedUDPSocket

create_connected_unix_datagram_socket

async create_connected_unix_datagram_socket(remote_path, ...) -> ConnectedUNIXDatagramSocket

create_task_group

create_task_group() -> TaskGroup — Create a task group.

create_tcp_listener

async create_tcp_listener(*, ...) -> MultiListener

create_udp_socket

async create_udp_socket(family, ...) -> UDPSocket

create_unix_datagram_socket

async create_unix_datagram_socket(*, ...) -> UNIXDatagramSocket

create_unix_listener

async create_unix_listener(path, ...) -> SocketListener

current_effective_deadline

current_effective_deadline() -> float — Return the nearest deadline among all cancel scopes.

current_time

current_time() -> float — Return the current value of the event loop's internal clock.

fail_after

fail_after(delay, shield=False) -> Generator[CancelScope, None, None] — Context manager that raises TimeoutError if not finished in time.

get_all_backends

get_all_backends() -> tuple[str, ...] — Return names of all built-in backends.

get_available_backends

get_available_backends() -> tuple[str, ...] — Test for availability of built-in backends.

get_cancelled_exc_class

get_cancelled_exc_class() -> type[BaseException] — Return cancellation exception class.

get_current_task

get_current_task() -> TaskInfo — Return the current task.

get_running_tasks

get_running_tasks() -> list[TaskInfo] — Return list of running tasks.

getaddrinfo

async getaddrinfo(host, port, ...) -> list[tuple[...]] — Look up numeric IP address given host name.

getnameinfo

getnameinfo(sockaddr, flags=0) -> Awaitable[tuple[str, str]] — Look up host name of an IP address.

gettempdir

async gettempdir() -> str — Return temporary directory name.

gettempdirb

async gettempdirb() -> bytes — Return temporary directory name as bytes.

mkdtemp

async mkdtemp(suffix, prefix, dir) -> str | bytes — Create a temporary directory.

mkstemp

async mkstemp(suffix, prefix, dir, text=False) -> tuple[int, str | bytes] — Create a temporary file.

move_on_after

move_on_after(delay, shield=False) -> CancelScope — Create a cancel scope with a deadline that expires after the given delay.

notify_closing

notify_closing(obj) -> None — Call before closing a file descriptor or socket to wake up waiters.

open_file

async open_file(file, mode='r', ..., limiter=None) -> AsyncFile — Open a file asynchronously.

open_process

async open_process(command, ...) -> Process — Start an external command in a subprocess.

open_signal_receiver

open_signal_receiver(*signals) -> AbstractContextManager[AsyncIterator[Signals]] — Start receiving OS signals.

run

run(func, *args, backend='asyncio', backend_options=None) -> T_Retval — Run a coroutine function in an async event loop.

run_process

async run_process(command, ...) -> CompletedProcess — Run an external command and wait for completion.

sleep

async sleep(delay) -> None — Pause current task for specified duration.

sleep_forever

async sleep_forever() -> None — Pause current task until cancelled.

sleep_until

async sleep_until(deadline) -> None — Pause current task until given time.

typed_attribute

typed_attribute() -> Any — Return a unique object to mark typed attributes.

wait_all_tasks_blocked

async wait_all_tasks_blocked() -> None — Wait until all other tasks are waiting for something.

wait_readable

wait_readable(obj) -> Awaitable[None] — Wait until the given object has data to be read.

wait_socket_readable

wait_socket_readable(sock) -> Awaitable[None] — Deprecated, use wait_readable.

wait_socket_writable

wait_socket_writable(sock) -> Awaitable[None] — Deprecated, use wait_writable.

wait_writable

wait_writable(obj) -> Awaitable[None] — Wait until the given object can be written to.

wrap_file

wrap_file(file, *, limiter=None) -> AsyncFile — Wrap an existing file as an async file.

📁 FILE

/home/chedong/.local/lib/python3.10/site-packages/anyio/__init__.py

anyio
📖 NAME 🚀 Quick Reference 📦 Package Contents 🏗️ Classes
AsyncContextManagerMixin AsyncFile BrokenResourceError BrokenWorkerInterpreter BrokenWorkerProcess BusyResourceError CancelScope CapacityLimiter CapacityLimiterStatistics ClosedResourceError Condition ConditionStatistics ConnectionFailed ContextManagerMixin DelimiterNotFound EndOfStream Event EventStatistics IncompleteRead Lock LockStatistics NamedTemporaryFile NoEventLoopError Path ResourceGuard RunFinishedError Semaphore SemaphoreStatistics SpooledTemporaryFile TCPConnectable TaskCancelled TaskFailed TaskHandle TaskInfo TaskNotFinished TemporaryDirectory TemporaryFile TypedAttributeLookupError TypedAttributeProvider TypedAttributeSet UNIXConnectable WouldBlock create_memory_object_stream
⚙️ Functions
__getattr__ aclose_forcefully as_connectable connect_tcp connect_unix create_connected_udp_socket create_connected_unix_datagram_socket create_task_group create_tcp_listener create_udp_socket create_unix_datagram_socket create_unix_listener current_effective_deadline current_time fail_after get_all_backends get_available_backends get_cancelled_exc_class get_current_task get_running_tasks getaddrinfo getnameinfo gettempdir gettempdirb mkdtemp mkstemp move_on_after notify_closing open_file open_process open_signal_receiver run run_process sleep sleep_forever sleep_until typed_attribute wait_all_tasks_blocked wait_readable wait_socket_readable wait_socket_writable wait_writable wrap_file
📁 FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-19 20:32 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^