Search code examples
pythonimportfast-ai

Why fastbook (fast.ai) is using a star import?


Usually in Python, it is recommended to never do a "star import" (e.g. from my_module import *).

The rationale is that it makes it hard to read, perform linting, and even worse could lead to clash of name (More on this here).

However, all the documentation and training of fast.ai through the usage of fastbook use the following lines:

import fastbook
fastbook.setup_book()

from fastbook import *

Why shall we use import * for fastbook?

How feasible would it be to do import fastbook as fb instead?

Thanks


Solution

  • According to the founder of fast.ai - Jeremy Howard, It is OK to use star import if you are using an interactive work environment like jupyter notebook. Below is what Jeremy says in his book "Deep Learning for Coders With Fastai and Pytorch AI Applications without a PhD":

    "A lot of Python coders recommend avoiding importing a whole library like this (using the import * syntax) because in large software projects it can cause problems. However, for interactive work such as in a Jupyter notebook, it works great. The fastai library is specially designed to support this kind of interactive use, and it will import only the necessary pieces into your environment."