<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python Engineering on Chen Kai Blog</title><link>https://www.chenk.top/en/categories/python-engineering/</link><description>Recent content in Python Engineering on Chen Kai Blog</description><generator>Hugo</generator><language>en</language><lastBuildDate>Wed, 27 Apr 2022 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/en/categories/python-engineering/index.xml" rel="self" type="application/rss+xml"/><item><title>Python Engineering (8): Performance — Profiling, Caching, and Knowing When to Stop</title><link>https://www.chenk.top/en/python-engineering/08-performance-and-profiling/</link><pubDate>Wed, 27 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/08-performance-and-profiling/</guid><description>&lt;p>Donald Knuth&amp;rsquo;s famous quote is often half-remembered. The full version is: &amp;ldquo;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.&amp;rdquo; The second sentence is the key. Performance work isn&amp;rsquo;t about making everything fast; it&amp;rsquo;s about finding the 3% that matters and making that fast.&lt;/p>
&lt;p>This article is about finding that 3%. You&amp;rsquo;ll learn to profile first, optimize second, and measure the impact of each change.&lt;/p></description></item><item><title>Python Engineering (7): Packaging — From pip install to PyPI</title><link>https://www.chenk.top/en/python-engineering/07-packaging-and-distribution/</link><pubDate>Sun, 24 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/07-packaging-and-distribution/</guid><description>&lt;p>You wrote a useful utility. A colleague asks you to share it. You zip the folder and email it. They unzip it, run &lt;code>python main.py&lt;/code>, and get &lt;code>ModuleNotFoundError&lt;/code> because they do not have the dependencies. Then they install the dependencies, but the wrong versions. Then they have Python 3.8 and your f-string walrus operators do not parse.&lt;/p>
&lt;p>Proper packaging eliminates all of this. With &lt;code>pip install your-tool&lt;/code>, everything just works: correct dependencies, correct versions, and a clean CLI command.&lt;/p></description></item><item><title>Python Engineering (6): Concurrency — Threads, Processes, and asyncio</title><link>https://www.chenk.top/en/python-engineering/06-concurrency/</link><pubDate>Thu, 21 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/06-concurrency/</guid><description>&lt;p>Your script downloads 100 files one at a time. Each download takes 2 seconds, mostly waiting for the server to respond. Total time: 200 seconds. Your CPU is idle for 99% of that time, wasting compute and money on network latency. Concurrency can fix this.&lt;/p>
&lt;p>Python has three concurrency models, each designed for different problems. Choosing the wrong one can make your code slow or full of race conditions. This article explains when to use each.&lt;/p></description></item><item><title>Python Engineering (5): I/O, Serialization, and Data Formats</title><link>https://www.chenk.top/en/python-engineering/05-io-and-serialization/</link><pubDate>Tue, 19 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/05-io-and-serialization/</guid><description>&lt;p>Most programs are just plumbing between data formats. Read a CSV, transform it, write JSON. Load a config file, validate it, pass settings to the application. Every Python developer writes this code, and most of them get encoding, path handling, or serialization subtleties wrong at least once.&lt;/p>
&lt;p>This article covers every common I/O pattern in Python, from basic file reading to columnar data formats, with a focus on the pitfalls that waste your time.&lt;/p></description></item><item><title>Python Engineering (4): Type Hints, Linting, and Code Quality</title><link>https://www.chenk.top/en/python-engineering/04-type-hints-and-linting/</link><pubDate>Sun, 17 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/04-type-hints-and-linting/</guid><description>&lt;p>Code reviews should be about logic and design, not about whether someone used single quotes or double quotes. Formatting debates are a waste of engineering time. The solution is to let machines handle style and let humans focus on correctness.&lt;/p>
&lt;p>This article covers three layers of automated code quality: type hints catch logical errors before runtime, linters catch style violations and common bugs, and pre-commit hooks enforce everything automatically on every commit.&lt;/p></description></item><item><title>Python Engineering (3): Testing — pytest, Fixtures, and the Confidence Loop</title><link>https://www.chenk.top/en/python-engineering/03-testing-and-debugging/</link><pubDate>Thu, 14 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/03-testing-and-debugging/</guid><description>&lt;p>You change one line and three unrelated features break. You refactor a function and spend two hours manually clicking through the app to check if everything still works. You deploy on Friday and get paged at midnight. All of these are symptoms of the same disease: no tests.&lt;/p>
&lt;p>Tests are not bureaucracy. They are the fastest way to know that your code does what you think it does. A good test suite runs in seconds and catches the bugs that would take hours to find manually.&lt;/p></description></item><item><title>Python Engineering (2): Project Structure — From Script to Package</title><link>https://www.chenk.top/en/python-engineering/02-project-structure/</link><pubDate>Tue, 12 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/02-project-structure/</guid><description>&lt;p>Every project starts as a single file. You write &lt;code>main.py&lt;/code>, it works, you add features, and one day you realize you have 1,500 lines in one file with functions that call other functions that depend on globals defined 800 lines above. The code works, but nobody (including future you) can understand it.&lt;/p>
&lt;p>The jump from script to package is the first real engineering decision in a Python project. Get it right early, and testing, packaging, and deployment become easier. Get it wrong, and you&amp;rsquo;ll spend weeks untangling circular imports.&lt;/p></description></item><item><title>Python Engineering (1): Environment Setup — pyenv, venv, and Dependency Hell</title><link>https://www.chenk.top/en/python-engineering/01-environment-and-toolchain/</link><pubDate>Sun, 10 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/python-engineering/01-environment-and-toolchain/</guid><description>&lt;p>Every Python developer has lived through this moment: you run a script on your colleague&amp;rsquo;s machine and it crashes because they have Python 3.8 while you wrote it on 3.11. Or worse, you &lt;code>pip install&lt;/code> something globally and break a completely unrelated project. Python&amp;rsquo;s environment story is powerful once you understand it, but the default experience is a minefield.&lt;/p>
&lt;p>This article walks through the entire toolchain from scratch. By the end, you&amp;rsquo;ll have a reproducible, isolated, and version-pinned setup that works the same way on every machine.&lt;/p></description></item></channel></rss>