</>CodeWithKarani
All topics
Topic

Python & FastAPI

FastAPI, async, packaging and the ORM - building and shipping Python services without the event loop or the dependency tree fighting you.

Sub-topics

40 articles · showing 1-9 (page 1 of 5)

AI Engineering6 min read

Metering, model routing and the regression suite that stops your agent rotting

Two questions decide whether an AI feature survives its first year: does each request make money, and will a prompt edit break something silently? An append-only credit ledger, two-tier routing, and a suite that asserts question-to-metric mappings are the answers.

Read
Security12 min read

Exactly-once over an unreliable pipe: HMAC, nonces, and a byte-exact contract

A per-request nonce and a per-content hash look like the same idea and are not. One says this request arrived twice, the other says this message arrived twice, and a payment pipeline needs both. The signing design behind a production SMS gateway.

Read
Frappe/ERPNext12 min read

Bolting a phone onto ERPNext: custom routes, guest endpoints and HMAC auth in Frappe

Frappe claims every /api/* path before website routing, so a fixed third-party path 404s. Here is the before_request rewrite that fixes it, including the cached property you also have to bust, and why allow_guest endpoints can still be strongly authenticated.

Read
AI Engineering6 min read

Shipping a business agent on WhatsApp: templates, webhooks and the 24-hour window

The in-app chat panel was good and nobody opened it. Putting the agent on WhatsApp means the Cloud API's template rules, idempotent webhooks, per-tenant scheduled jobs, alert hysteresis, and testing that Sheng routes to the right metric.

Read
AI Engineering6 min read

Hosted brain, dumb connector: splitting an AI agent so the data never leaves the client

Ship your agent to the client and you hand over your product. Pull their data to your platform and you become the custodian of their business records. The third option is a split: a hosted brain that decides what to fetch, and an on-prem connector with no intelligence in it at all.

Read
Payments & Fintech6 min read

M-Pesa Reconciliation That Scales: From Paybill Statement to Trial Balance

Stop reconciling in spreadsheets. A three-way match between the Safaricom statement, your callback events and a double-entry ledger, with named break categories and a daily close job in Python and SQL.

Read
Payments & Fintech7 min read

M-Pesa "Invalid BusinessShortCode": The Python requests Bug Behind It

Daraja error 400.002.02 blames your shortcode, but the real cause is usually data=payload instead of json=payload in Python requests. Here is how to prove it.

Read
Databases8 min read

MySQL server has gone away: four unrelated causes, one message

Errors 2006 and 2013 are a shrug, not a diagnosis. Idle timeouts, packet size, read timeouts and a crashed server all produce them, and each needs a completely different fix.

Read
Databases8 min read

FATAL: sorry, too many clients already - and why raising max_connections is wrong

Every Postgres connection is a separate OS process, so raising max_connections trades a clear error for an OOM. Here is the connection maths and the PgBouncer fix.

Read
Python & FastAPI - Guides, Sub-topics & Fixes · Code With Karani