![]() In many cases, "static" is used when saying Static Analysis, Static Checking, Static Type Checking, etc. It's treated just as a text file containing code. It just means that the code is not being executed. The counterpart of runtime would be static. And Pydantic and FastAPI take advantage of those features.Īnother term commonly used to refer to doing things at runtime is to do things dynamically. How can these tools do that? Python is so powerful that it has features to allow exactly that, to read type annotations at runtime from the same Python code. And if we send a JSON request with a price that is not a float, they will be able to validate the data for us.įastAPI and Pydantic are written in pure Python. So, for example, in the Item class above, we have:Īt runtime, Pydantic and FastAPI will see that name is a str and price is a float. The way that program works is that, at runtime (when our code is being executed), Pydantic and FastAPI read those type annotations (or type hints) to extract their data and do things with it. main.py, it is not running, so we are not at runtime. When our code is not being executed, for example, when we are editing the file. It's just the period of time when it is executing our code. Now, when that program python is executing our code written in the Python programming language, we call that "runtime". So, you could say that python (the program) can read Python (the programming language).
0 Comments
Leave a Reply. |