Skip to content

yaping reference API

Here's the reference or code API, the classes, functions, parameters, attributes, and all the yaping parts you can use in your applications.

If you want to learn yaping you are much better off reading the yaping User Guide.

Sync API

yaping.ping

Synchronous yaping API.

Here is an example using the functional API:

from yaping.ping import ping
from yaping.tools import response_text

for response in ping(["gnu.org", "orcid.org"], count=4):
    text = response_text(response)
    print(text)

Ping(sock: Socket, icmp_id: int | None = None, timeout: float | None = None)

Handle several hosts with a single "shared" ICMP socket

ping(hosts: Iterable[str], icmp_id: int | None = None, interval: float = 1, strict_interval: bool = False, count: int | None = None, timeout: float | None = 1) -> Iterable[dict]

Functional helper to ping a group of given hosts concurrently count number of times separated by interval (s). Infinine sequence of pings (default) is achieved with count=None. If strict_interval is True, a best effort is made to start group ping in fixed periods.

Example:

from yaping.ping import ping
from yaping.tools import response_text

for response in ping(["gnu.org", "orcid.org"], count=4):
    text = response_text(response)
    print(text)

Async API

yaping.aioping

Asynchronous yaping API.

Here is an example using the functional API:

import asyncio

from yaping.aioping import ping
from yaping.tools import response_text

async def pings(hosts):
    async for response in ping(hosts, count=4):
        text = response_text(response)
        print(text)

asyncio.run(pings(["gnu.org", "orcid.org"]))

AsyncPing(sock: Socket, icmp_id: int | None = None, timeout: float | None = None)

Handle several hosts with a single "shared" ICMP socket.

Example:

import asyncio

from yaping.aioping import AsyncPing
from yaping.tools import response_text
from yaping.socket import Socket

async def pings():
    sock = Socket()
    ping = AsyncPing(sock, icmp_id, timeout)
    async for response in ping.ping(hosts, interval, strict_interval, count):
        text = response_text(response)
        print(text)

asyncio.run(pings(["gnu.org", "orcid.org"]))

ping(hosts: Iterable[str], icmp_id: int | None = None, interval: float = 1, strict_interval: bool = False, count: int | None = None, timeout: float | None = 1) async

Functional helper to ping a group of given hosts concurrently count number of times separated by interval (s). Infinine sequence of pings (default) is achieved with count=None. If strict_interval is True, a best effort is made to start group ping in fixed periods.

Example:

import asyncio

from yaping.ping import ping
from yaping.tools import response_text

async def pings(hosts):
    async for response in ping(hosts, count=4):
        text = response_text(response)
        print(text)

asyncio.run(pings(["gnu.org", "orcid.org"]))

ICMP Socket

yaping.socket

Socket(family: socket.AddressFamily = socket.AF_INET, type: socket.SocketKind | None = None, timeout: float = 0)

Bases: socket

An ICMP socket