Search code examples
pythonnumpyscipy

Official abbreviation for: import scipy as sp/sc


I've seen both:

import scipy as sp

and:

import scipy as sc

Is there an official preference listed anywhere?

For example, in the Introduction of the Scipy documentation, it is recommended to

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

but a similar abbreviation is not offered for the Scipy package.

In this question, sp is recommended, but the link to the Scipy docs doesn't actually specify sp over sc.


Solution

  • SciPy maintainer here.

    Before SciPy 1.9, we recommended people to not import the main namespace (import scipy) because this would recursively import everything leading to long import time.

    Now we have a lazy loading mechanism which does not incur any performance penalty. So you can do import scipy and modules are only loaded when you use them.

    To answer the OP, we do not have a recommended way to import SciPy. There are strong opinions among maintainers. Some maintainers advocate for never using aliases while other would welcome one.

    My personal take is that, while the project does not recommend the use of an alias, if people are still going to use one, it would be best if everyone doing so would use the same. sp seems to be more used and libraries like NetworkX and Scikit-Image use this convention internally.

    See the updated doc: https://scipy.github.io/devdocs/reference/index.html#guidelines-for-importing-functions-from-scipy