Hasty Briefsbeta

Bilingual

Rewriting a 20-year-old Python library

3 days ago
  • #Akismet
  • #Software Rewrite
  • #Python
  • The author took over maintenance of the Akismet Python library in 2015 after its original creator, Michael Foord, could no longer maintain it.
  • The library was initially rewritten for Python 2 and 3 compatibility in 2017, simplifying configuration and replacing the standard HTTP stack with the requests library.
  • A major rewrite began in 2024 to add support for async/await and expose the Akismet API's three-state spam detection (ham, spam, blatant spam) using an enum.
  • The new design includes separate SyncClient and AsyncClient classes to handle synchronous and asynchronous operations cleanly.
  • Credential validation is handled via alternative constructors (validated_client) and context managers to ensure API keys are verified without blocking in async contexts.
  • The rewrite switched from the requests library to httpx, which supports both sync and async HTTP requests and allows custom HTTP clients to be passed in.
  • Testing improvements include TestSyncClient and TestAsyncClient subclasses that use httpx's MockTransport to avoid real HTTP requests, and a pytest plugin for easy integration.
  • Type hints were added for better documentation and type checking, and the project structure was reorganized into multiple files with private modules.
  • Calendar versioning was adopted for release numbering, and development tools were updated to use PDM for packaging and a Makefile for common tasks.
  • The final release (25.10.0) removed the old Akismet class, marking the completion of the rewrite with minimal breaking changes for users.