Annoyed writing multiple import statements? Let PyForest do the work for you

Photo by hamza tighza on Unsplash

Python is a primary language used by data scientists for data science projects, because of the presence of thousands of open-source libraries that can ease and perform a data scientist task. Over 235,000 Python packages can be imported through PyPl.

Multiple libraries and frameworks need to be imported to perform tasks in a data science case study. Every time a data scientist or analyst starts a new jupyter notebook or any other IDE, they need to import all the libraries as per their requirements. Sometimes writing multiple lines of the same import statement over and over again can be frustrating. Here pyforest libraries come into the rescue, and it does the work for you.

Pyforest Library:

Image by StockSnap from Pixabay

Pyforest is an open-sourced Python library that enables data scientists to feel the bliss of automated imports. While working on a data science case study one needs to import multiple packages or libraries like pandas, matplotlib, seaborn, NumPy, SkLearn, etc. Importing all these libraries every time can be boring and disrupt the natural flow of your work. Also, you are free from searching for the exact import statement, like from sklearn.ensemble import RandomForestClassifier .

Using pyforest one can overcome these problems. Pyforest enables you to use all your favorite libraries without importing them. Pyforest does the work for you by automatically importing the libraries you want to use for your case study.

Once you import the pyforest library in one line, now you can use all the python libraries like one usually does. Any of the libraries that you use is not imported, Pyforest imports it for you automatically. The libraries are only imported once you call them or create an object of it. If a library is not used or called, it won’t be imported by pyforest.


Pyforest can be installed from Pypl using the following command:

pip install pyforest

After installing the library, you need to just import it in one line of code. Now you can use your favorite library like you usually do, without writing imports. In the below sample jupyter notebook, we have not imported pandas, seaborn and matplotlib library, still, we can use them by just importing the pyforest library.

Can pyforest import all libraries?

This package aims to add all the libraries that account for more than 99% of the imports, including popular libraries such as pandas as pd, NumPy as np, matplotlob.pyplot as plt, seaborn as sns, and many more. In addition to these libraries, it also some helper modules such as os, tqdm, re, and many more.

If you want to see the list of libraries, use dir(pyforest).

To add your own import statements to the pyforest libraries list, type in your explicit import statement to a file present in your home directory ~/.pyforest/ .

Functions of pyforest:

Pyforest automatically the python libraries as and when required. Pyforest comes up with some function to know the status of libraries:

  • active_imports(): Returns the list of libraries that have been imported and in use.
  • lazy_imports(): Return with the list of all libraries to import in the pyforest library.


In this article, we have discussed the pyforest library, an automated importing library. Using this library can reduce the stress to import tons of necessary libraries, instead, it does automatically imports the requirements. This library can be helpful for a data scientist who constantly works with new jupyter notebooks to explore their data science case study, now they can be free from importing the libraries, hence accelerating their workflow.


[1] Pyforest documentation (Apr 17, 2020):

Thank You for Reading

Import all Python libraries in one line of code was originally published in Towards Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.