Metadata-Version: 2.5
Name: fastdotcom
Version: 0.1.0
Summary: Async Python API and CLI for testing internet speed on Fast.com
Project-URL: Homepage, https://github.com/nkgilley/fast.com
Project-URL: Repository, https://github.com/nkgilley/fast.com
Project-URL: Issues, https://github.com/nkgilley/fast.com/issues
Author: Nolan Gilley
License-Expression: MIT
License-File: LICENSE
Keywords: aiohttp,asyncio,fast.com,home-assistant,network,speedtest
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Internet
Classifier: Topic :: System :: Networking :: Monitoring
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: aiohttp>=3.10.0
Description-Content-Type: text/markdown

# fastdotcom

`fastdotcom` is an asynchronous Python library and CLI for running internet speed tests using Netflix's [Fast.com](https://fast.com) API v2. It measures download speed, upload speed, and unloaded/loaded HTTP latency without requiring raw ICMP socket privileges.

## Features

- **Pure `asyncio` + `aiohttp`:** Native async client with optional external `aiohttp.ClientSession` injection (ideal for Home Assistant and other async applications).
- **Download & Upload Speed Tests:** Dynamically scales parallel connections and stops early once throughput stabilizes.
- **Unloaded & Loaded Latency:** Measures HTTP RTT via keep-alive `/speedtest/range/0-0` probes (works in rootless containers without raw ICMP privileges).
- **Backwards-Compatible Sync API:** Preserves `fast_com()` returning a metrics dictionary.
- **Command-Line Interface:** Includes a `fastdotcom` CLI with human-readable and `--json` output.
- **Typed:** Ships with frozen dataclasses, typed exceptions, and PEP 561 `py.typed`.

## Installation

Install `fastdotcom` from PyPI:

```bash
pip install fastdotcom
```

## Usage

### Async API (Recommended)

```python
import asyncio
from fastdotcom import async_fast_com


async def main() -> None:
    result = await async_fast_com(max_time=10)
    print(f"Download: {result.download_speed:.2f} Mbps")
    print(f"Upload: {result.upload_speed:.2f} Mbps")
    print(f"Unloaded Ping: {result.unloaded_ping:.2f} ms")
    print(f"Loaded Ping: {result.loaded_ping:.2f} ms")


asyncio.run(main())
```

You can also pass an existing `aiohttp.ClientSession` (which `fastdotcom` will never close):

```python
import aiohttp
from fastdotcom import FastDotComClient

async with aiohttp.ClientSession() as session:
    async with FastDotComClient(session=session) as client:
        result = await client.run_speedtest(max_time=10)
```

### Synchronous API

```python
import fastdotcom

result = fastdotcom.fast_com(max_time=10)
print(result)
```

Example output:

```python
{
    "download_speed": 189.08,
    "upload_speed": 125.36,
    "unloaded_ping": 23.53,
    "loaded_ping": 61.8,
    "success": 1,
}
```

- **Download Speed:** Measured download speed in Mbps.
- **Upload Speed:** Measured upload speed in Mbps.
- **Unloaded Ping:** Average HTTP latency (ms) when the network is idle.
- **Loaded Ping:** Average HTTP latency (ms) during the download test.
- **Success:** `1` when the speed test succeeds. Network, timeout, or token errors raise a `FastDotComError` subclass (`FastDotComConnectionError`, `FastDotComTimeoutError`, or `FastDotComTokenError`).

### CLI

```bash
fastdotcom
fastdotcom --max-time 10 --json
fastdotcom --no-upload --no-latency
```

## Requirements

- Python 3.11 or newer
- `aiohttp>=3.10.0`

## License

`fastdotcom` is released under the MIT License. See [LICENSE](LICENSE) for details.

## Contributing

Contributions are welcome! Please feel free to submit a pull request on GitHub.
