Skip to content
Lazy-import of all popular Python Data Science libraries
Python Shell Batchfile
Branch: master
Clone or download
tkrabel Merge pull request #8 from ecederstrand/patch-2
Specify supported Python versions
Latest commit 54b1329 Aug 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github add issue template Aug 12, 2019
examples crop gif Aug 15, 2019
src/pyforest Added statistics module Aug 14, 2019
tests add feature: make Importables callable Aug 12, 2019
.coveragerc init Aug 11, 2019
.gitignore ignore private coverage file Aug 12, 2019
.pre-commit-config.yaml add black pre-commit hook Aug 13, 2019
AUTHORS.rst init Aug 11, 2019
CHANGELOG.rst init Aug 11, 2019
LICENSE.txt init Aug 11, 2019
README.md add website Aug 15, 2019
bld.bat initial conda build setup Aug 13, 2019
build.sh initial conda build setup Aug 13, 2019
meta.yaml remove leading "v" in git_rev Aug 15, 2019
requirements.txt removed pyscaffold Aug 14, 2019
setup.cfg Specify supported Python versions Aug 16, 2019
setup.py removed pyscaffold Aug 14, 2019
upload_to_conda.sh crop gif Aug 15, 2019
upload_to_pypi.sh

README.md

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

Demo in Python Shell

demo

Using pyforest

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 as pd, numpy as np, seaborn as sns, matplotlib.pyplot as plt, or OneHotEncoder from sklearn and many more. In addition, there are also helper modules like os, re, tqdm, or Path from pathlib.
  • 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.

Installation

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.

Frequently Asked Questions

  • "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().
  • "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.
  • "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 the pyforest_autoimport.py file. You will find further instructions in the file.
  • "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.
  • "Why is pandas_profiling also imported in the demo?"

    • pyforest supports complementary, optional imports. For example, pandas_profiling patches the pd.DataFrame with the convenience function df.profile_report. Therefore, pyforest also imports pandas_profiling if you have it installed. If you don't have pandas_profiling installed, the optional import will be skipped.
  • "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.
  • "Why is the project called pyforest?"

    • In which ecosystem do pandas live?

Contributing

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

Using pyforest as Package Developer

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")

About

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

Join our community and grow further

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.

You can’t perform that action at this time.