In this tutorial, I will explain how to import all functions from a file in Python. As a developer working on a project, I often came across a scenario where I needed to import all functions from a file. We will cover different approaches to importing functions with examples and screenshots.
Import Specific Functions
If you only need a few specific functions from another file in Python, you can import them individually. This approach is recommended as it makes your code more readable and avoids potential naming conflicts.
Suppose you have a file named us_states.py with the following functions:
def get_capital(state):
# Function to retrieve the capital of a given US state
capitals = {
"California": "Sacramento",
"New York": "Albany",
"Texas": "Austin"
}
return capitals.get(state, "Capital not found")
def is_state(state):
# Function to check if a given string is a valid US state
states = ["California", "New York", "Texas", "Florida", "Illinois"]
return state in statesTo import these specific functions in your main script, you can use the following syntax:
from us_states import get_capital, is_state
# Example usage
print(get_capital("California"))
print(is_state("New York")) Output:
Sacramento
TrueYou can see the output in the screenshot below.

By explicitly listing the functions you want to import, you can access them directly in your main script without the need to prefix them with the module name.
Read How to Get the Basename of a File in Python?
Import All Functions Using Wildcards
In some cases, you might want to import all Python functions from a file without listing them individually. Python provides the wildcard (*) syntax for this purpose. However, it’s important to note that using wildcards can make your code less readable and may introduce naming conflicts.
To import all functions from the us_states.py file using a wildcard, you can use the following syntax:
from us_states import *
# Example usage
print(get_capital("Texas"))
print(is_state("Florida")) Output:
Austin
TrueYou can see the output in the screenshot below.

While this approach seems convenient, it’s generally discouraged because it can lead to unclear dependencies and potential issues if the imported file contains functions with the same names as those in your main script. It’s better to explicitly import the required functions.
Check out How to Create a CSV File in Python?
Best Practices for Importing Functions in Python
When importing functions from other files, keep the following best practices in mind:
- Explicit imports: Always prefer importing specific functions over using wildcards. It improves code readability and helps avoid naming conflicts.
- Naming conventions: Use meaningful and descriptive names for your functions and modules.
- Avoid circular imports: Be cautious not to create circular dependencies between modules. Circular imports can lead to unexpected behavior and make your code harder to understand.
- Organize your code: Logically structure your project, grouping related functions and modules. This makes it easier to navigate and maintain your codebase.
Read How to Write Bytes to File in Python?
Troubleshoot Import Issues
If you encounter issues while importing functions from another file, consider the following:
- Make sure the file you’re trying to import is in the same directory as your main script or in a directory that is part of the Python module search path.
- Double-check the spelling and capitalization of the file name and function names. Python is case-sensitive, so any mismatch will result in an import error.
- Verify that the file you’re importing doesn’t have any syntax errors or missing dependencies. Run the file individually to ensure it executes without any issues.
Check out How to Read Large CSV Files in Python?
Conclusion
In this tutorial, I have explained how to import all functions from a file in Python. I discussed how to import specific functions and import all functions using wildcards. I also covered some best practices for importing functions in Python and troubleshooting import issues.
You may like to read:
- How to Call a Function from Another File in Python?
- How to Replace a Specific Line in a File Using Python?
- How to Create a Python File in Terminal?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.