Why some Django classes and default apps are called API?

I have recently started using Django and came across a few instances where in documentation some of the default django classes are referred to as APIs.

One such instance is on this link where Model class is referred to as an API.

This somehow doesn't make much sense to me. I have tried searching this on web but no help there. Is the Model class not a class and an API, or can it be both? I haven't studied Django Rest Framework at all, will it make more sense then?


Solution 1:

API (Application Programming Interface) is a general term in programming and libraries, it's not a term that's specific to Django or even web frameworks. Generically, any programming interface which is intended to be used by someone else is an API. This could be a module, classes, etc. Usually, they follow some sort of design pattern or have some element of congruity.

This may be confusing if you are unfamiliar with the terminology because of the proximity to the web framework, which deals with REST/web APIs, which is probably the most common way the term API is used. In this instance of the documentation API does not mean web API.

The requests package has an API. The json module has an API. etc.

Is the Model class not a class and an API, or can it be both?

They're certainly not exclusive terms. django.db.Model is certainly a class and has an API. It's probably better said that the Model class has an API or that the model class is the implementation of the Model API.

The term API can sometimes be used in contrast with a User interface (UI). A REST interface is a programming interface (API), a website frontend is a user interface (UI).

Used in a sentence:

"I like the Model API because it is simple and clean and plays nice with the entire Django ecosystem"