anyio
| Use Case | Command | Description |
|---|---|---|
| Run an async function | anyio.run(func, *args) | Run a coroutine in an event loop (asyncio/trio) |
| Create a task group | anyio.create_task_group() | Create a task group for structured concurrency |
| Open an async file | await anyio.open_file(...) | Open a file with async I/O |
| Connect TCP | await anyio.connect_tcp(host, port) | Connect to a TCP server |
| Create a memory object stream | send, recv = anyio.create_memory_object_stream() | Create an in-memory channel for objects |
| Sleep | await anyio.sleep(seconds) | Pause the current task |
| Timeout | with anyio.fail_after(delay): ... | Raise TimeoutError after delay |
| Cancel scope | with anyio.CancelScope() as scope: ... | Make a block cancellable |
| Run in subprocess | result = await anyio.run_process(...) | Run an external command and wait for completion |
| Async path operations | await anyio.Path('/tmp').read_text() | Async file path operations |
_backends (package)_core (package)abc (package)from_threadfunctoolsitertoolslowlevelpytest_pluginstreams (package)to_interpreterto_processto_threadMixin class providing async context manager functionality via a generator-based implementation.
async __aenter__(self) -> _T_coasync __aexit__(self, exc_type, exc_val, exc_tb) -> _ExitT_co__asynccontextmanager__(self) -> AbstractAsyncContextManager — Implement your async context manager logic here.An asynchronous file object. Wraps a standard file object and provides async friendly versions of blocking methods.
__init__(self, fp, *, limiter=None)async __aiter__(self) -> AsyncIterator__getattr__(self, name)async aclose(self)async flush(self)async read(self, size=-1)async read1(self, size=-1) (bytes only)async readinto(self, b) (bytes only)async readinto1(self, b) (bytes only)async readline(self)async readlines(self)async seek(self, offset, whence=0)async tell(self)async truncate(self, size=None)async write(self, b)async writelines(self, lines)Readonly properties: limiter, wrapped
Raised when trying to use a resource that has been rendered unusable due to external causes.
Raised by anyio.to_interpreter.run_sync if an unexpected exception is raised in the subinterpreter.
Raised by anyio.to_process.run_sync if the worker process terminates abruptly.
Raised when two tasks are trying to read from or write to the same resource concurrently.
Wraps a unit of work that can be made separately cancellable.
cancel(self, reason=None) — Cancel this scope immediately.cancel_called, cancelled_caughtdeadline, shieldUsed to limit the number of concurrent operations.
async acquire(self)acquire_nowait(self)async acquire_on_behalf_of(self, borrower)acquire_on_behalf_of_nowait(self, borrower)release(self)release_on_behalf_of(self, borrower)statistics(self) -> CapacityLimiterStatisticsavailable_tokens, borrowed_tokenstotal_tokensData class with fields: borrowed_tokens, total_tokens, borrowers, tasks_waiting.
Raised when trying to use a resource that has been closed.
Async condition variable.
async acquire(self)acquire_nowait(self)locked(self) -> boolnotify(self, n=1)notify_all(self)release(self)statistics(self) -> ConditionStatisticsasync wait(self)async wait_for(self, predicate)Data class with fields: tasks_waiting, lock_statistics.
Raised when a connection attempt fails. Inherits from OSError.
Mixin class providing context manager functionality via a generator-based implementation.
Raised during BufferedByteReceiveStream.receive_until if max bytes read without delimiter.
Raised when trying to read from a stream that has been closed from the other end.
Async event.
is_set(self) -> boolset(self)statistics(self) -> EventStatisticsasync wait(self)Data class with field: tasks_waiting.
Raised during BufferedByteReceiveStream.receive_exactly or receive_until if connection closed before requested amount.
Async lock.
async acquire(self)acquire_nowait(self)locked(self) -> boolrelease(self)statistics(self) -> LockStatisticsData class with fields: locked, owner, tasks_waiting.
Async named temporary file.
async __aenter__(self) -> AsyncFileasync __aexit__(self, ...)Raised when no event loop is running in the current thread.
Async version of pathlib.Path.
Path(*args, limiter=None)absolute, chmod, exists, expanduser, glob, group, hardlink_to, is_block_device, is_char_device, is_dir, is_fifo, is_file, is_mount, is_socket, is_symlink, iterdir, lchmod, lstat, mkdir, open, owner, read_bytes, read_text, readlink, rename, replace, resolve, rglob, rmdir, samefile, stat, symlink_to, touch, unlink, write_bytes, write_textasync cwd(), async home()Context manager for ensuring a resource is only used by a single task at a time.
Raised by from_thread.run/run_sync if the event loop has already finished.
Async semaphore.
async acquire(self)acquire_nowait(self)release(self)statistics(self) -> SemaphoreStatisticsmax_value, valueData class with field: tasks_waiting.
Async spooled temporary file that starts in memory and is spooled to disk.
AsyncFile.async rollover(self)closedConnects to a TCP server.
__init__(self, host, port)async connect(self) -> SocketStreamRaised when awaiting on a TaskHandle that was cancelled. Inherits from TaskFailed.
Raised when awaiting on a TaskHandle that raised an exception.
Returned from task-spawning methods of TaskGroup. Can be awaited to get the return value.
cancel(self) — Set the task to a cancelled state.async wait(self) — Wait for the task to finish.coro, exception, name, return_value, start_value, statusStatus: PENDING, FINISHED, CANCELLING, CANCELLED, FAILEDRepresents an asynchronous task.
id, parent_id, name, corohas_pending_cancellation(self) -> boolRaised when attempting to access the return value or exception of a TaskHandle that is still pending.
Async temporary directory.
async __aenter__(self) -> strasync cleanup(self)Async temporary file.
async __aenter__(self) -> AsyncFileRaised by TypedAttributeProvider.extra when attribute not found and no default.
Base class for classes that provide typed extra attributes.
extra(self, attribute, default=undefined)extra_attributesSuperclass for typed attribute collections.
Connects to a UNIX domain socket.
__init__(self, path)async connect(self) -> UNIXSocketStreamRaised by X_nowait functions if X() would block.
Creates a memory object stream. Returns a tuple of (MemoryObjectSendStream, MemoryObjectReceiveStream).
__getattr__(attr: str) -> type[BrokenWorkerInterpreter] — Support deprecated aliases.
async aclose_forcefully(resource: AsyncResource) -> None — Close an async resource in a cancelled scope.
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.
async connect_tcp(remote_host, remote_port, *, ...) -> SocketStream | TLSStream — Connect to a host using TCP with Happy Eyeballs.
async connect_unix(path) -> UNIXSocketStream — Connect to a UNIX socket.
async create_connected_udp_socket(remote_host, remote_port, ...) -> ConnectedUDPSocket
async create_connected_unix_datagram_socket(remote_path, ...) -> ConnectedUNIXDatagramSocket
create_task_group() -> TaskGroup — Create a task group.
async create_tcp_listener(*, ...) -> MultiListener
async create_udp_socket(family, ...) -> UDPSocket
async create_unix_datagram_socket(*, ...) -> UNIXDatagramSocket
async create_unix_listener(path, ...) -> SocketListener
current_effective_deadline() -> float — Return the nearest deadline among all cancel scopes.
current_time() -> float — Return the current value of the event loop's internal clock.
fail_after(delay, shield=False) -> Generator[CancelScope, None, None] — Context manager that raises TimeoutError if not finished in time.
get_all_backends() -> tuple[str, ...] — Return names of all built-in backends.
get_available_backends() -> tuple[str, ...] — Test for availability of built-in backends.
get_cancelled_exc_class() -> type[BaseException] — Return cancellation exception class.
get_current_task() -> TaskInfo — Return the current task.
get_running_tasks() -> list[TaskInfo] — Return list of running tasks.
async getaddrinfo(host, port, ...) -> list[tuple[...]] — Look up numeric IP address given host name.
getnameinfo(sockaddr, flags=0) -> Awaitable[tuple[str, str]] — Look up host name of an IP address.
async gettempdir() -> str — Return temporary directory name.
async gettempdirb() -> bytes — Return temporary directory name as bytes.
async mkdtemp(suffix, prefix, dir) -> str | bytes — Create a temporary directory.
async mkstemp(suffix, prefix, dir, text=False) -> tuple[int, str | bytes] — Create a temporary file.
move_on_after(delay, shield=False) -> CancelScope — Create a cancel scope with a deadline that expires after the given delay.
notify_closing(obj) -> None — Call before closing a file descriptor or socket to wake up waiters.
async open_file(file, mode='r', ..., limiter=None) -> AsyncFile — Open a file asynchronously.
async open_process(command, ...) -> Process — Start an external command in a subprocess.
open_signal_receiver(*signals) -> AbstractContextManager[AsyncIterator[Signals]] — Start receiving OS signals.
run(func, *args, backend='asyncio', backend_options=None) -> T_Retval — Run a coroutine function in an async event loop.
async run_process(command, ...) -> CompletedProcess — Run an external command and wait for completion.
async sleep(delay) -> None — Pause current task for specified duration.
async sleep_forever() -> None — Pause current task until cancelled.
async sleep_until(deadline) -> None — Pause current task until given time.
typed_attribute() -> Any — Return a unique object to mark typed attributes.
async wait_all_tasks_blocked() -> None — Wait until all other tasks are waiting for something.
wait_readable(obj) -> Awaitable[None] — Wait until the given object has data to be read.
wait_socket_readable(sock) -> Awaitable[None] — Deprecated, use wait_readable.
wait_socket_writable(sock) -> Awaitable[None] — Deprecated, use wait_writable.
wait_writable(obj) -> Awaitable[None] — Wait until the given object can be written to.
wrap_file(file, *, limiter=None) -> AsyncFile — Wrap an existing file as an async file.
/home/chedong/.local/lib/python3.10/site-packages/anyio/__init__.py
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)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format