A simple replication of R's file.choose() for Python.
Project description
pyfilechoose
R's file.choose(), reimplemented for Python.
In R, file.choose() opens a file picker and returns the path you select.
pyfilechoose gives you the same one-liner in Python, with no GUI boilerplate
and no leftover Tk windows.
It uses tkinter from the standard library, so it has no third-party
dependencies.
Installation
With pip:
pip install pyfilechoose
With uv:
# Add it to your project
uv add pyfilechoose
# ...or install it into the current environment
uv pip install pyfilechoose
# ...or run a one-off script that uses it, no install needed
uv run --with pyfilechoose your_script.py
On Linux, tkinter ships with most Python builds but may need to be installed
separately, e.g. sudo apt install python3-tk.
Usage
Pick a single file
from pyfilechoose import file_choose
path = file_choose()
print(path) # absolute path of the file you selected
With pandas (the classic R workflow)
file_choose() returns a path string, so it works with any function that takes
a file path, including pd.read_csv:
import pandas as pd
from pyfilechoose import file_choose
# Just like df <- read.csv(file.choose()) in R
df = pd.read_csv(file_choose())
You can still pass the usual pandas options, and filter the picker to CSVs:
df = pd.read_csv(file_choose(filetypes=[("CSV files", "*.csv")]), sep=";")
Filter file types and set a starting directory
path = file_choose(
title="Pick your dataset",
filetypes=[("CSV files", "*.csv"), ("All files", "*.*")],
initialdir="~/Documents",
)
Pick several files at once
from pyfilechoose import files_choose
paths = files_choose(filetypes=[("Images", "*.png *.jpg")])
for p in paths:
print(p)
API
file_choose(*, title="Select a file", filetypes=None, initialdir=None) -> str
Opens a dialog and returns the absolute path of the chosen file.
Raises FileNotFoundError if the user cancels.
files_choose(*, title="Select one or more files", filetypes=None, initialdir=None) -> list[str]
Same as above but allows multiple selections; returns a list of absolute paths.
Raises FileNotFoundError if nothing is selected.
| Argument | Type | Description |
|---|---|---|
title |
str |
Title of the dialog window. |
filetypes |
list[tuple[str, str]] | None |
(label, pattern) pairs, e.g. [("CSV", "*.csv")]. |
initialdir |
str | None |
Directory the dialog opens in. |
Development
git clone https://github.com/Pinto-Katende-Jonathan/pyfilechoose.git
cd pyfilechoose
With uv, which creates and manages the virtualenv for you:
uv sync --extra dev # set up the environment with dev dependencies
uv run pytest # run the test suite
With pip:
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest
License
MIT © Jonathan Katende Pinto
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfilechoose-0.1.0.tar.gz.
File metadata
- Download URL: pyfilechoose-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bbbbb0fd6bf848231a18b7473ad474ab5e37e8d95423543e106daa0ab82137f
|
|
| MD5 |
013b68af96228d6a951d3083f0f29a45
|
|
| BLAKE2b-256 |
a3ead9573fc70388d47c1380f3df3dc4542c08891902a80f7f1cdf1613090cdf
|
File details
Details for the file pyfilechoose-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyfilechoose-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
427f7180a36feb49730ee637e0195723f8c421358cb9f8d802b3e3e9d0123145
|
|
| MD5 |
528221d7abeab3c72fda72ee3cd7919c
|
|
| BLAKE2b-256 |
12971d1f1326faa5728296fc9850d44b840cc7137a17febd7e4b083ef4eb97d1
|