
A valid, yet normal pattern of writing decision logic typically would default to if/else statements:
if company == "anthropic":
print("Model: Opus 5")
elif company == "openai":
print("Model: GPT-5.6 Sol")
elif company = "google":
print("Model: Gemini 3.5")
else:
print("Not a valid company")Inherently, there isn’t anything wrong with this: you’re looking to make a decision based upon some kind of criteria. This is a situation where you’d use a if/else statement!
However, when scaling to multiple conditions, this can become cumbersome and tough to maintain - what if we wanted to include models such as Qwen, DeepSeek, or models that are developed locally/in-house?
Sure, you could expand upon what you have, but this becomes a problem because of maintenance.
The Registry Pattern
This is where the registry pattern comes into play. You can think of a registry as a single "place” where you store all of your if/else conditions and outputs. This “place” is normally a dictionary within your code.
So, instead of maintaining a bunch of if/else statements, you’d maintain this dictionary instead:
registry = {
"anthropic" : "Opus 5",
"openai" : "GPT-5.6 Sol",
"google" : "Gemini 3.5",
# ... add other companies/models here
}
# sample variable
company = "anthropic"
model = company.get("registry")
if not model:
print(f"{company} not in the registry")
else:
print(f"Model: {model}")Notice that instead of a bunch of if/else statements we only have one? This is because we’re checking for the existence of a company in a dictionary instead of checking against a variable.
This pattern has a number of advantages, not only from a maintenance perspective, but also from a scalability perspective. For instance, if our dictionary grows too large, we can refactor this to a JSON file and read it in during run-time.
For those who are interested in time complexity, using a registry is linear (O(1)), as dictionary lookup, adding keys, and removing is linear. On the converse, using if/else statements is at best linear (O(1)), but average case is linear (O(n)).
Thus, as the number of companies grows when using the if/else statements, the slower the code becomes.
Happy coding!
📧 Join the Python Snacks Newsletter! 🐍
Want even more Python-related content that’s useful? Here’s 3 reasons why you should subscribe the Python Snacks newsletter:
Get Ahead in Python with bite-sized Python tips and tricks delivered straight to your inbox, like the one above.
Exclusive Subscriber Perks: Receive a curated selection of up to 6 high-impact Python resources, tips, and exclusive insights with each email.
Get Smarter with Python in under 5 minutes. Your next Python breakthrough could just an email away.
You can unsubscribe at any time.
Interested in starting a newsletter or a blog?
Do you have a wealth of knowledge and insights to share with the world? Starting your own newsletter or blog is an excellent way to establish yourself as an authority in your field, connect with a like-minded community, and open up new opportunities.
If TikTok, Twitter, Facebook, or other social media platforms were to get banned, you’d lose all your followers. This is why you should start a newsletter: you own your audience.
This article may contain affiliate links. Affiliate links come at no cost to you and support the costs of this blog. Should you purchase a product/service from an affiliate link, it will come at no additional cost to you.

