pyforest - lazy-import of all popular Python Data Science libraries. Stop writing the same imports over and over again.
pyforest lazy-imports all popular Python Data Science libraries so that they are always there when you need them. If you don't use a library, it won't be imported. When you are done with your script, you can export the Python code for the import statements.
- Demo in Jupyter Notebook
- Demo in Python Shell
- Using pyforest
- Installation
- FAQs
- Contributing
- Using pyforest as Package Developer
- About
- Join our community and grow further
pyforest lazy-imports all popular Python Data Science libraries with a single line of code:
from pyforest import *
And if you use Jupyter or IPython, you can even skip this line because pyforest adds itself to the autostart.
When you are done with your script, you can export all import statements via:
active_imports()
Which libraries are available?
- We aim to add all popular Python Data Science libraries which should account for >99% of your daily imports. For example,
pandas
aspd
,numpy
asnp
,seaborn
assns
,matplotlib.pyplot
asplt
, orOneHotEncoder
fromsklearn
and many more. In addition, there are also helper modules likeos
,re
,tqdm
, orPath
frompathlib
. - You can see an overview of all available lazy imports if you type
lazy_imports()
in Python. - If you are missing an import, you can add it to the pyforest imports.
In order to gather all the most important names, we need your help. Please open a pull request and add the imports that we are still missing.
You need Python 3.6 or above because we love f-strings.
From the terminal, enter:
pip install pyforest
And you're ready to go.
Please note, that this will also add pyforest to your IPython default startup settings.
-
"I need to always explicitly write down the libraries I used at the top of my scripts."
- Of course, you can export the import statements for all used libraries with
active_imports()
.
- Of course, you can export the import statements for all used libraries with
-
"Doesn't this slow down my Jupyter or Python startup process?"
- No, because the libraries will only be imported when you actually use them. Until you use them, the variables like
pd
are only pyforest placeholders.
- No, because the libraries will only be imported when you actually use them. Until you use them, the variables like
-
"Why can't I just use the typical IPython import?"
- If you were to add all the libraries that pyforest includes, your startup time might take more than 30s.
-
"I don't have and don't need tensorflow. What will happen when I use pyforest?"
- Tensorflow is included in pyforest but pyforest does not install any dependencies. You need to install your libraries separately from pyforest. Afterwards, you can access the libraries via pyforest if they are included in the pyforest imports.
-
"Will the pyforest variables interfere with my own local variables?"
- Please make sure that you import pyforest at the beginning of your script. Then you will always be safe. You can use your variables like you would without pyforest. The worst thing that can happen is that you overwrite a pyforest placeholder and thus cannot use the placeholder any more (duh).
-
"What about auto-completion on lazily imported modules?"
- It works :) As soon as you start the auto-completion, pyforest will import the module and return the available symbols to your auto-completer.
-
"How to (temporarily) deactivate the auto_import in IPython and Jupyter?"
- Go to the directory
~/.ipython/profile_default/startup
and adjust or delete thepyforest_autoimport.py
file. You will find further instructions in the file.
- Go to the directory
-
"How to (re)activate the pyforest auto_import?"
- Execute the following Python command in Jupyter, IPython or Python:
from pyforest.auto_import import setup; setup()
. Please note that the auto_import only works for Jupyter and IPython.
- Execute the following Python command in Jupyter, IPython or Python:
-
"Why is pandas_profiling also imported in the demo?"
- pyforest supports complementary, optional imports. For example,
pandas_profiling
patches thepd.DataFrame
with the convenience functiondf.profile_report
. Therefore, pyforest also importspandas_profiling
if you have it installed. If you don't havepandas_profiling
installed, the optional import will be skipped.
- pyforest supports complementary, optional imports. For example,
-
"I don't want to copy complementary import statements to the top of my file."
- Please note, that the complementary imports will always appear at the bottom of the import_statements list. So, you can just copy all statements above. Alternatively, you can deactivate complementary imports.
-
"How to deactivate complementary imports?"
- You can uncomment the statements
*.__on_import__()
at the bottom of the pyforest imports file.
- You can uncomment the statements
-
"Why is the project called pyforest?"
- In which ecosystem do pandas live?
In order to gather all the most important names, we need your help. Please open a pull request and add the imports that we are still missing to the pyforest imports. You can also find the guidelines in the pyforest imports file
pyforest helps you to minimize the (initial) import time of your package which improves the user experience. If you want your package imports to become lazy, rewrite your imports as follows:
Replace
import pandas as pd
with
from pyforest import LazyImport
pd = LazyImport("import pandas as pd")
pyforest is developed by Florian, Tobias and Guido from 8080 Labs. Our goal is to improve the productivity of Python Data Scientists. Other projects that we are working on are edaviz and bamboolib
If you
- like our work or
- want to become a faster Python Data Scientist or
- want to discuss the future of the Python Data Science ecosystem or
- are just interested in mingling with like-minded fellows
then, you are invited to join our slack.