#TechTalk #LibraryAPIs #PythonTutorial
Hey tech enthusiasts! Let’s dive into a fascinating topic today – why are libraries sometimes called “APIs”?
So, I recently stumbled upon the term “API” being used to refer to a Python library in my coding journey and it left me scratching my head. 🤔 Shouldn’t APIs be those tools that connect software applications and facilitate data exchange? But here we are, talking about PIL image manipulation library as an API!
Here’s a possible explanation for why libraries are sometimes called APIs in the tech world:
– Libraries contain pre-written functions and methods that developers can use to perform specific tasks in their code.
– APIs, on the other hand, are interfaces that allow different software programs to communicate with each other.
In the context of Python programming, libraries like PIL provide a set of functions that developers can call upon to manipulate images, acting as an interface between the developer and the code.
So, in a way, libraries can be seen as APIs that developers can leverage to achieve certain functionalities in their programs. Pretty neat, right? 🌟
What are your thoughts on this intriguing connection between libraries and APIs? Share your insights in the comments below! Let’s learn and grow together in the world of coding. 💻 #TechCommunity
API – means “a way for two running programs to talk to each other”.
When I write a program that allows such communication then I also write a publicly accessible library called API that other developers can use to interact with my program. For example: You can use OpenAI API library to easily get your program to talk to ChatGPT, that’s running on servers belonging to OpenAI.
But since PIL is not a library that’s like that I think your professor used a verbal simplification. Some people call all the public methods and functions inside any library an “API of that library”. Technically you use them to interact with the logic hidden inside the library. So technically it’s like an API, just there is no second program.
The API is the interface to whatever does the thing. In a car the api would be the steering wheel and the pedals and the library the whole car.
So to you as a programmer the API is the interresting thing, how you interact with the library.
APIs can be either. They are just interfaces into functionality of a application. I know nothing of the specific library your professor speaks of, but the library acts as an interface/api into some sort of functionality, just as some web service acts as an interface/api into some data retrieval functionality.
API is a generic term. Now, mind you, a [RESTful API](https://en.wikipedia.org/wiki/REST#Architectural_constraints) is the latter one you presented. A python library is NOT a restful API
API = Application Programming Interface
An interface is where 2 things meet. In this case the 2 things are your code, and the library’s code.
The API, in this case, is the documented way that your code can interact with the library – it’s the list of functions that the documentation for that library tells you about. The library may contain other functions that aren’t designed for you to call; if they’re not listed in the documentation then they’re not part of the API, but they’re still part of the library; they’re just internal “black box” stuff that you don’t need to worry about.
So a library isn’t an API, but it usually **has** an API.
Note also that other things can have an API too, such as a web API (a way to communicate with a service on the internet) or an operating system API (a way for your code to communicate with the operating system). API is a generic term for a documented way for 2 pieces of software to talk to each other.
The general definition of API – Application Programming Interface is the *public/user facing part* of a programming language, library, framework, etc.
Only lately, the term API has been reduced to web APIs.
E.g. Java has always called the user facing part of the language as API
This is an API for Java’s List interface.
https://docs.oracle.com/javase/8/docs/api/java/util/List.html
It tells you all the methods you can use with a List interface. Java has many such APIs.
It can be web APIs, which is a subset of all APIs.
I think this can be contrasted with a protocol, such as HTTP used to communicate with a web server. But, I’m not positive.
because that is what they are coded to be. application program interface. the library has the functions necessary to interface with the program.
An API is basically a piece of code or data that you insert into your code that allows you to add functionality into it
Remote/External APIs would be interfaces like REST API (JSON) data or packages installed via a package manager
Local APIs would be interfaces you can locally import – aka frameworks/packages containing libraries of functions, or a text file you open, read and insert into your program runtime buffers
The application programming interface existed before web apps were a thing.
Think of that as the public interface expected to be used by consumer of your library or service.
API documentation has been provided for DLLs, header files, and really any situation when you use someone else’s code.
So yes, these days “API” is often short for something like “web service API” but it has a broader meaning in history and is sometimes used as a synonym for library.
This won’t be the last time you hear it used this way.
There are already a lot of good answers in this thread but I just want to clarify some things with examples.
With code libraries, there will often be situations where two different libraries may have the same API. For example, Java code runs on the Java Virtual Machine (JVM). The way the Java code works is documented in a language specification, so anyone can create their own JVM. As long as it adheres to the specification then Java code will run on it. This is why we have different JVM options like the Oracle JVM or the one provided by OpenJDK.
In addition to the JVM specification, Java has an API for its standard library. Oracle and OpenJDK both provide their own implantation of these libraries that adhere to the API specification.
As a developer, you might not know or care which implementation of these libraries you are using or how it works, so you might simply say “I am using the Java ‘streams’ API” and not “I am using OpenJDK’s ‘streams’ library”. As long as the library being used properly adheres to the API then your code should work.
Python also has some situations where you might not be using the library you think you are. Python makes it really easy to use an underlying C library to perform some tasks. This is very common for things that have high performance requirements like math functions and network programming. Because C is compiled to machine code it is platform dependent. Python using C code running on Windows and Python using C code running on Linux will be using different C libraries. It might be the same library source code but compiler flags for different platforms will result in different compiled libraries.
The important thing to note here is that the Python code on both platforms will have the same API so the Python code will be platform independent as long as the C library is available on that platform. If you’ve ever tried installing some Python SQL libraries on a fresh Linux system you’ll probably get errors saying that the C libraries could not be found and that you need to download those first.
The important thing to take away is that different libraries may implement the same API in which case they should be interchangeable without changing any of the code that uses the library.
They are not.
PIL is a library as its name says, and it is not an API.
It has APIs as part of the library, it’s still not correct to say it is just an API