Client API¶
The client module provides the high-level API for querying Finger servers.
FingerClient¶
FingerClient
¶
High-level Finger client with async/await API.
This class provides a simple, high-level interface for querying Finger servers. It handles connection management, timeouts, and query parsing.
Examples:
>>> # Basic usage
>>> async with FingerClient() as client:
... response = await client.query("alice@example.com")
... print(response.body)
>>> # Query with verbose output
>>> async with FingerClient() as client:
... response = await client.query("/W alice", host="example.com")
>>> # Direct host/port specification
>>> client = FingerClient(timeout=10.0)
>>> response = await client.finger("example.com", query="alice")
Initialize the Finger client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Request timeout in seconds. Default is 30 seconds. |
DEFAULT_TIMEOUT
|
Source code in src/mapilli/client/session.py
query
async
¶
query(
query_string: str = "",
host: str | None = None,
port: int = DEFAULT_PORT,
) -> FingerResponse
Execute a Finger query.
Parses the query string to extract username and optional host. If host is embedded in query (user@host), uses that host. Otherwise uses the provided host parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_string
|
str
|
Query string (e.g., "alice", "alice@host", "/W alice") |
''
|
host
|
str | None
|
Target host (used if not in query_string) |
None
|
port
|
int
|
Target port |
DEFAULT_PORT
|
Returns:
| Type | Description |
|---|---|
FingerResponse
|
FingerResponse with query result |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no host specified and none in query |
TimeoutError
|
If request times out |
ConnectionError
|
If connection fails |
Source code in src/mapilli/client/session.py
finger
async
¶
Execute a raw Finger query to a specific host.
This is the low-level method that sends the query directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Target hostname |
required |
query
|
str
|
Raw query string (sent as-is + CRLF) |
''
|
port
|
int
|
Target port |
DEFAULT_PORT
|
Returns:
| Type | Description |
|---|---|
FingerResponse
|
FingerResponse with query result |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If request times out |
ConnectionError
|
If connection fails |
Source code in src/mapilli/client/session.py
__aenter__
async
¶
__aexit__
async
¶
Example Usage¶
Basic Query¶
from mapilli import FingerClient
async with FingerClient() as client:
response = await client.query("alice@example.com")
print(response.body)
With Custom Timeout¶
client = FingerClient(timeout=10.0)
async with client:
response = await client.query("alice@example.com")
Low-Level API¶
async with FingerClient() as client:
# Direct query to specific host
response = await client.finger("example.com", query="alice")