Skip to content

Development

The source is on GitHub. It’s Python 3.12 with Streamlit 1.67, pandas 3 and Plotly 7, plus FastAPI for the mobile API (since 0.7.0).

app.py # Streamlit shell: navigation, sidebar, sign-in gating
sonarr_analyzer/
analysis.py # Streamlit-free analysis pipeline (metrics, outliers, re-encode estimates)
sonarr_client.py # Sonarr API client (URL validation, retries, parallel fetching)
media.py # Codec names, runtimes and disk usage from Sonarr media info
forecast.py # Storage trend, R², disk runway
overview.py # Dashboard/sidebar numbers built from saved history
storage.py, db.py # History database and schema migrations
auth.py, security.py # Users (bcrypt, lockout) and encrypted Sonarr credentials
scheduler.py # Scheduled analyses (thread or `python -m sonarr_analyzer.scheduler`)
dashboard.py # Which candidates, outliers and changes the Dashboard lists (web and API)
api.py # Mobile API (FastAPI, served by uvicorn on port 8502)
tls.py # Self-signed certificate and its fingerprint (`python -m sonarr_analyzer.tls`)
healthcheck.py # Container health check, http or https
config.py # Environment variables
ui/ # Shared components, session state and one module per page
tests/ # pytest suite
fixtures/api/ # Example API responses: the contract the mobile apps code against
spec/, tasks/ # Specs and task lists for the mobile API and apps
docs/design/ # UI design reference (direction C, "dense console")
.streamlit/config.toml # Light and dark theme
Terminal window
pip install -r requirements.txt
streamlit run app.py

The mobile API is a separate process. Run it next to the web app (both read the same data/ folder):

Terminal window
uvicorn sonarr_analyzer.api:app --port 8502 --reload
curl http://localhost:8502/api/v1/health

Run it with a single worker (uvicorn’s default): the sign-in rate limit is kept in memory, per process.

Terminal window
pip install -r requirements-dev.txt
pytest -v
pytest --cov=sonarr_analyzer --cov-report=html

To run them in the same environment as the image:

Terminal window
docker run --rm -v "$PWD":/src -w /src python:3.12-slim \
sh -c "pip install -q -r requirements-dev.txt && pytest -q"

The suite covers authentication, token encryption, storage, schema migrations from v0.3/v0.4/v0.6, the analysis pipeline, media metadata, the forecast and dashboard overview, the Sonarr client, the scheduler, the mobile API, the self-signed certificate, the health check, and UI tests for every page (Streamlit AppTest).

tests/test_api.py compares the API’s responses with the JSON files in tests/fixtures/api/. The mobile apps copy these files into their own tests, so they are the contract between the server and the apps. When you change a response on purpose, regenerate them and review the diff:

Terminal window
UPDATE_API_FIXTURES=1 pytest tests/test_api.py
git diff tests/fixtures/api/

Floats are compared rounded to 6 decimals, because numpy’s least-squares fit differs in the last digits between arm64 and amd64 (CI).

Terminal window
docker build -t sonarr-analyzer:local .

Releases are published for both architectures, as vX.Y.Z and latest:

Terminal window
docker buildx build --platform linux/amd64,linux/arm64 \
-t martitoci/sonarr-analyzer:vX.Y.Z -t martitoci/sonarr-analyzer:latest --push .
  1. Fork the repository and create a feature branch.
  2. Install the dev tools: pip install -r requirements-dev.txt && pre-commit install.
  3. Add tests for new features.
  4. Run pytest and make sure everything passes. CI also runs pre-commit, pip-audit and a Docker smoke test.
  5. Open a pull request.

The project is MIT-licensed.

Sonarr Analyzer v0.7.0 · GitHub · Docker Hub ·Report an issue

No trackers · MIT License · © Carlos Medina · Not affiliated with Sonarr