How to Give a Module a Shorter Name in Python with import as
Some module names are long, and code uses them many times. import <module> as <name> gives a module a shorter name for your file, the way import pandas as pd does. This guide imports statistics as stats on Python 3.15.2.
Syntax
import <module> as <short name>
from <module> import <name> as <other name>
| Part | What it means |
|---|---|
<module> | The module to import, such as statistics or skops.io |
as <short name> | The name you'll use for it in this file |
from <module> import <name> as <other name> | The same, for one name from inside a module |
The Python language reference says: "If the module name is followed by as, then the name following as is bound directly to the imported module."
The Example
The script imports the standard statistics module as stats and works out the mean of three numbers.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
import statistics as stats
print(stats.mean([3, 5, 10]))
![The import_as.py script in a macOS-style code window: import statistics as stats, then print(stats.mean([3, 5, 10])).](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/python-import-as-01-code.webp)
Step 2: Run It
uv run python import_as.py
6

stats.mean is statistics.mean under its new name: the mean of 3, 5 and 10 is 6. The command works unchanged in PowerShell.
One Name, Renamed
The from form renames a single function. from statistics import mean as average, then print(average([3, 5, 10])), also printed 6.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Using the module's full name after renaming it | NameError: name 'statistics' is not defined. Did you forget to import 'statistics'? | Use the new name, stats, or import the module without as too |
| Inventing a different short name in every file | Readers have to look each one up | Use the names everyone knows, such as pd for pandas and np for NumPy |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
NameError for a module you imported | It was imported with as, so only the new name exists | Use the name after as |
FAQ
Does as change the module for other files?
No. The new name exists only in the file that imports it.
Can a module with dots in its name be renamed?
Yes: import skops.io as sio gives the skops.io module the name sio.
Conclusion
import statistics as stats made stats.mean([3, 5, 10]) work and print 6, and the full name statistics was no longer defined in that file. Use the short names most Python code already uses.
Additional Resources
- The import statement — the reference, including
as. - Modules — the Python tutorial.
