
What happened
A writer ran a chat_stream.py script against Ollama 0.40.4 on Windows 11 and Python 3.11, using only urllib and json to call /api/chat with stream: true and print each NDJSON line as it arrived.
Why it matters
Developers who cannot or will not add the official ollama library now have a working reference for streaming output with zero extra dependencies, though they must handle model load times and history themselves.
Summaries like this, every morning.
The post is aimed at a common friction point: Ollama ships an official Python library, but some scripts are better off without it. By importing only urllib and json, the author avoids pip entirely, which suits single-file tools or machines where adding packages is a hassle. The script targets the local endpoint at http://127.0.0.1:11434/api/chat with a small qwen2.5:0.5b model, so the whole loop stays visible in about 20 lines.
The mechanism rests on NDJSON: with stream set to true, each line is a self-contained JSON object holding a piece of message.content and a done flag. Iterating over the response and printing each piece with flush is what produces the typewriter effect in a terminal, though redirecting to a pipe collapses it into one block. The author notes that json.loads accepts the raw bytes directly, since Python 3.6 and later detect UTF-8 automatically, sidestepping decoding pitfalls.
The caveats are practical rather than conceptual. The first request waits on model loading, measured at roughly 30 seconds for the 0.5B model, which matters if you set your own timeout. And once streaming works, conversation history and token-stat formatting become your own responsibility, so the author suggests the official library when that overhead grows; the point here is running with zero dependencies.
Pick your industry and the AI tools you use, and get news related to your work every day.
Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →
Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.
Google DeepMind's Maxence Faldor, Satinder Singh and Roberta Raileanu reported in an October 15 preprint that…

Anthropic published srt (sandbox-runtime) on npm under Apache-2.0, wrapping native OS primitives: sandbox-exec…

AI Nexus CEO Nishito published Structured Data Editor, a free VS Code extension that opens Markdown, CSV/TSV a…

A free 4-week curriculum has been published for engineers with no C# experience to build a minimal WinForms ap…

At Anthropic's "Machines of Loving Grace" exhibition and DevelopersIO 2026 TOKYO, Claude and Claude Code power…

A FitLog developer replaced repeated prompt warnings with a harness — a 48-line CLAUDE.md "map" linking six do…
