Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import abbreviations for common modules

Google's style guide says, about imports, that modules might be aliased with import xyz as x when x is a common abbreviation for xyz.

What are the standard abbreviations for the most common modules?

I'm here looking for a list exhaustive as possible, including modules from the standard library, as well as third-party niche packages that are frequently used in their respective fields.

For instance, numpy is always imported as np, and tkinter, when hopefully not imported with from module import *, is generally imported as tk.

like image 610
Right leg Avatar asked Oct 29 '22 23:10

Right leg


1 Answers

Here are the names I see most of the time for the modules I frequently use. This list is not meant to become an absolute reference, but I hope it will help provide some guidelines. Please feel free to complete it, or to change whatever you think needs to be changed.

The import statements follow the conventions established by Google's Python style guide, namely:

  • Use import x for importing packages and modules.
  • Use from x import y where x is the package prefix and y is the module name with no prefix.
  • Use from x import y as z if two modules named y are to be imported or if y is an inconveniently long name.
  • Use import y as z only when z is a standard abbreviation (e.g., np for numpy).

MODULE                  ALIAS       IMPORT STATEMENT

datetime                dt          import datetime as dt
matplotlib.pyplot       plt         from matplotlib import pyplot as plt
multiprocessing         mp          import multiprocessing as mp
numpy                   np          import numpy as np
pandas                  pd          import pandas as pd
seaborn                 sns         import seaborn as sns 
tensorflow              tf          import tensorflow as tf
tkinter                 tk          import tkinter as tk
like image 123
9 revs, 3 users 80% Avatar answered Nov 15 '22 07:11

9 revs, 3 users 80%