import module
from module import name
import module as alias
Example
import json
from pathlib importPathfrom collections import defaultdict,Counterimport numpy as np # common alias convention
data = json.dumps({"key":"value"})print(data)
Output
{"key": "value"}
Note Convention: standard library imports first, then third-party, then local. Separate groups with a blank line. Use isort to auto-format.
// tsconfig.json{"compilerOptions":{"baseUrl":".","paths":{"@components/*":["src/components/*"],"@utils/*":["src/utils/*"],"@api/*":["src/api/*"],"@types/*":["src/types/*"]}}}// In your code:import{Button}from"@components/Button";import{ formatDate }from"@utils/date";importtype{User}from"@types/user";
Output
// Path aliases shorten deep relative imports like ../../../../utils
Note paths only affects TypeScript's type resolution - it does NOT rewrite imports in emitted JS. Your bundler (Vite, webpack) or runtime (ts-node, tsx) needs matching alias config. For Node.js, package.json "imports" with subpath patterns is the modern alternative that works without bundler config.
Frequently asked questions
How does Python handle alias import?
This task is covered in 2 stacks on this page: Python, TypeScript. The "Basic Imports" snippet in Python uses `import module`.
Which code does the Python example use?
The "Basic Imports" snippet uses `import module`, from the Modules & Imports section of the Python cheat sheet.
Which stacks cover "alias import" on this page?
Python, TypeScript. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Basic Imports": Convention: standard library imports first, then third-party, then local. Separate groups with a blank line. Use isort to auto-format.