Wrapper libraries and idea of "built on top of"

  • Thread starter fog37
  • Start date
In summary, wrapper libraries are software components that provide a simplified interface to a more complex underlying system or library, allowing developers to interact with it more easily. The concept of "built on top of" refers to how these wrapper libraries build upon the functionality of existing libraries or frameworks, enhancing usability, abstraction, and often adding additional features without altering the core functionality of the original system. This approach facilitates development by reducing the complexity developers face while leveraging the capabilities of the underlying technologies.
  • #1
fog37
1,569
108
TL;DR Summary
Wrapper libraries and the backend software they support
Hello,
I understand that a software library is called "wrapper library" if it provides a level of abstraction to another library: we can use the wrapper library instead of using the backend library directly to have an easier and more convenient access to the backend library functionalities.
One example from the Python world is the pair of viz libraries Matplotlib and Seaborn. It is standard to always imported both two libraries together but we could import only one of them and use it alone.

Seaborn is built on top of matplotlib and is said to be a wrapper library for matplotlib. That means that seaborn can do everything that matplotlib does. Seaborn is just an easier to use interface (API) to use all the functionalities of matplotlib under the hood.
  • That said, why do we need to also import matplotlib if seaborn can do everything anyway? Is it simply because seaborn can only get so far and does not really access ALL the capabilities of the more sophisticated matplotlib? Matplotlib has a slightly harder syntax but we can tweak more with it. Is that correct?
  • Importing seaborn does not automatically import matplotlib. However, in the case of the Python libraries Keras and Tensorflow, Keras is the API and wrapper library for TF and Keras does not work without the Tensorflow engine. TF is always imported implicitly or explicitly and needs to be there...That is not the case for the pair matplotlib and seaborn...Why?
  • Do you have any other example of wrapper library in Python? Many libraries are built on top of other libraries. For example, pandas is built on top of numpy and matplotib. But "built on top" simply means that the these libraries started out from the skeleton of these other two libraries. It does not mean that pandas is a wrapper library for numpy or matplotlib...Correct?
Thank you!
 
Technology news on Phys.org
  • #2
It depends on the how they were designed and what things from the library are exposed to the enduser.

As an example, the lower level library may have defined some constants that are needed in the calls to the wrapper library so rather than redefining the constants, the designer felt it was better to require the import of the lower level library.

Wrapper libraries do not necessarily support all features of the lower level library, only those things that users are most interested in using and that support their usecases.

I have seen this used with the curses library where wrapper libraries provide character based gui widgets like checkboxes, selectable list objects... that curses doesn't provide. This saves the enduser from developing those widgets each time they are needed in their code.
 
  • #3
I have never used Seaborn, but here are my two cents after looking at the Seaborn documentation.
fog37 said:
TL;DR Summary: Wrapper libraries and the backend software they support

Hello,
I understand that a software library is called "wrapper library" if it provides a level of abstraction to another library: we can use the wrapper library instead of using the backend library directly to have an easier and more convenient access to the backend library functionalities.
One example from the Python world is the pair of viz libraries Matplotlib and Seaborn. It is standard to always imported both two libraries together but we could import only one of them and use it alone.
The Seaborn documentation says that it is based on Matplotlib and just provides an interface to it. So I believe that it will not work unless Matplotlib is installed.
fog37 said:
Seaborn is built on top of matplotlib and is said to be a wrapper library for matplotlib. That means that seaborn can do everything that matplotlib does.
No. Seaborn can only do the tasks that it has been designed to do. There is no reason to believe that it provides all the functionality or flexibility of Matplotlib.
fog37 said:
Seaborn is just an easier to use interface (API) to use all the functionalities of matplotlib under the hood.
"all the functionalities of Matplotlib"? What makes you think that it provides "all" of the functionalities?
fog37 said:
  • That said, why do we need to also import matplotlib if seaborn can do everything anyway?
Because Seaborn uses Matplotlib to do the work. It makes using some parts of Matplotlib easier. It almost certainly does not allow you to do everything that Matplotlib can do unless it also provides a direct pass-through of Matplotlib commands.
fog37 said:
  • Is it simply because seaborn can only get so far and does not really access ALL the capabilities of the more sophisticated matplotlib? Matplotlib has a slightly harder syntax but we can tweak more with it. Is that correct?
That would be my assumption.
fog37 said:
  • Importing seaborn does not automatically import matplotlib. However, in the case of the Python libraries Keras and Tensorflow, Keras is the API and wrapper library for TF and Keras does not work without the Tensorflow engine. TF is always imported implicitly or explicitly and needs to be there...That is not the case for the pair matplotlib and seaborn...Why?
Because different designers developed their programs differently. There is no law that it has to be done a certain way.
fog37 said:
  • Do you have any other example of wrapper library in Python? Many libraries are built on top of other libraries. For example, pandas is built on top of numpy and matplotib. But "built on top" simply means that the these libraries started out from the skeleton of these other two libraries.
I's not sure what you mean by "the skeleton of these other two libraries". Do you mean a subset?
fog37 said:
  • It does not mean that pandas is a wrapper library for numpy or matplotlib...Correct?
numpy is imported when pandas is used. I don't know if there is an official definition of "wrapper library".
 
  • #4
Seaborn doesn't have the full functionality of matplotlib; you have to call matplotlib functions directly in order to, for example, actually export a plot to an image file: see here.
 
  • Like
Likes FactChecker
  • #5
fog37 said:
It is standard to always imported both two libraries together but we could import only one of them and use it alone.
According to the documentation, Seaborn cannot be used without numpy, pandas, and mathplotlib:
https://seaborn.pydata.org/installing.html said:
The basic invocation of pip will install seaborn and, if necessary, its mandatory dependencies.

[...]

Mandatory dependencies​

 
  • Like
Likes FactChecker and fog37
  • #6
jack action said:
According to the documentation, Seaborn cannot be used without numpy, pandas, and mathplotlib:
I see. Thank you.

So numpy, pandas, matplotlib are required dependencies. Without them installed, seaborn does not work, i.e. it cannot be installed alone. However, it can be imported alone: in the code, I can simply type import seaborn as sns and everything works just fine. Under the hood, matplotlib and numpy do not get imported but do they still get "contacted" (bad term) by seaborn?
 
  • #7
fog37 said:
I see. Thank you.

So numpy, pandas, matplotlib are required dependencies. Without them installed, seaborn does not work, i.e. it cannot be installed alone. However, it can be imported alone: in the code, I can simply type import seaborn as sns and everything works just fine. Under the hood, matplotlib and numpy do not get imported but do they still get "contacted" (bad term) by seaborn?

Check the source code. seaborn.utils imports matplotlib, numpy and pandas:

Python:
"""Utility functions, mostly for internal use."""
import os
import re
import inspect
import warnings
import colorsys
from contextlib import contextmanager
from urllib.request import urlopen, urlretrieve

import numpy as np
import pandas as pd
import matplotlib as mpl
from matplotlib.colors import to_rgb
import matplotlib.pyplot as plt
from matplotlib.cbook import normalize_kwargs

from .external.version import Version
from .external.appdirs import user_cache_dir
 
  • Like
Likes DrClaude, FactChecker and fog37
  • #8
pasmith said:
Check the source code. seaborn.utils imports matplotlib, numpy and pandas:

Python:
"""Utility functions, mostly for internal use."""
import os
import re
import inspect
import warnings
import colorsys
from contextlib import contextmanager
from urllib.request import urlopen, urlretrieve

import numpy as np
import pandas as pd
import matplotlib as mpl
from matplotlib.colors import to_rgb
import matplotlib.pyplot as plt
from matplotlib.cbook import normalize_kwargs

from .external.version import Version
from .external.appdirs import user_cache_dir
Thank you! Looking into.

So the line import seaborn as sns does automatically import, under the cover, the libraries matplotlib, pandas, and numpy... but that does not mean we can use those other libraries and their methods without explicitly importing them as well...
 
  • Like
Likes jedishrfu
  • #9
fog37 said:
So the line import seaborn as sns does automatically import, under the cover, the libraries matplotlib, pandas, and numpy
Not really. The full description of how the import system works is here: https://docs.python.org/3/reference/import.html but in summary:

The import statement combines two operations; it searches for the named module, then it binds the results of that search to a name in the local scope.​

So when you do import seaborn as sns, what you are doing is binding the seaborn module to the name sns in your code's scope so that you can use its public methods.

Whether seaborn imports any other modules into its scope is completely irrelevant to you.
 
  • #10
fog37 said:
Thank you! Looking into.

So the line import seaborn as sns does automatically import, under the cover, the libraries matplotlib, pandas, and numpy... but that does not mean we can use those other libraries and their methods without explicitly importing them as well...
You should be able to use them if they are in the scope where you need them.
 

FAQ: Wrapper libraries and idea of "built on top of"

What is a wrapper library?

A wrapper library is a set of code that provides a simplified interface to a more complex set of code or functionality. It essentially "wraps" the original code in a more user-friendly way, making it easier to use and understand.

How does a wrapper library work?

A wrapper library works by providing a layer of abstraction between the user and the original code or functionality. Users interact with the wrapper library, which then translates their requests into the appropriate calls to the underlying code.

What are the benefits of using a wrapper library?

Using a wrapper library can make it easier and faster to implement complex functionality, as it provides a simpler interface for interacting with the underlying code. It can also help to standardize and streamline the way that code is used across different projects or teams.

Can a wrapper library be customized or extended?

Yes, wrapper libraries can often be customized or extended to meet specific needs or requirements. Users can add new functionality, modify existing functionality, or even create entirely new wrappers for different code bases.

How does the idea of "built on top of" relate to wrapper libraries?

The idea of "built on top of" refers to the concept of using a wrapper library to extend or enhance the functionality of existing code. By building on top of a wrapper library, developers can leverage its simplified interface to create new features or applications without having to directly interact with the underlying code.

Similar threads

Back
Top