A Python package that makes file paths easy and reproducible. Stop hardcoding paths and working directory headaches — use relative paths that work anywhere.
Install here using pip:
pip install hereCreate a simple script that uses here() to resolve paths relative to your script:
from here import here
# Get the path to a data file relative to your script
data_file = here("data/input.csv")
print(data_file)
# Output: /absolute/path/to/your/project/data/input.csvThat's it! No matter where your script is called from, or what kind of python file from which it is called, this path will always point to the right place.
here() works seamlessly in Jupyter notebooks too:
from here import here
import pandas as pd
# Load data relative to your notebook location
df = pd.read_csv(here("data/results.csv"))
# Save outputs relative to your project root
df.to_csv(here("output/processed.csv"), index=False)The path will be relative to your project root, even when working interactively.
A typical project structure works well with here():
my_project/
├── data/
│ ├── input/
│ └── output/
├── scripts/
│ ├── analysis.py
│ └── preprocessing.py
├── notebooks/
│ └── exploration.ipynb
└── results/
From any script or notebook, use relative paths:
from here import here
input_data = here("data/input/raw.csv")
output_data = here("data/output/processed.csv")
results = here("results/summary.txt")If you have scripts in subdirectories, here() still finds the project root:
my_project/
├── data/
├── scripts/
│ ├── main.py
│ └── utils/
│ └── helper.py
In helper.py, you can still access project-relative paths:
from here import here
# Even nested scripts can access project files
config_file = here("config/settings.json")Use standard path notation to move up directories:
from here import here
# Go up from current location, then down into another folder
sibling_dir = here("../config")
parallel_project = here("../../other_project/data")Working with file paths in Python has challenges:
Hardcoded absolute paths break when files move:
# ❌ This breaks when you move your project
df = pd.read_csv("/Users/me/projects/my_work/data.csv")Relative paths from os.getcwd() are unreliable:
# ❌ This breaks when you run from a different directory
df = pd.read_csv("data/input.csv") # Only works if cwd is your project rootJupyter notebooks and scripts behave differently:
# ❌ In notebooks, relative paths behave unexpectedly
# The working directory may not be where you think it ishere() uses file-based path resolution instead of directory-based:
- It finds the directory containing your script or notebook
- It resolves paths relative to that location
- It always works, regardless of where the code is called from
# ✅ This always works, anywhere
data_file = here("data/input.csv")When you call here("path/to/file"):
here()inspects the call stack to find which file called it- It determines that file's directory
- It resolves your relative path from there
- It returns the absolute path
This approach means:
- No
setwd()needed — paths are always relative to your source file - Works in scripts, notebooks, and interactive shells — same behavior everywhere
- Reproducible — paths don't depend on where the code is executed from
- Portable — move your project and all paths still work
Resolves a file path relative to your script or notebook location.
Parameters:
path(str, optional): A relative path to resolve. Use/as separator. Default is empty string (returns the project root).print_debug_info(bool, optional): IfTrue, prints debug information about path resolution. Default isFalse.
Returns:
str: The absolute path to the file or directory.
Examples:
from here import here
# Get project root
root = here()
# Get a specific file
data_file = here("data/input.csv")
# Navigate with parent directories
config = here("../config/settings.json")
# Debug path resolution
here("data", print_debug_info=True)Supported Environments:
- Python scripts (
.pyfiles) - Jupyter notebooks (
.ipynbfiles) - IPython interactive shells
- Any Python environment with a call stack
Returns the absolute directory path of the script or notebook that called this function.
Parameters:
print_debug_info(bool, optional): IfTrue, prints debug information. Default isFalse.
Returns:
str: The absolute path to the directory containing the calling script.
Example:
from here import get_calling_script_file_path
current_dir = get_calling_script_file_path()
print(current_dir)
# Output: /absolute/path/to/your/project/scriptsThis project is licensed under the MIT License. See the LICENSE file for details.
