python
Python services, tooling and the packaging around them.
-
Tracking Meals and Automating Shopping With an MCP Server
An MCP server for meal tracking and grocery shopping automation: planned meals minus live stock, and why the v2 rebuild derives stock from an event journal.
-
Automating Web Shop Order Processing Before the Catalogue
Web shop order processing automated first: Stripe webhook payment confirmation, stock reservations, outbox-driven DHL labels, two manual steps.
-
A Daily Digest of What Actually Got Merged, Built from MQTT and a Local LLM
paho-mqtt subscriber to SQLite plus a local LLM: a daily digest that summarises merged pull requests per repository from diff stats, no cloud API.
-
The NTP Clock Jump That Made the Scheduler Skip a Week of Measurements
time.time() vs time.monotonic() in a Python scheduler: a backwards NTP step delayed runs by nine days. Monotonic durations and a jump-injecting test.
-
One Local Endpoint for Every Agent Session
OPENAI_BASE_URL=http://localhost:8080/v1 for every AI tool: one local FastAPI proxy that logs each request and refuses internal-only projects.
-
Testing an Agent Harness Without Ever Calling the Model
Unit testing a coding agent's tool-call permission layer with pytest and recorded fixtures: allow, deny or ask decisions with no model or API key.
-
A Deterministic Daemon That Turns a Labelled Issue Into a Pull Request
git apply --check before git commit: an issue-to-PR daemon where the model only returns a patch and plain Python commits, pushes and opens the PR.
-
The Transactional Outbox: Never Losing a Job You Already Committed
Transactional outbox in Postgres: commit-then-enqueue loses jobs on a crash. A SKIP LOCKED relay to Redis Streams and an idempotent consumer.
-
Building the Dry-Run Path First, and Testing That It Sends Nothing
if dry_run: return guards drift as side effects are added. Split the tool into a pure plan() and apply(), and test that dry run never calls the client.
-
Idempotent Payment Webhooks with a Deduplication Table
Payment webhook processed twice on retry: dedupe on the provider event ID with a primary key, committed in the same transaction as the side effect.
-
Modelling an Order Lifecycle as an Explicit State Machine
Python order status as a state machine: a transition table and one transition_to method that raises InvalidTransition on moves like shipping a cancelled order.
-
Migrating Redis Consumers from Python to C++ on Constrained Hardware
redis-plus-plus xreadgroup times out before its block timeout: set socket_timeout to 0. Replacing idle Python Redis stream consumers with C++.
-
UUID Case Normalization as a Recurring Cross-Service Bug
Uppercase vs lowercase UUID keys cause silent cache and database lookup misses between services. Normalise once at the boundary with str(uuid.UUID(value)).
-
Chaining Single-Purpose Redis Consumers into a Processing Pipeline
XREADGROUP, XACK and XAUTOCLAIM: splitting one Python consumer into single-purpose Redis Streams stages with at-least-once delivery and crash recovery.
-
A Python CLI That Scaffolds a Project Structure You Actually Want
Python scaffolding CLI with only argparse and string.Template: generates src layout, pyproject.toml, Dockerfile and .gitignore, tested with tomllib.
-
Replacing pip, venv, flake8, black and isort with uv and Ruff
uv sync --locked and ruff check replacing pip install -r requirements.txt, venv, flake8, black and isort: uv.lock plus one pyproject.toml config.
-
Configuration Precedence: Docker Secrets, Kubernetes Secrets, Environment, .env, Default
Docker secrets in /run/secrets, Kubernetes secret mounts, env vars and .env: a Python resolver with fixed precedence that reports which source won.
-
An Exception Hierarchy and One Handler for FastAPI Error Responses
FastAPI add_exception_handler on a base AppError instead of raising HTTPException in services: one status-code mapping and a consistent error body.
-
Designing a Consistent FastAPI Response Envelope
FastAPI response envelope with Pydantic Generic[T] and a custom APIRoute get_route_handler that wraps every response in success, data and error.
-
A Feature-Module Layout for a FastAPI Application That Keeps Growing
FastAPI APIRouter per feature directory with its own router.py, schemas.py and service.py, replacing a shared routers.py, schemas.py and crud.py.