Member-only story

Pydantic in Python — An Introduction

Aaweg I
6 min readApr 1, 2024

--

One of the biggest issues with Python as a programming language is the lack of static typing. Python uses dynamic typing, which means that when you create a variable, you don’t have to declare its type.

Compare this to something like Java or C where you actually have to declare the type upfront. Once a Python variable is created, you can also override it with a different type than what you created it with.

This does make it easier to get started with Python, but it can cause a lot of problems later on. For example, as your app gets bigger, it becomes harder and harder to keep track of all your variables and what type they should be.

It’s also difficult when you have to work with functions where the argument types aren’t obvious.

But the biggest downside of using dynamic types by far is that it allows you to accidentally create an invalid object. By that, I mean an object with values that it shouldn’t be allowed to have.

This can be really hard to debug because the failure could occur at any time in your program. And it could be hard to associate that failure with the actual cause.

--

--

No responses yet