Skip to content

Drop FastAPI, uvicorn and httpx for the stdlib #4

Description

@STRML

src/hark/ has exactly two third-party runtime imports:

  • fastapi in app.py:15
  • httpx in whisper.py:8

Those two, plus uvicorn, pull 24 packages and 26 MB into the venv (uv tree: pydantic, pydantic-core, starlette, anyio, httpcore, certifi, h11, click, idna, typing-extensions, and the rest). Everything else the service imports is stdlib: wave, array, re, secrets, asyncio, logging, tomllib.

For one user sending one request at a time to loopback, http.server.ThreadingHTTPServer plus roughly 20 lines of hand-rolled multipart for the whisper-server call would cover it. Async buys nothing at this concurrency.

The catch

This does not remove the need for uv. System python3 on macOS is 3.9.6 with no tomllib, and config.py:16 needs 3.11 or newer. Depending on Apple's deprecated /usr/bin/python3 would be a worse dependency than a managed interpreter, not a better one.

So the win is 24 packages to 0, not "no Python toolchain". Lower priority than #2 and #3 for that reason.

Cost

  • hand-rolled multipart encoding, which is exactly the kind of thing a library gets right and a hand roll gets subtly wrong
  • losing fastapi.testclient, so tests/test_app.py needs reworking against a real socket or a hand-built request object
  • losing automatic 422 handling and the {"detail": ...} body shape that client/init.lua's extractDetail parses

That last one is a compatibility constraint, not just a nicety. Whatever replaces FastAPI has to keep emitting {"detail": "..."} or the client's error alerts go blank.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions