Posts

Showing posts with the label Python

Ollama Tutorial: Run Your First Local LLM in Python

Image
Quick answer Ollama is a free program that runs open language models on your own computer, no API key or cloud account needed. You install it, download a model with one command, and talk to it from a terminal or your own code through a local HTTP API on port 11434. This post installs Ollama on Linux, pulls a small 352 MB model, and sorts four real support tickets from Python. Picture a small software company's support inbox on a Monday morning. Four tickets waited overnight: a plan that never activated after payment, an app crashing on the settings page, a misspelled name on an invoice, and a whole team locked out since breakfast. Sorting them by hand takes a morning; a cloud AI means uploading customer data to someone else's server and paying per message. A model on your own machine changes that trade: it sorts the tickets and sends nothing outside your computer. This post shows that setup working, with real timings. What I would check before using it My first check is whe...

RabbitMQ Tutorial: An Order Queue That Never Loses Work

Image
Quick answer RabbitMQ is a message broker: one program puts a message into a queue, and another takes it out later, so slow work does not block the user. This post publishes three shop orders to a real queue with Python and pika, acknowledges the two good ones, and rejects the broken one into a dead-letter queue. It fits work that must survive a crash, and is overkill for a simple in-process job. Picture a small online shop. A customer clicks buy, and the checkout code charges the card and updates stock, all inside one web request. Then the payment gateway stalls, the request times out, the customer clicks buy again, and the card is charged twice. A queue breaks the chain. The web request only has to record the order and hand it to RabbitMQ, and a separate worker takes orders one at a time and confirms each one only when the work is done. If the worker crashes halfway, the order is still in the queue, waiting for the next worker. What I would check before using it My first check: ...

Sentry Error Tracking: Catch Bugs Before Your Users Do

Image
Quick answer Sentry error tracking collects the exceptions your Python app raises in production and groups them into issues you can triage, with the stack trace and how many users were hit. Install sentry-sdk, call sentry_sdk.init() with your project DSN as early as possible, and every unhandled exception is reported automatically. It is worth it once real users can hit errors you never see in development. Your checkout worked on your laptop. It passed review, the tests were green, and the deploy went out on a Friday afternoon. Then a customer writes on Monday that their order failed, and you have nothing to go on. No log line, no stack trace, just a screenshot and a vague description. You open the logs and find a wall of lines, most harmless, while the one line that matters sits buried in the middle. That gap, between an error happening and your team knowing about it, is the whole problem. Sentry closes it by catching the exception the moment it happens and sending you the details. ...

OpenTelemetry Python: Trace a Checkout Flow End to End

Image
Quick answer Yes. OpenTelemetry Python adds distributed tracing to a Python service with a few lines of setup: create a tracer provider, attach an exporter, and wrap each step of a request in a span. Each span records a name, timing, and attributes, and spans from one request share a trace id. Start with the console exporter, then switch to a real backend when the traces look right. A customer writes in: checkout took thirty seconds, then failed, and nobody can say where the time went. The order service says the payment call was slow. The payment service says it never saw the request. The logs from both sides exist, but they disagree about what happened first. That is the gap tracing fills. A trace follows one request across every service it touches, giving you one timeline with a name, a duration, and a few facts per step. OpenTelemetry is the shared vocabulary for that timeline, and the Python SDK is the part you wire into your own code. What I would check before using it My firs...

LangChain Tutorial: Build Your First LLM App in Python

Image
Quick answer LangChain is a Python framework for building applications powered by large language models, and in current LangChain 1.x you compose those applications with LCEL, the LangChain Expression Language, written as prompt | model | parser. This post builds a working support-ticket triage chain with that pattern, running offline with a stand-in model so you can learn the shape before spending anything on API calls. Picture a support inbox on a Monday morning. Two hundred messages arrived over the weekend: billing questions, outage reports, one customer who cannot check out. Reading each one by hand takes hours, and the urgent ones hide among the routine ones. A language model can read and sort them in seconds, but wiring that into real code means formatting prompts, calling the API, parsing replies, and handling failures. That wiring is the job LangChain is built for, and this post shows it on a small, honest example. What I would check before using it My first check is wheth...

DuckDB: Analytics Queries on a File, Without a Server

Image
A small shop owner exports twelve orders to a CSV file and wants one answer: which city brought in the most money this week? The file sits on a laptop, the data fits in a spreadsheet, and yet getting the answer takes longer than it should. A spreadsheet means wrestling with filters and formulas, and the totals shift every time a row is added. A database server for a file this small is worse: installing, configuring, creating users, all for twelve rows. DuckDB sits in the middle. It is a small analytical database that runs inside your own program, reads the CSV directly, and answers with plain SQL. No server, no setup, no separate process to keep alive. Quick answer Yes, DuckDB can answer analytics questions straight from a CSV file, with no database server to install or run. It reads the file with SQL, so totals, rankings, and revenue per city come from a few queries in a short Python script. The catch is messy data: prices stored as text with a thousands comma, and blank values, nee...

SQLAlchemy: Turn Your Python Classes Into Database Tables

Image
Picture a bike repair shop. The owner keeps one notebook for customers, another for bikes, and a third for repair jobs. Each week she works out who owes what, matching names across three notebooks. A spreadsheet helps at first, until the same customer appears under two spellings and a paid job gets counted twice. For tables in Python without a spreadsheet, see Pandas Explained: Tables in Python, Without the Spreadsheet . It is all there, but the links between the pieces live only in her head. That is the point where a Python developer reaches for SQLAlchemy. It turns customers, bikes, and jobs into Python classes backed by tables, with the relationships written down in code instead of remembered. The question is whether it is the right weight for the job in front of you. Quick answer Yes, SQLAlchemy is worth it when a Python app has several related tables and the code will keep growing with them. It maps each table to a Python class, so customers, bikes, and jobs become objects with ...

Python asyncio: Run Jobs at the Same Time Without Threads

Picture a small shop dashboard on a Monday morning. Before the first order ships, someone has to check stock with four suppliers, one for tote bags, one for mugs, one for notebooks, one for lamps. Each check takes a couple of seconds while the supplier's system answers. Done one after another, that is eight seconds of staring at a spinner, and the computer spends almost all of it doing nothing, just waiting for a reply. The work is not hard, it is slow, and the slowness comes from waiting, not from thinking. That is the exact gap asyncio is built for: one program that starts several waits at once and picks each one up when its answer arrives. Quick answer Yes, asyncio is worth using when a program makes several independent waits, because it starts them all at once and the total time is the longest single wait, not the sum: four stock checks took 2.50 seconds together instead of 7.01 one by one. It needs libraries written for it, like aiohttp or asyncpg, and it does nothing for wo...

Matplotlib: Charts in Python Without Opening a Spreadsheet

Image
The numbers are there, but the pattern is not You have last week's sales in a CSV file: notebooks 42, pens 87, backpacks 23, mugs 61, desk lamps 35. You can read every number and still not answer the question your manager asked: which category is carrying the week? Rows of numbers hide shape. A bar chart shows it in one glance, pens towering over everything, backpacks barely registering. That gap is the whole reason to plot from inside Python. If your numbers already live in a script or a CSV you load with Python, opening a spreadsheet just to draw a chart is an extra round trip, and every round trip is a chance to paste the wrong column. For tables in Python, see Pandas Explained: Tables in Python, Without the Spreadsheet . Quick answer Yes, Matplotlib is the right default when your data is already in Python and the chart ends up in a report, a slide deck, or a document, because a bar chart is a handful of lines and it saves to PNG, PDF, and SVG. Use the figure-and-axes style f...