Building APIs for NLP models using FastAPI
FastAPI is a Python web framework for building APIs. It’s built on top of another two Python libraries, Starlette and Pydantic, making it one of the fastest Python frameworks available. FastAPI is based on standard Python type hints. With type hinting, we can specify the expected type of a variable, function parameter, or return value. This feature helps us catch bugs earlier in the development process, so let’s learn how to use type hints before heading to FastAPI usage.
Python type hinting 101
Python is a dynamically typed language, meaning it performs the type checks of the variables at runtime. For example, if we run this code, it does not throw any errors:
string_or_int = "Hi friends" string_or_int = 10
This runs smoothly because the Python interpreter handles the transition of string_or_int from String to int. This can lead to bugs because of silent errors. Type hinting provides a way to specify the...