There are lots of packages in Python ecosystem, like NumPy, Matplotlib.
to simplify coding, we usually code this way
import numpy as np
np is an alias, or shortcut, or something else.
the question is, what is the jargon of this usage? an link to python doc would be great.
You will not be wrong if you call it
asname
.Importing is a form of name binding; names in the current namespace are bound to imported objects.
The
import
statement documentation calls it an identifier, but identifiers are names. Importing an object always binds to an identifier, but theas <identifier>
syntax lets you specify an alternate name to use instead of the default.When parsing Python syntax into an Abstract Syntax Tree (which is what the CPython compiler does, and you can do with the
ast
module), then the resultingImport
andImportFrom
nodes have 1 or morenames
, each an object of theast.alias
type:and the
alias
type has aname
and anasname
value, both identifiers, andasname
is optional:So they are just names, variables, and because they differ from the default for those imports, it's fine to call them aliases.