concept

Relative Imports

Relative imports are a mechanism in programming languages for importing modules or packages based on their location relative to the current file's directory structure. They use dot notation (e.g., '.', '..') to specify paths within the same project, allowing developers to organize code into hierarchical directories while maintaining clear dependencies. This approach is commonly supported in languages like Python and JavaScript/TypeScript to facilitate modular development.

Also known as: relative paths, dot imports, local imports, intra-package imports, relative module imports
🧊Why learn Relative Imports?

Developers should use relative imports when working on projects with a structured directory layout, as they make dependencies explicit and portable within the same codebase, avoiding hardcoded absolute paths that can break when moving files. They are particularly useful in large applications with nested modules, such as web frameworks like Django or React projects, where maintaining relative paths simplifies refactoring and collaboration. However, they can become complex in deeply nested structures, so alternatives like absolute imports might be preferred in some cases.

Compare Relative Imports

Learning Resources

Related Tools

Alternatives to Relative Imports