Green Files

What is the difference between API, library and framework?

Day: 05/31/2022 - Time: 08:35:45

To complement, help or confuse a little more :) and be slightly dissonant. Terms can be defined differently depending on the context. I went to look at the definition found on Wikipedia in English for the terms API, Library and Framework. "Just for a change" in English is a better definition.


There it becomes clear that an API is a more abstract concept that defines ways to perform a specific task. It's the way your code relates to a library. Some answers give the impression (not necessarily claim) that the API is for accessing services external to the application, and often this is true. If it were always true, "how to handle a string" wouldn't be an API, which it is. A lot of people use the term API for something else related which is webservices or something similar, where obviously there is an API, but the provision of services is not the API itself.

In a way we can say that the API is the documentation that determines how a programmer can perform a task through a library. Of course, there is no mandatory relationship with the documentation. It is possible to have an API (nut) without documentation. And the actual documentation of a library will be close to but not necessarily the same as the API. The API is a set of rules for performing a task. It deals with possible behaviors. She is the contract.

An API is often stable, especially when it is freely publicly available. Although uncommon, it may have parts that are documented as unstable (mutable), which requires great care in its use.

In some cases an API may document some details of what the implementation should look like to ensure that some goals are achieved.

The API is more of a specification and not an implementation.


The library is usually an actual implementation of an API's rules. So it's more concrete. Just like the API, you don't need to know the implementation details to use it. The library needs to respect the API rules at all times, but it doesn't need to have a stable implementation. The library is usually self-sufficient.

A library can contain public implementations that are not part of the API. Using them can be risky.

You call a library. It's a tool. You use what you need.

So far, no answer has addressed the term library as a way of organizing binary codes for use with applications. A library is also an executable file containing a set of functions to perform various tasks. .dll or .so are library files for dynamic linking in the application. .lib or .a are library files for static linking in the application.

You can have a library of string manipulation, regular expression, data collection, file manipulation, database access, image manipulation, etc.

Libraries can be external, which is the case for web services. This is a common way these days to prevent piracy, as many applications are web based. It may have some advantages, but it also has many disadvantages.


A framework is usually a set of libraries to be able to perform a larger operation. It is common for a framework to encapsulate API behaviors in more complex implementations, allowing its use more flexibly, often through extensions, configurations, and inversions of control. As it can be considered a layer on top of the API it can eventually simplify it in a certain sense. It usually gives consistency to a set of libraries (too bad the opposite happens in some cases).

The framework usually "takes care" of your application leaving "doors" for you to access, which is important for your purpose. It is common to have a great interdependence between its components. For these two reasons, the framework can become a burden when it isn't made well, or isn't suited to what the programmer needs, or when the programmer doesn't quite know how to use it. It is very common for one or more of these situations to happen.

A framework calls you. It's a lifestyle. Your project commits to it.

Frameworks can be understood as development platforms. They have gaps that must be filled by the programmer to work as needed. It can be seen as a skeleton of an application. They are often mistaken, rightly or wrongly, as a set of classes.

Sometimes the term is used to denote a set of binary code library files, or fonts, or even other related resources for the application.

Examples are GUI systems, web operations systems, some ORMs, a set of standard libraries of a programming language, implementation of an MVC standard, etc.

Sometimes a library is or becomes so complex that it becomes a framework. Whether this is good or bad I leave it to you to decide.

Toolkits and SDKs

You didn't ask but there are still toolkits that can be confused with frameworks but work more freely, they are more like libraries working together, but in a traditional way where you call what you need.

There are also SDKs. Software Development Kits can take the form of toolkits or frameworks and provide everything you need to program on top of a platform (operating system, database, application, etc.). These kits often include additional tools in addition to the libraries as well as documentation and code examples that help to use the library properly.


Most of the time the terms can be interchanged without causing too much trouble. Everyone understands these three things as a set of codes ready to achieve some goal (even if it's not exactly that in all three cases).

But when you're defining something more formal, when you're explaining the details of a project to someone, it's best to use the correct terms to give a better understanding. Of course, if the interlocutor doesn't know the correct terms, the conversation is truncated anyway.