Sabitlenmiş Tweet
Nuno Bispo (aka Developer Service)
5.8K posts

Nuno Bispo (aka Developer Service)
@DevAsService
Building better devs, one post at a time. 💻 Practical tips, pro insights, and tools that actually work. Read the blog today.
Netherlands Katılım Temmuz 2021
632 Takip Edilen473 Takipçiler

Python has a dirty secret.
It will let you write broken code that runs perfectly fine.
No errors. No warnings. No stack traces.
Just wrong answers, silently, confidently wrong.
Scope bugs are the #1 reason this happens.
You think you're reading a local variable. Python is reading a global one.
Your function returns a result. The result is garbage. And the interpreter couldn't care less.
I've seen this trip up beginners on day 3.
I've seen it trip up senior engineers on year 5.
The fix isn't talent. It's knowing the rules Python plays by.
So I wrote them down. All of them. In plain English.
Get the free Python Scope Guide: …variable-scope.developer-service.blog
Save it. Share it. Send it to that colleague who keeps asking why their variable "has the wrong value".
#Python #Programming #SoftwareEngineering #PythonTips
English

Don't flatten what naturally has structure.
It's tempting to model everything in a single class. Easy to write, easy to read, at least until your data grows.
This is where most codebases start, with just one model.
But with model composition, each model has a single responsibility. And Pydantic handles nested validation automatically.
Structure your models the way your domain is actually structured. The code gets cleaner, the errors get clearer, and reuse becomes obvious.
This and other real-world modelling patterns are covered in Practical Pydantic:
👉 leanpub.com/practical-pyda…
Model your domain. Not just your data.
#Python #Pydantic #Data #Models #Patterns

English

Your Python data is unreadable.
Stop printing raw lists.
tabulate turns mess tables into a clean, structured table,with one function call.
No frameworks. Just Python. 🐍
youtube.com/shorts/Ru-HhuC…
#Python #PythonTips #PythonDeveloper #LearnPython #programming

YouTube
English

You push your code. Your teammate pulls it. Nothing works.
The "works on my machine" problem is one of the oldest frustrations in software development - and the fix is simpler than you think.
I just published a beginner-friendly guide to GitHub Actions for Python projects. One YAML file is all it takes to run your tests, linting, and type checks automatically on every push.
In the article:
→ Key concepts explained simply (workflow, job, step, runner)
→ A working CI pipeline from scratch with pytest
→ How to add ruff, mypy, and pip caching
→ Testing across multiple Python versions with matrix
→ Common pitfalls and how to avoid them
No prior CI/CD experience needed.
🔗 developer-service.blog/github-actions…
#Python #GitHub #CI #DevOps #SoftwareDevelopment
English

Nobody teaches you this in Python tutorials.
You learn variables. You learn functions. You learn classes.
But scope? You learn scope the hard way.
At 2am. With a bug you can't explain. Staring at code that looks perfectly fine.
Here's what's actually happening:
Python doesn't look for variables the way you think it does.
It follows a very specific lookup order - Local → Enclosing → Global → Built-in - and if you don't know the rules, it will surprise you in the worst moments.
I wrote a free guide to fix that gap:
✔ How Python actually resolves variable names
✔ Why closures behave the way they do
✔ The global and nonlocal keywords demystified
✔ Real examples of scope bugs - and how to squash them
No fluff. No theory for the sake of theory. Just the stuff that makes you a sharper Python dev.
🎁 Free download: …variable-scope.developer-service.blog
Drop a 🐍 in the comments if scope has burned you before.
#Python #PythonDeveloper #LearnPython #Debugging #Scope #Variable
English

Your model shouldn't just store data. It should understand it.
Most developers use Pydantic for validation. Fewer use it to derive meaning from data.
Here's a pattern worth adding to your toolkit, computed fields.
No manual calculation. No risk of forgetting to update a field. No inconsistent state.
order.total is always correct, because it can't be anything else.
This matters more than it looks. Every time you store a derived value separately, you create a sync problem.
What happens when quantity changes but total doesn't? Bugs that are challenging to trace and easy to introduce.
Computed fields eliminate that class of problem entirely. The model owns the logic. Callers just consume the result.
That's what Practical Pydantic is about, designing models that carry business logic, not just data shapes.
👉 leanpub.com/practical-pyda…
Stop storing what you can compute.
#Python #Pydantic #Data #Computed

English

Full article covers:
→ Reconstructing race state from raw OpenF1 streams
→ MicroPython display code for the CYD
→ gc.collect() discipline for a 2hr race session
→ What OpenF1 doesn't give you (total laps — yes, really)
developer-service.blog/build-an-f1-pi…
English

I once spent 3 hours debugging a Python script.
The logic was right. The data was right. The tests were passing.
But the output was wrong. Every. Single. Time.
Turns out? A variable I thought was local was leaking from an outer scope.
One line. Three hours. A lesson I never forgot.
Scope bugs are brutal because Python doesn't yell at you, it just silently uses the wrong value.
So I put together a free guide that breaks down exactly how Python scope works:
→ The LEGB rule, explained simply
→ The most common scope bugs (and why they're so sneaky)
→ How to read your own code the way Python reads it
→ global and nonlocal, when to use them, when to avoid them
If you've ever been confused by a variable that "shouldn't" have that value... this guide is for you.
Get it free here: …variable-scope.developer-service.blog
Save this post. Your future self will thank you.
#Python #SoftwareDevelopment #Programming #PythonTips #ChiefOfCode
English

Real-world data is messy. Your models shouldn't be.
CSV files, external APIs, user input - they all deliver junk like "N/A", "unknown", or empty strings. Technically valid. Logically useless.
Instead of scattering cleanup logic across your codebase, normalize once - at the model level.
Downstream code stops worrying about edge cases. Business logic gets simpler.
That's the real value of structured models: a hard boundary between messy input and reliable internal state.
This pattern - and dozens like it - are covered in Practical Pydantic.
leanpub.com/practical-pyda…
Clean code starts with clean data.
#Python #Pydantic #CleanData

English

I just published an article on how to build and publish a Python package to PyPI — and I used a real project to show it.
The example is tinyfiledb: a lightweight file-based database that stores records in a local JSON file. Small enough to understand in one sitting, realistic enough to actually use.
The article covers the full workflow:
→ Structuring your package (flat layout vs src/)
→ Writing pyproject.toml from scratch
→ Building .whl and .tar.gz distributions with python -m build
→ Testing on TestPyPI before it counts
→ Publishing to PyPI with twine
→ Verifying the install end-to-end in a clean environment
The best first package is usually something you've already written — a module you keep copying between projects or a script you've sent to a colleague over Slack.
Add a pyproject.toml, a README, and a few minutes of setup. That's all it takes.
👇 Full article at the link in the comments.
#Python #OpenSource #PyPI #SoftwareDevelopment #PythonPackaging
English

The AI ecosystem is fragmented — every provider has its own API, auth, and rate limits.
OpenRouter fixes that with a single unified API.
@realpython just published my guide on showing how to:
✅ Connect to OpenRouter with plain requests
✅ Route to specific providers (by cost, speed, or throughput)
✅ Add model fallbacks for production reliability
No SDK required. Just Python 🐍
👉 realpython.com/openrouter-api/
#Python #AI #APIdev
English

Quick Python question:
Why does this happen? A variable works perfectly inside a function… but suddenly behaves differently outside of it.
For many developers, this is where Python variable scope becomes confusing.
Understanding how Python handles local, global, and nonlocal variables can eliminate a surprising number of bugs and make your code much easier to reason about.
I wrote a short guide that explains the concept clearly with practical examples.
👉 …variable-scope.developer-service.blog
If you're working with Python and want to strengthen your fundamentals, this is a concept worth mastering.
#Python #Programming #SoftwareDevelopment #LearnPython #CodingTips
English

Your Python terminal is embarrassing you.
Stop using plain print() statements.
The Rich library turns boring output into colors, tables, and progress bars.
youtube.com/shorts/z5bCJou…
#Python #RichLibrary #PythonTips #LearnPython

YouTube
English

If your validation lives outside your models, it will eventually drift.
This is one of the most common design issues I see in Python codebases.
Validation starts in the API layer.
Then some logic gets added in a service.
Then a background worker bypasses it.
Now you have three different interpretations of what “valid data” means.
A cleaner approach is to encode rules directly into your data models.
For example, using strict types in Pydantic when correctness matters.
Why this matters:
- "1" will not silently become 1
- "true" will not quietly convert to True
Incorrect data fails immediately.
In many systems, silent coercion is more dangerous than a loud failure.
Strict validation forces data producers to behave correctly, instead of letting your system “guess” what they meant.
More practical examples at: leanpub.com/practical-pyda…
Reliable systems are rarely accidental. They’re designed that way.
#Python #Pydantic #ValidData #Data #Validations

English