fastdotcom 0.0.7__tar.gz → 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastdotcom-0.1.0/.github/workflows/live_api.yml +30 -0
- fastdotcom-0.1.0/.github/workflows/main.yml +44 -0
- fastdotcom-0.1.0/.github/workflows/publish.yml +34 -0
- fastdotcom-0.1.0/.gitignore +39 -0
- fastdotcom-0.1.0/.pre-commit-config.yaml +15 -0
- fastdotcom-0.1.0/PKG-INFO +129 -0
- fastdotcom-0.1.0/README.md +99 -0
- fastdotcom-0.1.0/fastdotcom/__init__.py +158 -0
- fastdotcom-0.1.0/fastdotcom/cli.py +163 -0
- fastdotcom-0.1.0/fastdotcom/client.py +798 -0
- fastdotcom-0.1.0/fastdotcom/const.py +38 -0
- fastdotcom-0.1.0/fastdotcom/exceptions.py +19 -0
- fastdotcom-0.1.0/fastdotcom/models.py +59 -0
- fastdotcom-0.1.0/fastdotcom/py.typed +0 -0
- fastdotcom-0.1.0/pyproject.toml +108 -0
- fastdotcom-0.1.0/tests/__init__.py +0 -0
- fastdotcom-0.1.0/tests/conftest.py +247 -0
- fastdotcom-0.1.0/tests/test_cli.py +100 -0
- fastdotcom-0.1.0/tests/test_client.py +712 -0
- fastdotcom-0.1.0/tests/test_ha_compat.py +100 -0
- fastdotcom-0.1.0/tests/test_real_api_calls.py +57 -0
- fastdotcom-0.1.0/uv.lock +1456 -0
- fastdotcom-0.0.7/PKG-INFO +0 -16
- fastdotcom-0.0.7/README.md +0 -55
- fastdotcom-0.0.7/fastdotcom/__init__.py +0 -743
- fastdotcom-0.0.7/fastdotcom.egg-info/PKG-INFO +0 -16
- fastdotcom-0.0.7/fastdotcom.egg-info/SOURCES.txt +0 -10
- fastdotcom-0.0.7/fastdotcom.egg-info/dependency_links.txt +0 -1
- fastdotcom-0.0.7/fastdotcom.egg-info/requires.txt +0 -2
- fastdotcom-0.0.7/fastdotcom.egg-info/top_level.txt +0 -1
- fastdotcom-0.0.7/fastdotcom.egg-info/zip-safe +0 -1
- fastdotcom-0.0.7/setup.cfg +0 -4
- fastdotcom-0.0.7/setup.py +0 -43
- {fastdotcom-0.0.7 → fastdotcom-0.1.0}/LICENSE +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Runs an ultra-low-bandwidth Fast.com protocol smoke test (single connection,
|
|
2
|
+
# 4 KiB byte-range probes, <1 MiB total) rather than a full throughput benchmark
|
|
3
|
+
# so GitHub-hosted runner traffic remains minimal and GitHub AUP compliant.
|
|
4
|
+
name: Live Fast.com API Smoke Test
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
schedule:
|
|
8
|
+
- cron: "0 10 * * 1"
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
live-api:
|
|
13
|
+
name: Live fast.com protocol smoke test
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Check out repository
|
|
18
|
+
uses: actions/checkout@v7
|
|
19
|
+
|
|
20
|
+
- name: Set up uv and Python 3.13
|
|
21
|
+
uses: astral-sh/setup-uv@v10.4.0
|
|
22
|
+
with:
|
|
23
|
+
enable-cache: true
|
|
24
|
+
python-version: "3.13"
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --locked --all-groups
|
|
28
|
+
|
|
29
|
+
- name: Run minimal-bandwidth live Fast.com smoke test
|
|
30
|
+
run: uv run pytest -m real_api_call --no-cov
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Python ${{ matrix.python-version }}
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Check out repository
|
|
20
|
+
uses: actions/checkout@v7
|
|
21
|
+
|
|
22
|
+
- name: Set up uv and Python ${{ matrix.python-version }}
|
|
23
|
+
uses: astral-sh/setup-uv@v10.4.0
|
|
24
|
+
with:
|
|
25
|
+
enable-cache: true
|
|
26
|
+
python-version: ${{ matrix.python-version }}
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: uv sync --locked --all-groups
|
|
30
|
+
|
|
31
|
+
- name: Ruff lint
|
|
32
|
+
run: uv run ruff check --no-fix .
|
|
33
|
+
|
|
34
|
+
- name: Ruff format check
|
|
35
|
+
run: uv run ruff format --check .
|
|
36
|
+
|
|
37
|
+
- name: Mypy type check
|
|
38
|
+
run: uv run mypy fastdotcom tests
|
|
39
|
+
|
|
40
|
+
- name: Run offline test suite with branch coverage
|
|
41
|
+
run: uv run pytest --cov-report=xml:coverage.xml
|
|
42
|
+
|
|
43
|
+
- name: Build package
|
|
44
|
+
run: uv build
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Build and publish to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: pypi
|
|
14
|
+
url: https://pypi.org/p/fastdotcom
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
id-token: write
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Check out repository
|
|
21
|
+
uses: actions/checkout@v7
|
|
22
|
+
|
|
23
|
+
- name: Set up uv
|
|
24
|
+
uses: astral-sh/setup-uv@v10.4.0
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.13"
|
|
27
|
+
|
|
28
|
+
- name: Build distribution artifacts
|
|
29
|
+
run: uv build
|
|
30
|
+
|
|
31
|
+
- name: Publish package to PyPI
|
|
32
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
33
|
+
with:
|
|
34
|
+
attestations: true
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Packaging / distribution
|
|
7
|
+
*.egg-info/
|
|
8
|
+
.installed.cfg
|
|
9
|
+
*.egg
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
ENV/
|
|
17
|
+
|
|
18
|
+
# Test, lint & type-check caches
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
.mypy_cache/
|
|
21
|
+
.ruff_cache/
|
|
22
|
+
.tox/
|
|
23
|
+
.nox/
|
|
24
|
+
|
|
25
|
+
# Coverage reports
|
|
26
|
+
.coverage
|
|
27
|
+
.coverage.*
|
|
28
|
+
coverage.xml
|
|
29
|
+
htmlcov/
|
|
30
|
+
|
|
31
|
+
# Environment & secrets
|
|
32
|
+
.env
|
|
33
|
+
.env.*
|
|
34
|
+
|
|
35
|
+
# IDEs & OS artifacts
|
|
36
|
+
.vscode/
|
|
37
|
+
.idea/
|
|
38
|
+
.DS_Store
|
|
39
|
+
Thumbs.db
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v6.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: trailing-whitespace
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: check-yaml
|
|
8
|
+
- id: check-toml
|
|
9
|
+
- id: check-merge-conflict
|
|
10
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
11
|
+
rev: v0.17.6
|
|
12
|
+
hooks:
|
|
13
|
+
- id: ruff-check
|
|
14
|
+
args: [--fix]
|
|
15
|
+
- id: ruff-format
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: fastdotcom
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async Python API and CLI for testing internet speed on Fast.com
|
|
5
|
+
Project-URL: Homepage, https://github.com/nkgilley/fast.com
|
|
6
|
+
Project-URL: Repository, https://github.com/nkgilley/fast.com
|
|
7
|
+
Project-URL: Issues, https://github.com/nkgilley/fast.com/issues
|
|
8
|
+
Author: Nolan Gilley
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: aiohttp,asyncio,fast.com,home-assistant,network,speedtest
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
24
|
+
Classifier: Topic :: Internet
|
|
25
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.11
|
|
28
|
+
Requires-Dist: aiohttp>=3.10.0
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# fastdotcom
|
|
32
|
+
|
|
33
|
+
`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.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **Pure `asyncio` + `aiohttp`:** Native async client with optional external `aiohttp.ClientSession` injection (ideal for Home Assistant and other async applications).
|
|
38
|
+
- **Download & Upload Speed Tests:** Dynamically scales parallel connections and stops early once throughput stabilizes.
|
|
39
|
+
- **Unloaded & Loaded Latency:** Measures HTTP RTT via keep-alive `/speedtest/range/0-0` probes (works in rootless containers without raw ICMP privileges).
|
|
40
|
+
- **Backwards-Compatible Sync API:** Preserves `fast_com()` returning a metrics dictionary.
|
|
41
|
+
- **Command-Line Interface:** Includes a `fastdotcom` CLI with human-readable and `--json` output.
|
|
42
|
+
- **Typed:** Ships with frozen dataclasses, typed exceptions, and PEP 561 `py.typed`.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
Install `fastdotcom` from PyPI:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install fastdotcom
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Async API (Recommended)
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
from fastdotcom import async_fast_com
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def main() -> None:
|
|
62
|
+
result = await async_fast_com(max_time=10)
|
|
63
|
+
print(f"Download: {result.download_speed:.2f} Mbps")
|
|
64
|
+
print(f"Upload: {result.upload_speed:.2f} Mbps")
|
|
65
|
+
print(f"Unloaded Ping: {result.unloaded_ping:.2f} ms")
|
|
66
|
+
print(f"Loaded Ping: {result.loaded_ping:.2f} ms")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
You can also pass an existing `aiohttp.ClientSession` (which `fastdotcom` will never close):
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import aiohttp
|
|
76
|
+
from fastdotcom import FastDotComClient
|
|
77
|
+
|
|
78
|
+
async with aiohttp.ClientSession() as session:
|
|
79
|
+
async with FastDotComClient(session=session) as client:
|
|
80
|
+
result = await client.run_speedtest(max_time=10)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Synchronous API
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import fastdotcom
|
|
87
|
+
|
|
88
|
+
result = fastdotcom.fast_com(max_time=10)
|
|
89
|
+
print(result)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Example output:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
{
|
|
96
|
+
"download_speed": 189.08,
|
|
97
|
+
"upload_speed": 125.36,
|
|
98
|
+
"unloaded_ping": 23.53,
|
|
99
|
+
"loaded_ping": 61.8,
|
|
100
|
+
"success": 1,
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- **Download Speed:** Measured download speed in Mbps.
|
|
105
|
+
- **Upload Speed:** Measured upload speed in Mbps.
|
|
106
|
+
- **Unloaded Ping:** Average HTTP latency (ms) when the network is idle.
|
|
107
|
+
- **Loaded Ping:** Average HTTP latency (ms) during the download test.
|
|
108
|
+
- **Success:** `1` when the speed test succeeds. Network, timeout, or token errors raise a `FastDotComError` subclass (`FastDotComConnectionError`, `FastDotComTimeoutError`, or `FastDotComTokenError`).
|
|
109
|
+
|
|
110
|
+
### CLI
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
fastdotcom
|
|
114
|
+
fastdotcom --max-time 10 --json
|
|
115
|
+
fastdotcom --no-upload --no-latency
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Requirements
|
|
119
|
+
|
|
120
|
+
- Python 3.11 or newer
|
|
121
|
+
- `aiohttp>=3.10.0`
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
`fastdotcom` is released under the MIT License. See [LICENSE](LICENSE) for details.
|
|
126
|
+
|
|
127
|
+
## Contributing
|
|
128
|
+
|
|
129
|
+
Contributions are welcome! Please feel free to submit a pull request on GitHub.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# fastdotcom
|
|
2
|
+
|
|
3
|
+
`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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Pure `asyncio` + `aiohttp`:** Native async client with optional external `aiohttp.ClientSession` injection (ideal for Home Assistant and other async applications).
|
|
8
|
+
- **Download & Upload Speed Tests:** Dynamically scales parallel connections and stops early once throughput stabilizes.
|
|
9
|
+
- **Unloaded & Loaded Latency:** Measures HTTP RTT via keep-alive `/speedtest/range/0-0` probes (works in rootless containers without raw ICMP privileges).
|
|
10
|
+
- **Backwards-Compatible Sync API:** Preserves `fast_com()` returning a metrics dictionary.
|
|
11
|
+
- **Command-Line Interface:** Includes a `fastdotcom` CLI with human-readable and `--json` output.
|
|
12
|
+
- **Typed:** Ships with frozen dataclasses, typed exceptions, and PEP 561 `py.typed`.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install `fastdotcom` from PyPI:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install fastdotcom
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Async API (Recommended)
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import asyncio
|
|
28
|
+
from fastdotcom import async_fast_com
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
async def main() -> None:
|
|
32
|
+
result = await async_fast_com(max_time=10)
|
|
33
|
+
print(f"Download: {result.download_speed:.2f} Mbps")
|
|
34
|
+
print(f"Upload: {result.upload_speed:.2f} Mbps")
|
|
35
|
+
print(f"Unloaded Ping: {result.unloaded_ping:.2f} ms")
|
|
36
|
+
print(f"Loaded Ping: {result.loaded_ping:.2f} ms")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
asyncio.run(main())
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
You can also pass an existing `aiohttp.ClientSession` (which `fastdotcom` will never close):
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import aiohttp
|
|
46
|
+
from fastdotcom import FastDotComClient
|
|
47
|
+
|
|
48
|
+
async with aiohttp.ClientSession() as session:
|
|
49
|
+
async with FastDotComClient(session=session) as client:
|
|
50
|
+
result = await client.run_speedtest(max_time=10)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Synchronous API
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import fastdotcom
|
|
57
|
+
|
|
58
|
+
result = fastdotcom.fast_com(max_time=10)
|
|
59
|
+
print(result)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Example output:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
{
|
|
66
|
+
"download_speed": 189.08,
|
|
67
|
+
"upload_speed": 125.36,
|
|
68
|
+
"unloaded_ping": 23.53,
|
|
69
|
+
"loaded_ping": 61.8,
|
|
70
|
+
"success": 1,
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- **Download Speed:** Measured download speed in Mbps.
|
|
75
|
+
- **Upload Speed:** Measured upload speed in Mbps.
|
|
76
|
+
- **Unloaded Ping:** Average HTTP latency (ms) when the network is idle.
|
|
77
|
+
- **Loaded Ping:** Average HTTP latency (ms) during the download test.
|
|
78
|
+
- **Success:** `1` when the speed test succeeds. Network, timeout, or token errors raise a `FastDotComError` subclass (`FastDotComConnectionError`, `FastDotComTimeoutError`, or `FastDotComTokenError`).
|
|
79
|
+
|
|
80
|
+
### CLI
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
fastdotcom
|
|
84
|
+
fastdotcom --max-time 10 --json
|
|
85
|
+
fastdotcom --no-upload --no-latency
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Requirements
|
|
89
|
+
|
|
90
|
+
- Python 3.11 or newer
|
|
91
|
+
- `aiohttp>=3.10.0`
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
`fastdotcom` is released under the MIT License. See [LICENSE](LICENSE) for details.
|
|
96
|
+
|
|
97
|
+
## Contributing
|
|
98
|
+
|
|
99
|
+
Contributions are welcome! Please feel free to submit a pull request on GitHub.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Public API and Home Assistant drop-in facade for fastdotcom."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import logging
|
|
7
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from .client import FastDotComClient, decode_json_bytes, to_range_url
|
|
11
|
+
from .const import (
|
|
12
|
+
DEFAULT_CONNECTIONS_MAX,
|
|
13
|
+
DEFAULT_CONNECTIONS_MIN,
|
|
14
|
+
DEFAULT_MAX_TIME,
|
|
15
|
+
DEFAULT_MIN_TIME,
|
|
16
|
+
DEFAULT_PING_COUNT,
|
|
17
|
+
DEFAULT_PING_INTERVAL,
|
|
18
|
+
DEFAULT_TIMEOUT,
|
|
19
|
+
DEFAULT_UPLOAD_PAYLOAD_SIZE,
|
|
20
|
+
DEFAULT_URL_COUNT,
|
|
21
|
+
FAST_API_V2_URL,
|
|
22
|
+
FAST_COM_URL,
|
|
23
|
+
)
|
|
24
|
+
from .exceptions import (
|
|
25
|
+
FastDotComConnectionError,
|
|
26
|
+
FastDotComError,
|
|
27
|
+
FastDotComTimeoutError,
|
|
28
|
+
FastDotComTokenError,
|
|
29
|
+
)
|
|
30
|
+
from .models import (
|
|
31
|
+
FastClientInfo,
|
|
32
|
+
FastLocation,
|
|
33
|
+
FastSpeedtestResult,
|
|
34
|
+
FastTarget,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
import aiohttp
|
|
39
|
+
|
|
40
|
+
__version__ = "0.1.0"
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"FastClientInfo",
|
|
44
|
+
"FastDotComClient",
|
|
45
|
+
"FastDotComConnectionError",
|
|
46
|
+
"FastDotComError",
|
|
47
|
+
"FastDotComTimeoutError",
|
|
48
|
+
"FastDotComTokenError",
|
|
49
|
+
"FastLocation",
|
|
50
|
+
"FastSpeedtestResult",
|
|
51
|
+
"FastTarget",
|
|
52
|
+
"__version__",
|
|
53
|
+
"async_fast_com",
|
|
54
|
+
"decode_json_bytes",
|
|
55
|
+
"fast_com",
|
|
56
|
+
"to_range_url",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
_LOGGER = logging.getLogger(__name__)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
async def async_fast_com(
|
|
63
|
+
*,
|
|
64
|
+
session: aiohttp.ClientSession | None = None,
|
|
65
|
+
min_time: float = DEFAULT_MIN_TIME,
|
|
66
|
+
max_time: float = DEFAULT_MAX_TIME,
|
|
67
|
+
ping_count: int = DEFAULT_PING_COUNT,
|
|
68
|
+
ping_interval: float = DEFAULT_PING_INTERVAL,
|
|
69
|
+
url_count: int = DEFAULT_URL_COUNT,
|
|
70
|
+
connections_min: int = DEFAULT_CONNECTIONS_MIN,
|
|
71
|
+
connections_max: int = DEFAULT_CONNECTIONS_MAX,
|
|
72
|
+
upload_payload_size: int = DEFAULT_UPLOAD_PAYLOAD_SIZE,
|
|
73
|
+
measure_download: bool = True,
|
|
74
|
+
measure_upload: bool = True,
|
|
75
|
+
measure_latency: bool = True,
|
|
76
|
+
force_ipv4: bool = False,
|
|
77
|
+
force_ipv6: bool = False,
|
|
78
|
+
request_timeout: float = DEFAULT_TIMEOUT,
|
|
79
|
+
fast_com_url: str | None = None,
|
|
80
|
+
api_url: str | None = None,
|
|
81
|
+
) -> FastSpeedtestResult:
|
|
82
|
+
"""Measure Internet speed asynchronously using Fast.com API v2."""
|
|
83
|
+
async with FastDotComClient(
|
|
84
|
+
session=session,
|
|
85
|
+
timeout=request_timeout,
|
|
86
|
+
force_ipv4=force_ipv4,
|
|
87
|
+
force_ipv6=force_ipv6,
|
|
88
|
+
fast_com_url=FAST_COM_URL if fast_com_url is None else fast_com_url,
|
|
89
|
+
api_url=FAST_API_V2_URL if api_url is None else api_url,
|
|
90
|
+
) as client:
|
|
91
|
+
return await client.run_speedtest(
|
|
92
|
+
min_time=min_time,
|
|
93
|
+
max_time=max_time,
|
|
94
|
+
ping_count=ping_count,
|
|
95
|
+
ping_interval=ping_interval,
|
|
96
|
+
url_count=url_count,
|
|
97
|
+
connections_min=connections_min,
|
|
98
|
+
connections_max=connections_max,
|
|
99
|
+
upload_payload_size=upload_payload_size,
|
|
100
|
+
measure_download=measure_download,
|
|
101
|
+
measure_upload=measure_upload,
|
|
102
|
+
measure_latency=measure_latency,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def fast_com(
|
|
107
|
+
verbose: bool = False,
|
|
108
|
+
max_time: float = DEFAULT_MAX_TIME,
|
|
109
|
+
ping_count: int = DEFAULT_PING_COUNT,
|
|
110
|
+
force_ipv4: bool = False,
|
|
111
|
+
force_ipv6: bool = False,
|
|
112
|
+
payload_size: int | None = None,
|
|
113
|
+
max_payload_size: int | None = None,
|
|
114
|
+
) -> dict[str, float]:
|
|
115
|
+
"""Synchronous drop-in compatible speedtest entrypoint for Home Assistant."""
|
|
116
|
+
if payload_size is not None and payload_size <= 0:
|
|
117
|
+
raise ValueError("payload_size must be positive")
|
|
118
|
+
if max_payload_size is not None and max_payload_size <= 0:
|
|
119
|
+
raise ValueError("max_payload_size must be positive")
|
|
120
|
+
|
|
121
|
+
effective_min_time = min(DEFAULT_MIN_TIME, max_time)
|
|
122
|
+
effective_payload_size = DEFAULT_UPLOAD_PAYLOAD_SIZE
|
|
123
|
+
if payload_size is not None and max_payload_size is not None:
|
|
124
|
+
effective_payload_size = min(payload_size, max_payload_size)
|
|
125
|
+
elif payload_size is not None:
|
|
126
|
+
effective_payload_size = payload_size
|
|
127
|
+
elif max_payload_size is not None:
|
|
128
|
+
effective_payload_size = max_payload_size
|
|
129
|
+
|
|
130
|
+
async def _run() -> FastSpeedtestResult:
|
|
131
|
+
return await async_fast_com(
|
|
132
|
+
min_time=effective_min_time,
|
|
133
|
+
max_time=max_time,
|
|
134
|
+
ping_count=ping_count,
|
|
135
|
+
force_ipv4=force_ipv4,
|
|
136
|
+
force_ipv6=force_ipv6,
|
|
137
|
+
upload_payload_size=effective_payload_size,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
asyncio.get_running_loop()
|
|
142
|
+
except RuntimeError:
|
|
143
|
+
result = asyncio.run(_run())
|
|
144
|
+
else:
|
|
145
|
+
with ThreadPoolExecutor(max_workers=1) as pool:
|
|
146
|
+
result = pool.submit(asyncio.run, _run()).result()
|
|
147
|
+
|
|
148
|
+
if verbose:
|
|
149
|
+
_LOGGER.info(
|
|
150
|
+
"Fast.com speedtest complete: download=%.2f Mbps, upload=%.2f Mbps, "
|
|
151
|
+
"unloaded_ping=%.2f ms, loaded_ping=%.2f ms",
|
|
152
|
+
result.download_speed,
|
|
153
|
+
result.upload_speed,
|
|
154
|
+
result.unloaded_ping,
|
|
155
|
+
result.loaded_ping,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return result.to_dict()
|